Commit 11edc5e7 authored by Ben Boeckel's avatar Ben Boeckel
Browse files

paraDIS: remove unused files

parent f6baecca
......@@ -21,7 +21,6 @@ set(PARADIS_TECPLOT_SOURCES
avtparaDIS_tecplotFileFormat.C
RC_c_lib/args.c
RC_c_lib/debugutil.c
RC_c_lib/signals.c
RC_c_lib/fileutils.c
RC_c_lib/inventor.c
RC_cpp_lib/RangeList.C
......
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <netdb.h>
#include <errno.h>
#include <arpa/inet.h>
int main(int argc, char *argv[]){
char myHostName[1000];
char junk[INET_ADDRSTRLEN];
struct hostent *myHEP;
char **haddrp = NULL;
int addrno=0;
if (gethostname(myHostName, 1000) != 0) {
printf("Cannot get host name\n");
return 1;
} else {
printf("Hostname is %s\n", myHostName);
}
myHEP = gethostbyname(myHostName);
if (!myHEP) {
printf("Cannot get host entry from name %s (errno is %d)\n", myHostName, errno);
return 2;
}
printf("Result of gethostbyname: canonical h_name is %s\n", myHEP->h_name);
printf("Host addresses associated to name: \n");
haddrp = myHEP->h_addr_list;
while (*haddrp) {
printf("h_addr_list[%d] = %s\n", addrno++,
inet_ntop(myHEP->h_addrtype, *(haddrp++), junk, sizeof(junk)));
}
return 0;
}
/* gprof-helper.c -- preload library to profile pthread-enabled programs
*
* Authors: Sam Hocevar <sam at zoy dot org>
* Daniel J~nsson <danieljo at fagotten dot org>
*
* Compilation example:
* gcc -shared -nostdlib -fPIC gprof-helper.c -o gprof-helper.so -lpthread -ldl
*
* Usage example:
* LD_PRELOAD=./gprof-helper.so your_program
*/
/*!
Note from Rich Cook:
http://sam.zoy.org/writings/programming/gprof.html
What is gprof?
gprof is the GNU Profiler, a tool used when tracking which functions are eating CPU in your program. Anyway, you should already be familiar with it if you got interested in this page.
One problem with gprof under certain kernels (such as Linux) is that it doesn~t behave correctly with multithreaded applications. It actually only profiles the main thread, which is quite useless.
Workaround
There is an easy, but surprisingly not very widespread fix for this annoying gprof behaviour. Basically, gprof uses the internal ITIMER_PROF timer which makes the kernel deliver a signal to the application whenever it expires. So we just need to pass this timer data to all spawned threads.
Example
It wouldn~t be too hard to put a call to setitimer in each function spawned by a thread, but I thought it would be more elegant to implement a wrapper for pthread_create.
Daniel Jnsson enhanced my code so that it could be used in a preload library without having to modify the program. It can also be very useful for libraries that spawn threads without warning, such as libSDL. The result code is shown below and can be downloaded (gprof-helper.c):
*/
#define _GNU_SOURCE
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <pthread.h>
static void * wrapper_routine(void *);
/* Original pthread function */
static int (*pthread_create_orig)(pthread_t *__restrict,
__const pthread_attr_t *__restrict,
void *(*)(void *),
void *__restrict) = NULL;
/* Library initialization function */
void _init(void)
{
pthread_create_orig = dlsym(RTLD_NEXT, "pthread_create");
fprintf(stderr, "pthreads: using profiling hooks for gprof\n");
if(pthread_create_orig == NULL)
{
char *error = dlerror();
if(error == NULL)
{
error = "pthread_create is NULL";
}
fprintf(stderr, "%s", error);
#ifdef DEBUG
exit(EXIT_FAILURE);
#endif
}
}
/* Our data structure passed to the wrapper */
typedef struct wrapper_s
{
void * (*start_routine)(void *);
void * arg;
pthread_mutex_t lock;
pthread_cond_t wait;
struct itimerval itimer;
} wrapper_t;
/* The wrapper function in charge for setting the itimer value */
static void * wrapper_routine(void * data)
{
/* Put user data in thread-local variables */
void * (*start_routine)(void *) = ((wrapper_t*)data)->start_routine;
void * arg = ((wrapper_t*)data)->arg;
/* Set the profile timer value */
setitimer(ITIMER_PROF, &((wrapper_t*)data)->itimer, NULL);
/* Tell the calling thread that we don't need its data anymore */
pthread_mutex_lock(&((wrapper_t*)data)->lock);
pthread_cond_signal(&((wrapper_t*)data)->wait);
pthread_mutex_unlock(&((wrapper_t*)data)->lock);
/* Call the real function */
return start_routine(arg);
}
/* Our wrapper function for the real pthread_create() */
int pthread_create(pthread_t *__restrict thread,
__const pthread_attr_t *__restrict attr,
void * (*start_routine)(void *),
void *__restrict arg)
{
wrapper_t wrapper_data;
int i_return;
/* Initialize the wrapper structure */
wrapper_data.start_routine = start_routine;
wrapper_data.arg = arg;
getitimer(ITIMER_PROF, &wrapper_data.itimer);
pthread_cond_init(&wrapper_data.wait, NULL);
pthread_mutex_init(&wrapper_data.lock, NULL);
pthread_mutex_lock(&wrapper_data.lock);
/* The real pthread_create call */
i_return = pthread_create_orig(thread,
attr,
&wrapper_routine,
&wrapper_data);
/* If the thread was successfully spawned, wait for the data
* to be released */
if(i_return == 0)
{
pthread_cond_wait(&wrapper_data.wait, &wrapper_data.lock);
}
pthread_mutex_unlock(&wrapper_data.lock);
pthread_mutex_destroy(&wrapper_data.lock);
pthread_cond_destroy(&wrapper_data.wait);
return i_return;
}
/* $Id: signals.c,v 1.5 2005/09/14 02:30:56 rcook Exp $ */
#include <signal.h>
#include <stdio.h>
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <windows.h>
#else // _WIN32
#include <netdb.h>
#include <unistd.h>
#endif // _WIN32
/* set a signal handler for the given signal
sig == the signal to catch
func == the handler
useful functions are SIG_IGN, SIG_DFL
can of course pass a pointer to your own sigfunc
e.g.,
void myfunc(int sig);
if (!setsignal(SIGHUP, myfunc))
errexit("Can't set SIGHUP handler!\n");
q.v. Stephenson's Advance Unix Programming, page 270
*/
typedef void sigfunc (int);
int setsignal(int sig, sigfunc *func){
fprintf(stderr, "setting signal %d\n", sig);
if (signal(sig, func) == SIG_ERR) {
fprintf(stderr, "Error: couldn't set signal %d\n", sig);
return 0;
}
return 1;
}
void handler(int sig) {
printf("test prog received signal %d\n", sig);
/*exit(0);*/
}
#if 0
/* this is code I used to see if I was getting signaled at one point, and it might be useful*/
int GettingSignaled(void)
{
char localhost[256];
struct hostent *hep = NULL;
int i=0;
/* see if we're getting signaled, damnit!*/
setsignal(SIGINT, handler);
/*setsignal(SIGKILL, handler);*/
setsignal(SIGHUP, SIG_IGN);
setsignal(SIGPIPE, handler);
setsignal(SIGQUIT, handler);
/*setsignal(SIGSTOP, handler);*/
setsignal(SIGTERM, handler);
setsignal(SIGTTIN, handler);
setsignal(SIGABRT, handler);
setsignal(SIGCHLD, handler);
gethostname(localhost, 256);
hep = gethostbyname(localhost);
printf("test host is %s\n", hep->h_name);
fflush(stdout);
fprintf(stdout, "Child stdout.\n");
fprintf(stderr, "Child stderr new.\n");
/*fclose(stdout);*/
/*fclose(stderr);*/
i=30;
while (i--){
int err = usleep (999999);
if (err) {
fprintf(stderr, "child sleep err %d\n", err);
#ifdef DEBUG
exit(1);
#endif
}
printf("Child sleeping... (%d) \n", i);
fflush(stdout);
}
return 0;
}
#endif
#include "ComboBoxManager.h"
#include <QLineEdit>
#include "debugutil-qt.h"
//============================================================
ComboBoxManager::ComboBoxManager(QComboBox *box, Preferences *prefs, QString prefKey, QString emptyValue, bool deleteEmptyValue):
mComboBox(box), mPrefs(prefs), mEmptyValue(emptyValue),
mPrefKey(prefKey), mDeleteEmptyValue(deleteEmptyValue) {
setUp();
// these needs to be after setUp() to avoid recursion
if (mComboBox->isEditable()) {
connect(mComboBox->lineEdit(), SIGNAL(editingFinished()),
this, SLOT(editFinished()));
}
connect(mComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(itemChanged(int)));
return;
}
//============================================================
ComboBoxManager::~ComboBoxManager(){
return;
}
//============================================================
void ComboBoxManager::setUpNonEditable( ) {
dbprintf(5, "setUpNonEditable()");
if (mPrefs->hasKey((mPrefKey+"_initial").toStdString())) {
dbprintf(5, QString("found key %1\n").arg(mPrefKey+"_initial"));
QString value = mPrefs->GetValue((mPrefKey+"_initial").toStdString()).c_str();
int init = mComboBox->findText(value, Qt::MatchExactly);
if (init != -1) {
dbprintf(5, QString("key exists in menu\n"));
mComboBox->setCurrentIndex(init);
} else {
dbprintf(5, QString("key does not exist in menu, so ignoring\n"));
}
}
return;
}
//============================================================
void ComboBoxManager::setUp(void ) {
dbprintf(5, QString("setupComboBox(%1)\n").arg(mPrefKey));
if (!mComboBox->isEditable()) {
setUpNonEditable();
return;
}
QString data, initialItem;
if (mPrefs->hasKey(mPrefKey.toStdString())) {
data = mPrefs->GetValue(mPrefKey.toStdString()).c_str();
dbprintf(5, QString("Prefs have key\n"));
} else {
dbprintf(5, QString("Prefs no not have key\n"));
if (!mComboBox->count()) {
if (mPrefs->hasKey((mPrefKey+"_initial").toStdString())) {
data = mPrefs->GetValue((mPrefKey+"_initial").toStdString()).c_str();
} else {
data = "Click to edit";
}
}
}
dbprintf(5, QString("setupComboBox: data is \"%1\" and initialItem is \"%2\"\n").arg(data).arg(initialItem));
QStringList items =
data.split("<comboBoxItem>", QString::SkipEmptyParts);
//box->clear();
int itemNum = 0; // skip the first, which is the boxName
while (itemNum < items.size()) {
QString item = items[itemNum].trimmed();
dbprintf(5, QString("Parsing item \"%1\"...").arg(item));
if (item != "" && mComboBox->findText(item, Qt::MatchExactly) == -1) {
dbprintf(5, QString("adding item\n"));
mComboBox->addItem(item);
} else {
dbprintf(5, "skipping blank or redundant item\n");
}
++itemNum;
}
dbprintf(5, QString("Loaded %1 items to combo box \n").arg(itemNum));
if (mPrefs->hasKey((mPrefKey+"_initial").toStdString())) {
initialItem = mPrefs->GetValue((mPrefKey+"_initial").toStdString()).c_str();
} else {
initialItem = mComboBox->itemText(0);
}
dbprintf(5, QString("initialItem is now \"%1\"\n").arg(initialItem));
if (initialItem != "") {
int init = mComboBox->findText(initialItem, Qt::MatchExactly);
if (init != -1) {
dbprintf(5, "initialItem was found\n");
mComboBox->setCurrentIndex(init);
} else {
dbprintf(5, "initialItem not found\n");
mComboBox->addItem(initialItem);
mComboBox->setCurrentIndex(mComboBox->findText(initialItem, Qt::MatchExactly));
}
}
dbprintf(5, "done with comboBox\n");
return ;
}
//============================================================
void ComboBoxManager::saveToPrefs(void) {
QString value, text;
int i = 0;
while (i < mComboBox->count()) {
text = mComboBox->itemText(i).trimmed();
if (text != "") {
value += QString("<comboBoxItem> %1 ").arg(text);
}
++i;
}
mPrefs->SetValue(mPrefKey.toStdString(), value.toStdString());
mPrefs->SetValue((mPrefKey+"_initial").toStdString(), mComboBox->currentText().trimmed().toStdString());
return;
}
//============================================================
void ComboBoxManager::itemChanged(int item) {
dbprintf(5, QString("itemChanged, key is \"%1\", item is %2, current text is \"%3\"\n").arg(mPrefKey).arg(item).arg(mComboBox->currentText()));
if (mComboBox->isEditable()) {
editFinished();
}
return;
}
//============================================================
void ComboBoxManager::editFinished() {
dbprintf(5, QString("editFinished, key is \"%1\", current text is \"%2\"\n").arg(mPrefKey).arg(mComboBox->currentText()));
QString text = mComboBox->currentText();
if (text == "") {
dbprintf(5, "empty text\n");
if (mComboBox->currentIndex() != -1 && mDeleteEmptyValue) {
dbprintf(5, "removing empty current item\n");
mComboBox->removeItem(mComboBox->currentIndex());
}
if (mComboBox->count() == 0) {
dbprintf(5, QString("Empty list, placing empty value \"%1\" in list\n").arg(mEmptyValue));
mComboBox->addItem(mEmptyValue);
mComboBox->setCurrentIndex(0);
}
return;
}
if (text != "" && mComboBox->findText(text, Qt::MatchExactly) == -1) {
dbprintf(5, QString("Found and adding text \"%1\"\n").arg(text));
mComboBox->addItem(text);
}
if (mDeleteEmptyValue) {
int bad = mComboBox->findText(mEmptyValue, Qt::MatchExactly);
if (mComboBox->count() > 1 && bad != -1) {
dbprintf(5, QString("Removing empty value item \"%1\" at index \"%2\"\n").arg(mEmptyValue).arg(mComboBox->itemText(bad)));
mComboBox->removeItem(bad);
}
}
int setindex=mComboBox->findText(text, Qt::MatchExactly);
dbprintf(5, QString("setting index to %1 (%2)\n").arg(setindex).arg(text));
mComboBox->setCurrentIndex(setindex);
return;
}
/*!
A class which manages a Qt combo box, causing it to be able to save its contents to a file and to otherwise act intelligently.
Obviously, this file needs Qt to compile properly. As such, this is not part of the RC_cpp_lib collection.
*/
#ifndef COMBOBOX_MANAGER_H
#define COMBOBOX_MANAGER_H
#include <QComboBox>
#include "Prefs.h"
//====================================================================
class ComboBoxManager: public QObject {
Q_OBJECT
public:
ComboBoxManager(QComboBox *box, Preferences *prefs, QString prefKey, QString initialValue, bool deleteEmptyValue=false);
~ComboBoxManager();
void setUp(void);
void setUpNonEditable(void );
void saveToPrefs(void);
public slots:
void itemChanged(int);
void editFinished();
private:
QComboBox *mComboBox;
Preferences *mPrefs;
QString mEmptyValue, mPrefKey;
bool mDeleteEmptyValue;
};
#endif
/* return number of bytes read, throw string on error */
#ifndef CPPFILEUTIL_H
#define CPPFILEUTIL_H
#include "stringutil.h"
/* returns number of elements read, not bytes! */
template <class W>
u_int32_t fread_loop(FILE *theFile, u_int32_t elems2Read, W *bufp) {
u_int32_t totalRead = fread(bufp, sizeof(W), elems2Read, theFile);
bufp += totalRead;
while (elems2Read > totalRead) {
u_int32_t numread = fread(bufp+numread, sizeof(W), elems2Read - totalRead, theFile);
if (!numread) {
string errstring = string("Data read failed after ") +
doubleToString(totalRead+numread) +
"bytes: ";
int err = ferror(theFile);
if (err) throw errstring + "error "+doubleToString(err);
if (feof(theFile)) throw errstring + "unexpected EOF";
else throw errstring + "zero items read, but no error or EOF (impossible!)";
}
bufp += numread;
totalRead += numread;
}
return totalRead;
}
#endif
/*
** $RCSfile: debugutil-qt.cpp,v $
** $Name: $
**
** ASCI Visualization Project
**
** Lawrence Livermore National Laboratory
** Information Management and Graphics Group
** P.O. Box 808, Mail Stop L-561
** Livermore, CA 94551-0808
**
** For information about this project see:
** http://www.llnl.gov/sccd/lc/img/
**
** or contact: asciviz@llnl.gov
**
** For copyright and disclaimer information see:
** $(ASCIVIS_ROOT)/copyright_notice_1.txt
**
** or man llnl_copyright
**
** $Id: debugutil-qt.cpp,v 1.1 2009/04/02 00:39:23 rcook Exp $
**
*/
/*
**
** Abstract:
**
** Author:
**
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <stdarg.h>
#include "debugutil-qt.h"
#include <time.h>
#include <sys/time.h>
#include "QFile"
#include "QDataStream"
#include "QDir"
#include <sys/stat.h>
using namespace std;
static int sVerbose = 0;
static int sCheck = 0;
static bool sUseDateString = false;
static QString sPrependString;
static bool sUseFilesAndLines = false;
static QFile sDebugFile;
static QDataStream sDebugFileStream;
static int sDebugFileVerbose = 0;
static QTcpSocket *sDebugSocket = NULL;
QDataStream sDebugSocketStream;
static int sDebugSocketVerbose = 0;
char *datestring(void) {
static char timebuf[32];
time_t now;
now = time(NULL);
strftime(timebuf, 31, "%d/%m/%y %H:%M:%S", (struct tm *)localtime(&now));
return timebuf;
}
void real_dbfprintf(FILE *stream, int level, QString filename, int lineno, QString msg){
if (sUseFilesAndLines) {
msg = QString("[ %1: %2 ]: %3").arg(filename).arg(lineno).arg(msg);
}
if (sUseDateString) {
msg = QString("(%1) ").arg(datestring()) + msg;
}
msg = sPrependString + msg;
if(sVerbose >= level){
fprintf(stream, msg.toStdString().c_str());
}
if (sDebugFileVerbose >= level && sDebugFile.isWritable()) {
sDebugFileStream << msg.toAscii();
}
if (sDebugSocketVerbose >= level && sDebugSocket && sDebugSocket->isWritable()) {
sDebugSocketStream << msg;
}
return;
}
static int check_verbose(void)
{
if (!sCheck) {
if (getenv("DEBUG_VERBOSE")) {
sVerbose = atoi(getenv("DEBUG_VERBOSE"));
}