Commit 8979dd9e authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

changed debug variables to new namespaced variables

parent 2addd48f
#include "cdoDebugOutput.h"
#include "argument.h"
#include "dmemory.h"
#include "util.h"
......@@ -11,6 +12,10 @@
argument_t *file_argument_new(const char *filename)
{
if(CdoDebug::ARGUMENT > 0)
{
MESSAGE("Creating new file argument for file ", filename);
}
argument_t *argument = new argument_t();
argument->argc = 1;
......@@ -25,6 +30,11 @@ argument_t *file_argument_new(const char *filename)
argument_t * pipe_argument_new(const argument_t *argument, char *pipename, int pnlen)
{
// struct sched_param param;
if(CdoDebug::ARGUMENT > 0)
{
MESSAGE("Creating new pipe argument for pipename ", pipename );
}
argument_t *newargument = argument_new(argument->argc + 1, argument->argc *sizeof(char *));
newargument->operatorName = "";
......@@ -59,6 +69,11 @@ void file_argument_free(argument_t *argument)
argument_t *argument_new(size_t argc, size_t len)
{
if(CdoDebug::ARGUMENT > 0)
{
MESSAGE("Creating new argument");
}
argument_t *argument = new argument_t();
if ( argc > 0 )
......@@ -112,31 +127,31 @@ void argument_fill(argument_t *argument, int argc, char *argv[])
std::string print_argument(argument_t * p_argument)
{
std::string output = "";
output += "argv with " + std::to_string(p_argument->argc) + " arguments:\n" ;
output += " argv with " + std::to_string(p_argument->argc) + " arguments:\n";
for(int i = 0; i < p_argument->argc; i++)
{
output += std::string(p_argument->argv[i]) + " ";
output += " " + std::string(p_argument->argv[i]) + " ";
}
output += "\n";
output += "OperatorName: " + p_argument->operatorName + "\n";
output += " OperatorName: " + p_argument->operatorName + "\n";
output += "operatorArguments";
output += " operatorArguments";
if(p_argument->operatorArguments){
output += ": " + std::string(p_argument->operatorArguments) + "\n";
output += ": " + std::string(p_argument->operatorArguments) + "\n";
}
else
{
output += " not set\n";
}
output += "args";
output += " args";
if(p_argument->operatorArguments){
output += ": " + std::string(p_argument->args) + "\n";
output += ": " + std::string(p_argument->args);
}
else
{
output += " not set\n";
output += " not set";
}
return output;
}
......@@ -393,14 +393,16 @@ void cdoSetDebug(int level)
level 64: stream
level 128: pipe
level 256: pthread
level 512: process
*/
cdiDebug(level);
if ( level == 1 || (level & 32) ) cdoDebug = 1;
if ( level == 1 || (level & 64) ) pstreamDebug(1);
if ( level == 1 || (level & 64) ) CdoDebug::PSTREAM = 1;
if ( level == 1 || (level & 512) ) CdoDebug::PROCESS = 1;
#if defined(HAVE_LIBPTHREAD)
if ( level == 1 || (level & 128) ) pipeDebug(1);
if ( level == 1 || (level & 256) ) Pthread_debug(1);
if ( level == 1 || (level & 128) ) CdoDebug::PIPE = 1;
if ( level == 1 || (level & 256) ) CdoDebug::PTHREAD = 1;
#endif
}
......@@ -1111,7 +1113,6 @@ int parse_options_long(int argc, char *argv[])
int lsortparam;
int ldebLevel;
int lscmode;
bool sepDebugFromLog;
// clang-format off
struct cdo_option opt_long[] =
......@@ -1427,6 +1428,8 @@ int parse_options_long(int argc, char *argv[])
#ifdef DEBUG
CdoDebug::outfile = CDO_optarg;
CdoDebug::print_to_seperate_file = true;
CdoDebug::PSTREAM = 1;
CdoDebug::PROCESS = 1;
#endif
break;
}
......@@ -1473,6 +1476,7 @@ void cdo_rusage(void)
int main(int argc, char *argv[])
{
int lstop = FALSE;
int noff = 0;
int status = 0;
......@@ -1503,7 +1507,9 @@ int main(int argc, char *argv[])
if ( status != 0 ) return -1;
cdo_set_options();
#ifdef DEBUG
CdoDebug::CdoStartMessage();
#endif
if ( Debug || Version ) cdo_version();
if ( Debug )
......@@ -1624,9 +1630,8 @@ int main(int argc, char *argv[])
timer_start(timer_total);
#ifdef DEBUG
CdoDebug::Message_(":==CDO==","Start");
#endif
#ifdef CUSTOM_MODULES
load_custom_modules("custom_modules");
operatorModule(operatorName)(argument);
......@@ -1634,9 +1639,6 @@ int main(int argc, char *argv[])
#else
operatorModule(operatorName)(argument);
#endif
#ifdef DEBUG
CdoDebug::Message_(":==CDO==","End\n");
#endif
timer_stop(timer_total);
......@@ -1658,6 +1660,8 @@ int main(int argc, char *argv[])
if ( cdoGridSearchDir ) Free(cdoGridSearchDir);
if ( CDO_Rusage ) cdo_rusage();
#ifdef DEBUG
CdoDebug::CdoEndMessage();
#endif
return status;
}
......@@ -17,6 +17,7 @@
#if defined(HAVE_CONFIG_H)
#include "config.h"
#include "cdoDebugOutput.h"
#endif
#include <stdio.h>
......@@ -31,7 +32,6 @@
#if defined(HAVE_LIBPTHREAD)
static int PipeDebug = 0;
pipe_t::pipe_t() { pipe_init(); }
......@@ -46,7 +46,7 @@ pipe_t::pipe_init()
*/
/*
#if defined(_POSIX_THREAD_PROCESS_SHARED)
if ( PipeDebug )
if ( CdoDebug::PIPE )
{
Message("setpshared mutexattr to PTHREAD_PROCESS_SHARED");
Message("setpshared condattr to PTHREAD_PROCESS_SHARED");
......@@ -55,7 +55,7 @@ pipe_t::pipe_init()
pthread_mutexattr_setpshared(&m_attr, PTHREAD_PROCESS_SHARED);
pthread_condattr_setpshared(&c_attr, PTHREAD_PROCESS_SHARED);
if ( PipeDebug )
if ( CdoDebug::PIPE )
{
int pshared;
pthread_mutexattr_getpshared(&m_attr, &pshared);
......@@ -71,7 +71,7 @@ pipe_t::pipe_init()
Message("getpshared condattr is PTHREAD_PROCESS_PRIVATE");
}
#else
if ( PipeDebug )
if ( CdoDebug::PIPE )
Message("_POSIX_THREAD_PROCESS_SHARED undefined");
#endif
*/
......@@ -135,24 +135,24 @@ pipe_t::pipeInqTimestep(int p_tsID)
{
if (EOP)
{
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s EOP", name.c_str());
break;
}
if (hasdata)
{
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s has data", name.c_str());
hasdata = false;
data = NULL;
readCond.notify_all();
}
else if (PipeDebug)
else if (CdoDebug::PIPE)
Message("%s has no data", name.c_str());
recInq.notify_all(); /* o.k. ??? */
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s wait of tsDef", name.c_str());
tsDef.wait(locked_mutex);
}
......@@ -201,7 +201,7 @@ pipe_t::pipeInqVlist(int &p_vlistID)
{
time_to_wait += TIMEOUT;
// fprintf(stderr, "tvsec %g\n", (double) time_to_wait.tv_sec);
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s wait of vlistDef", name.c_str());
// pthread_cond_wait(pipe->vlistDef, pipe->mutex);
retcode = vlistDef.wait_for(locked_mutex, time_to_wait);
......@@ -217,7 +217,7 @@ pipe_t::pipeInqVlist(int &p_vlistID)
if (retcode == std::cv_status::timeout)
vlistID = p_vlistID;
else if (PipeDebug)
else if (CdoDebug::PIPE)
Message("%s timeout!", name.c_str());
// UNLOCK
......@@ -250,12 +250,12 @@ pipe_t::pipeDefTimestep(int p_vlistID, int p_tsID)
numrecs += zaxisInqSize(vlistInqVarZaxis(vlistID, varID));
}
}
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s numrecs = %d nvars = %d", name.c_str(), numrecs, vlistNvars(vlistID));
}
nrecs = numrecs;
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s numrecs %d p_tsID %d %d %d", name.c_str(), numrecs, p_tsID, tsIDw, tsIDr);
if (numrecs == 0)
EOP = true;
......@@ -271,11 +271,11 @@ pipe_t::pipeDefTimestep(int p_vlistID, int p_tsID)
{
if (EOP)
{
if (PipeDebug)
if (CdoDebug::PIPE)
Message("EOP");
break;
}
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s wait of tsInq (p_tsID %d %d)", name.c_str(), p_tsID, tsIDr);
tsInq.wait(locked_mutex);
}
......@@ -287,11 +287,11 @@ pipe_t::pipeInqRecord(int *p_varID, int *p_levelID)
{
bool condSignal = false;
// if (PipeDebug)
// if (CdoDebug::PIPE)
// LOCK
m_mutex.lock();
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s has no data %d %d", name.c_str(), recIDr, recIDw);
if (hasdata || usedata)
{
......@@ -311,18 +311,18 @@ pipe_t::pipeInqRecord(int *p_varID, int *p_levelID)
usedata = true;
recIDr++;
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s recID %d %d", name.c_str(), recIDr, recIDw);
while (recIDw != recIDr)
{
if (EOP)
{
if (PipeDebug)
if (CdoDebug::PIPE)
Message("EOP");
break;
}
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s wait of recDef", name.c_str());
recDef.wait(locked_mutex);
}
......@@ -353,7 +353,7 @@ pipe_t::pipeDefRecord(int p_varID, int p_levelID)
// LOCK
m_mutex.lock();
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s has data %d %d", name.c_str(), recIDr, recIDw);
if (hasdata)
{
......@@ -373,7 +373,7 @@ pipe_t::pipeDefRecord(int p_varID, int p_levelID)
recIDw++;
varID = p_varID;
levelID = p_levelID;
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s recID %d %d", name.c_str(), recIDr, recIDw);
m_mutex.unlock();
// UNLOCK
......@@ -388,7 +388,7 @@ pipe_t::pipeDefRecord(int p_varID, int p_levelID)
break;
if (EOP)
break;
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s wait of recInq %d", name.c_str(), recIDr);
recInq.wait(locked_mutex);
}
......@@ -424,7 +424,7 @@ pipeGetReadTarget(pstream_t *pstreamptr, pstream_t *pstreamptr_in)
pstreamptr = pstreamptr_in;
while (pstreamptr_in->ispipe)
{
if (PipeDebug)
if (CdoDebug::PIPE)
fprintf(stderr, "%s: istream %d is pipe\n", __func__, pstreamptr_in->self);
pstreamptr = pstreamptr_in;
pstreamptr_in = pstreamptr_in->pipe->pstreamptr_in;
......@@ -451,7 +451,7 @@ pipe_t::pipeReadRecord(int p_vlistID, double *data, size_t *nmiss)
std::unique_lock<std::mutex> locked_mutex(m_mutex);
while (!hasdata)
{
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s wait of writeCond", name.c_str());
writeCond.wait(locked_mutex);
}
......@@ -465,7 +465,7 @@ pipe_t::pipeReadRecord(int p_vlistID, double *data, size_t *nmiss)
Error("data type %d not implemented", hasdata);
}
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s read record %d", name.c_str(), recIDr);
hasdata = false;
......@@ -492,7 +492,7 @@ pipe_t::pipeWriteRecord(double *p_data, size_t p_nmiss)
writeCond.notify_all();
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s write record %d", name.c_str(), recIDw);
// LOCK
......@@ -510,21 +510,14 @@ pipe_t::pipeWriteRecord(double *p_data, size_t p_nmiss)
if (EOP)
{
if (PipeDebug)
if (CdoDebug::PIPE)
Message("EOP");
break;
}
if (PipeDebug)
if (CdoDebug::PIPE)
Message("%s wait of readCond", name.c_str());
readCond.wait(locked_mutex);
}
// UNLOCK
}
void
pipeDebug(int debug)
{
PipeDebug = debug;
}
#endif
......@@ -75,9 +75,6 @@ public:
std::string name;
};
void pipeDebug(int debug);
#endif
#endif /* PIPE_H */
......@@ -41,6 +41,7 @@
#include "pstream.h"
#include "dmemory.h"
#include "pthread.h"
#include "cdoDebugOutput.h"
#include <map>
#include <stack>
......@@ -49,8 +50,6 @@
pthread_mutex_t processMutex = PTHREAD_MUTEX_INITIALIZER;
#endif
constexpr bool PROCESS_DEBUG = false;
static process_t *root_process;
static std::map<int, process_t> Process;
......@@ -1221,7 +1220,7 @@ processClosePipes(void)
{
pstream_t *pstreamptr = processInqInputStream(sindex);
if (PROCESS_DEBUG)
if (CdoDebug::PROCESS)
Message("process %d stream %d close streamID %d", processSelf().m_ID, sindex, pstreamptr->self);
if (pstreamptr)
......@@ -1233,7 +1232,7 @@ processClosePipes(void)
{
pstream_t *pstreamptr = processInqOutputStream(sindex);
if (PROCESS_DEBUG)
if (CdoDebug::PROCESS)
Message("process %d stream %d close streamID %d", processSelf().m_ID, sindex, pstreamptr->self);
if (pstreamptr)
......@@ -1253,7 +1252,7 @@ cdoFinish(void)
double p_cputime = 0, p_usertime = 0, p_systime = 0;
#if defined(HAVE_LIBPTHREAD)
if (PROCESS_DEBUG)
if (CdoDebug::PROCESS)
Message("process %d thread %ld", processID, pthread_self());
#endif
......
......@@ -534,7 +534,7 @@ pstream_t::pstreamOpenReadFile(const char* p_args)
}
if (CdoDebug::PSTREAM)
MESSAGE("file ", filename.c_str());
MESSAGE("Opening (r) file: ", filename.c_str());
#if defined(HAVE_LIBPTHREAD)
if (cdoLockIO)
......@@ -579,8 +579,8 @@ pstreamOpenRead(const argument_t *argument)
{
if(CdoDebug::PSTREAM)
{
MESSAGE("Opening new pstream for reading with argument:");
MESSAGE(print_argument((argument_t*)argument));
MESSAGE("Opening new pstream for reading with argument:",
print_argument((argument_t*)argument));
}
pstream_t *pstreamptr = create_pstream();
......@@ -752,7 +752,7 @@ pstreamOpenWriteFile(const argument_t *argument, int filetype)
int pstreamID = pstreamptr->self;
if (CdoDebug::PSTREAM)
MESSAGE("file ", argument->args);
MESSAGE("Opening (w) file ", argument->args);
if (filetype == CDI_UNDEFID)
filetype = CDI_FILETYPE_GRB;
......
......@@ -9,6 +9,7 @@
#include <pthread.h>
#include <errno.h>
#include "error.h"
#include "cdoDebugOutput.h"
#include <mutex>
#include <condition_variable>
#include <iostream>
......@@ -124,24 +125,14 @@ void print_pthread_condattr(const char *caller, pthread_condattr_t *c_attr)
#endif
}
int PTHREAD_Debug = 0;
void Pthread_debug(int debug)
{
PTHREAD_Debug = debug;
}
int Pthread_create(const char *caller, pthread_t *th,
pthread_attr_t *attr, void * (*start_routine)(void *), void *arg)
{
int status;
if ( PTHREAD_Debug ) Message("%s", caller);
if ( CdoDebug::PTHREAD ) Message("%s", caller);
if ( PTHREAD_Debug )
if ( CdoDebug::PTHREAD )
{
Message("%s attributes:", caller);
if ( attr )
......@@ -152,7 +143,7 @@ int Pthread_create(const char *caller, pthread_t *th,
status = pthread_create(th, attr, start_routine, arg);
//if ( PTHREAD_Debug ) Message("-%s (thID = %ld, status = %d)", caller, (long) *th, status);
//if ( CdoDebug::PTHREAD ) Message("-%s (thID = %ld, status = %d)", caller, (long) *th, status);
return status;
}
......@@ -163,11 +154,11 @@ int Pthread_join(const char *caller, pthread_t th, void **thread_return)
int status;
(void) caller;
// if ( PTHREAD_Debug ) Message("+%s (thID = %ld)", caller, (void *) th);
// if ( CdoDebug::PTHREAD ) Message("+%s (thID = %ld)", caller, (void *) th);
status = pthread_join(th, thread_return);
// if ( PTHREAD_Debug ) Message("-%s (thID = %ld, status = %d)", caller, (void *) th, status);
// if ( CdoDebug::PTHREAD ) Message("-%s (thID = %ld, status = %d)", caller, (void *) th, status);
return status;
}
......@@ -177,7 +168,7 @@ void Pthread_mutex_lock(const char *caller, pthread_mutex_t *mutex)
{
int status;
if ( PTHREAD_Debug ) Message("%s (mutex = %p)", caller, (void *) mutex);
if ( CdoDebug::PTHREAD ) Message("%s (mutex = %p)", caller, (void *) mutex);
status = pthread_mutex_lock(mutex);
if ( status != 0 )
......@@ -212,7 +203,7 @@ void Pthread_mutex_unlock(const char *caller, pthread_mutex_t *mutex)
{
int status;
if ( PTHREAD_Debug ) Message("%s (mutex = %p)", caller, (void *) mutex);
if ( CdoDebug::PTHREAD ) Message("%s (mutex = %p)", caller, (void *) mutex);
status = pthread_mutex_unlock(mutex);
if ( status != 0 )
......@@ -246,36 +237,36 @@ void Pthread_mutex_unlock(const char *caller, std::mutex &p_mutex)
void Pthread_cond_signal(const char *caller,std::condition_variable &p_cond_var)
{
if( PTHREAD_Debug)Message("+%s (cond = %p)", caller, (void *) &p_cond_var);
if( CdoDebug::PTHREAD)Message("+%s (cond = %p)", caller, (void *) &p_cond_var);
p_cond_var.notify_all();
if ( PTHREAD_Debug ) Message("-%s (cond = %p)", caller, (void *) &p_cond_var);
if ( CdoDebug::PTHREAD ) Message("-%s (cond = %p)", caller, (void *) &p_cond_var);
}
void Pthread_cond_signal(const char *caller, pthread_cond_t *cond)
{
if ( PTHREAD_Debug ) Message("+%s (cond = %p)", caller, (void *) cond);
if ( CdoDebug::PTHREAD ) Message("+%s (cond = %p)", caller, (void *) cond);
pthread_cond_signal(cond);
if ( PTHREAD_Debug ) Message("-%s (cond = %p)", caller, (void *) cond);
if ( CdoDebug::PTHREAD ) Message("-%s (cond = %p)", caller, (void *) cond);
}
void Pthread_cond_wait(const char *caller, std::condition_variable &p_cond, std::unique_lock<std::mutex> &p_locked_mutex)
{
if ( PTHREAD_Debug ) std::cout << caller << "waiting for condition "<< &p_cond << std::endl;
if ( CdoDebug::PTHREAD ) std::cout << caller << "waiting for condition "<< &p_cond << std::endl;
p_cond.wait(p_locked_mutex);
if ( PTHREAD_Debug ) std::cout << caller << "finished waiting " << &p_cond << std::endl;
if ( CdoDebug::PTHREAD ) std::cout << caller << "finished waiting " << &p_cond << std::endl;
}
void Pthread_cond_wait(const char *caller, pthread_cond_t *cond, pthread_mutex_t *mutex)
{
if ( PTHREAD_Debug ) Message("+%s (cond = %p, mutex = %p)",
if ( CdoDebug::PTHREAD ) Message("+%s (cond = %p, mutex = %p)",
caller, (void *) cond, (void *) mutex);
pthread_cond_wait(cond, mutex);
if ( PTHREAD_Debug ) Message("-%s (cond = %p, mutex = %p)",
if ( CdoDebug::PTHREAD ) Message("-%s (cond = %p, mutex = %p)",
caller, (void *) cond, (void *) mutex);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment