psTrace.h

Go to the documentation of this file.
00001 /** @file psTrace.h
00002  *
00003  *  @brief basic run-time trace facilities
00004  *
00005  *  This file will hold the prototypes for defining procedures to insert
00006  *  trace messages into the code.
00007  *
00008  *  @author Robert Lupton, Princeton University
00009  *  @author GLG, MHPCC
00010  *
00011  *  @version $Revision: 1.54 $ $Name:  $
00012  *  @date $Date: 2007/01/31 00:38:46 $
00013  *
00014  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
00015  */
00016 
00017 #ifndef PS_TRACE_H
00018 #define PS_TRACE_H 1
00019 
00020 /// @addtogroup SysUtils System Utilities
00021 /// @{
00022 
00023 #include <stdarg.h>
00024 #include "psMetadata.h"
00025 
00026 #define PS_UNKNOWN_TRACE_LEVEL -9999   // we don't know this name's level
00027 #define PS_DEFAULT_TRACE_LEVEL -1
00028 #define PS_THE_OTHER_DEFAULT_TRACE_LEVEL 0
00029 
00030 enum {
00031     PS_TRACE_TO_NONE = 0,             ///< turn off all traces
00032     PS_TRACE_TO_STDOUT = 1,           ///< trace to system's stdout
00033     PS_TRACE_TO_STDERR = 2,           ///< trace to system's stderr
00034 };
00035 
00036 /** Functions **************************************************************/
00037 
00038 //#define PS_NO_TRACE 1   ///< to turn off all tracing
00039 
00040 // XXX EAM : the old 'empty' values of (void) 0 are dangerous
00041 # if defined(PS_NO_TRACE)
00042     #   define psTrace(facil, level, ...)   /* do nothing */
00043     #   define p_psTrace(facil, level, ...) /* do nothing */
00044     #   define psTraceSetLevel(facil,level) /* do nothing */
00045     #   define psTraceGetLevel(facil)       -INFINITY /* really really low level */
00046     #   define psTraceReset()               /* do nothing */
00047     #   define psTraceFree()                /* do nothing */
00048     #   define psTracePrintLevels()         /* do nothing */
00049     #   define psTraceSetDestination(fp)    /* do nothing */
00050     #   define psTraceGetDestination()      2 /* destination is stderr */
00051     #   define psTraceSetFormat(format)     /* do nothing */
00052     #   define PS_TRACE_ON                  0
00053 
00054     # else /* PS_NO_TRACE */
00055         #   define PS_TRACE_ON 1
00056 
00057         /** Basic structure for the component tree.  A component is a string of the
00058             form aaa.bbb.ccc, and may itself contain further subcomponents.  The
00059             Component structure doesn't in fact contain it's full name, but only the
00060             last part. */
00061         typedef struct p_psComponent
00062         {
00063             const char *name;                  ///< last part of name of component
00064             psS32 level;                       ///< trace level for this component
00065             bool p_psSpecified;                ///< whether the component is specified
00066             psS32 n;                           ///< number of subcomponents
00067             struct p_psComponent* *subcomp;    ///< next level of subcomponents
00068         }
00069 p_psComponent;
00070 
00071 /** This procedure sets the trace format for future trace messages.  The argument
00072  *  must be a character string consistsing of the letters H (host), L
00073  *  (level), M (message), N (name), and T (time).  The default is "THLNM".
00074  *  Deleting a letter from the string will cause the associated information
00075  *  to not be logged.  This procedure does not alter the order in which
00076  *  the messages are displayed.
00077  *
00078  *  @return bool:       True if successful, otherwise false.
00079  */
00080 bool psTraceSetFormat(
00081     const char *format                 ///< Specifies the system trace format
00082 );
00083 
00084 #ifdef DOXYGEN
00085 /** Sends a trace message. */
00086 void psTrace(
00087     const char *facil,                 ///< facilty of interest
00088     int level,                         ///< desired trace level
00089     const char *format,                ///< printf-style format command
00090     ...                                ///< trace message arguments
00091 );
00092 
00093 /** Get the trace level
00094  *
00095  *  @return int:    Trace Level
00096  */
00097 int psTraceGetLevel(
00098     const char *facil                  ///< facilty of interest
00099 );
00100 
00101 #else // DOXYGEN
00102 #ifdef __GNUC__
00103 /// Send a trace message
00104 void p_psTrace(
00105     const char* file,                  ///< file name
00106     int lineno,                        ///< line number in file
00107     const char* func,                  ///< function name
00108     const char *facil,                 ///< facilty of interest
00109     psS32 level,                       ///< desired trace level
00110     const char *format,                ///< printf-style format command
00111     ...                                ///< trace message arguments
00112 ) __attribute__((format(printf, 6, 7)));
00113 #else // __GNUC__
00114 void p_psTrace(
00115     const char* file,                  ///< file name
00116     int lineno,                        ///< line number in file
00117     const char* func,                  ///< function name
00118     const char *facil,                 ///< facilty of interest
00119     psS32 level,                       ///< desired trace level
00120     const char *format,                ///< printf-style format command
00121     ...                                ///< trace message arguments
00122 );
00123 #endif // __GNUC__
00124 
00125 /** Get the trace level
00126  *
00127  *  @return int:    Trace Level
00128  */
00129 int p_psTraceGetLevel(
00130     const char* file,                  ///< file name
00131     int lineno,                        ///< line number in file
00132     const char *func,                  ///< function name
00133     const char *facil                  ///< facilty of interest
00134 );
00135 
00136 #ifndef SWIG
00137 #define psTrace(facil, level, ...) p_psTrace(__FILE__,__LINE__,__func__,facil, level, __VA_ARGS__)
00138 #define psTraceGetLevel(facil) p_psTraceGetLevel(__FILE__,__LINE__,__func__,facil)
00139 /** Sends a trace message. */
00140 void psTraceV(
00141     const char *facil,                 ///< facilty of interest
00142     int level,                         ///< desired trace level
00143     const char *format,                ///< printf-style format command
00144     va_list ap                         ///< varargs argument list
00145 );
00146 #endif /* SWIG */
00147 #endif /* DOXYGEN */
00148 
00149 /** Set trace level
00150  *
00151  *  @return int:       The previous level.
00152  */
00153 int psTraceSetLevel(
00154     const char *facil,                 ///< facilty of interest
00155     int level                          ///< desired trace level
00156 );
00157 
00158 /// Set all trace levels to zero (do not free nodes in the facility tree).
00159 void psTraceReset(void);
00160 
00161 /// print trace levels
00162 void psTracePrintLevels(void);
00163 
00164 /// Set the destination of future trace messages.
00165 bool psTraceSetDestination(
00166     int fd                             ///< File descriptor
00167 );
00168 
00169 /** Get the current destination for trace messages.
00170  *
00171  *  @return FILE*:      File Destination
00172  */
00173 int psTraceGetDestination(void);
00174 
00175 /// Return a psMetadata summarising the trace levels
00176 psMetadata *psTraceLevels(void);
00177 
00178 /// @}
00179 #endif /* PS_NO_TRACE */
00180 #endif /* PS_TRACE_H */

Generated on Fri Feb 2 22:24:35 2007 for pslib by  doxygen 1.5.1