Changeset 1013 for trunk/psLib/src/sys/psTrace.c
- Timestamp:
- Jun 11, 2004, 7:50:01 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psTrace.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psTrace.c
r928 r1013 1 /***************************************************************************** 2 A simple implementation of a tracing facility for Pan-STARRS. Tracing 3 is controlled on a per "component" basis, where a "component" is a name 4 of the form aaa.bbb.ccc where aaa is the most significant part. 5 1 /** @file psTrace.c 2 * \brief basic run-time trace facilities 3 * \ingroup LogTrace 4 * 5 * This file will hold the code for procedures to insert 6 * trace messages into the code. 7 * 8 * @author Robert Lupton, Princeton University 9 * @author George Gusciora, MHPCC 10 * 11 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-06-12 05:50:01 $ 13 * 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 15 */ 16 /***************************************************************************** 6 17 NOTES: 7 18 In the SRD, higher trace levels correspond to a numerically lower trace … … 16 27 trace level of that node. 17 28 18 This code is obfuscated by the fact that component names are of the form19 ".a.b.c.d" where "." is always the root of the tree, and for tree that have20 a depth of 3 or higher (including the root ".") the "." character is also21 the deliminator between different individual nodes in the full component22 name. So, for ".a.b.c.d", the first "." signifies the root of the tree,23 while the last three dots merely act as separators between the node names24 "b", "c", and "d".25 26 29 I added a function psTraceFree() which frees all nodes in the trace component 27 30 tree. Previously, there had been no function in the API which accomplished … … 32 35 #include <string.h> 33 36 #include <stdarg.h> 34 /* #include "pslib.h" */35 37 #include "psMemory.h" 36 38 #include "psTrace.h" … … 38 40 #include "psError.h" 39 41 40 static Component * croot = NULL;// The root of the trace component41 static FILE * traceFP = NULL;42 /***************************************************************************** 43 componentAlloc(): allocate memory for a new node, and initialize members.42 static Component *p_psCroot = NULL; // The root of the trace component 43 static FILE *p_psTraceFP = NULL; // File destination for messages. 44 /***************************************************************************** 45 componentAlloc(): allocate memory for a new node, and initialize members. 44 46 *****************************************************************************/ 45 47 Component *componentAlloc(const char *name, … … 56 58 57 59 /***************************************************************************** 58 componentFree(): free the current node in the root tree, and all 59 childrennodes as well.60 componentFree(): free the current node in the root tree, and all children 61 nodes as well. 60 62 *****************************************************************************/ 61 63 static void componentFree(Component *comp) … … 78 80 79 81 /***************************************************************************** 80 initTrace(): simply initialize the component root tree.82 initTrace(): simply initialize the component root tree. 81 83 *****************************************************************************/ 82 84 static void initTrace(void) 83 85 { 84 if ( croot == NULL) {85 croot = componentAlloc(".", DEFAULT_TRACE_LEVEL);86 } 87 } 88 89 90 /***************************************************************************** 91 Set all trace levels to zero.86 if (p_psCroot == NULL) { 87 p_psCroot = componentAlloc(".", DEFAULT_TRACE_LEVEL); 88 } 89 } 90 91 92 /***************************************************************************** 93 Set all trace levels to zero. 92 94 *****************************************************************************/ 93 95 void p_psTraceReset(Component *currentNode) … … 112 114 } 113 115 116 /***************************************************************************** 117 Set all trace levels to zero. 118 *****************************************************************************/ 114 119 void psTraceReset() 115 120 { 116 p_psTraceReset(croot); 117 } 118 119 121 p_psTraceReset(p_psCroot); 122 } 123 124 125 /***************************************************************************** 126 Free all nodes in the component tree. 127 *****************************************************************************/ 120 128 void psTraceFree() 121 129 { 122 componentFree( croot);123 } 124 125 126 /***************************************************************************** 127 componentAdd(): Adds the component named "addNodeName" to the root tree.130 componentFree(p_psCroot); 131 } 132 133 134 /***************************************************************************** 135 componentAdd(): Adds the component named "addNodeName" to the root tree. 128 136 129 NOTE: replace the call to strsep() with a call to strtok(), which conforms130 to ANSI-C.137 NOTE: replace the call to strsep() with a call to strtok(), which conforms 138 to ANSI-C. 131 139 *****************************************************************************/ 132 140 static void componentAdd(const char *addNodeName, 133 141 int level) 134 142 { 135 int i = 0; 136 char name[strlen(addNodeName) + 1]; 137 // buffer for writeable copy. 143 int i = 0; // Loop index variable. 144 char name[strlen(addNodeName) + 1]; // buffer for writeable copy. 138 145 char *pname=name; 139 146 char *firstComponent = NULL; // first component of name 140 Component *currentNode = croot;147 Component *currentNode = p_psCroot; 141 148 int nodeExists = 0; 142 149 143 150 // Is this the root node? If so, simply set level and return. 144 151 if (strcmp(".", addNodeName) == 0) { 145 croot->level = level;152 p_psCroot->level = level; 146 153 return; 147 154 } … … 199 206 { 200 207 // If the root component tree does not exist, then initialize it. 201 if ( croot == NULL) {208 if (p_psCroot == NULL) { 202 209 initTrace(); 203 210 } … … 230 237 char *pname=name; 231 238 char *firstComponent = NULL; // first component of name 232 Component *currentNode = croot;239 Component *currentNode = p_psCroot; 233 240 int i = 0; 234 241 … … 238 245 239 246 if (strcmp(".", aname) == 0) { 240 return( croot->level);247 return(p_psCroot->level); 241 248 } 242 249 … … 282 289 int psTraceGetLevel(const char *name) 283 290 { 284 if ( croot == NULL) {291 if (p_psCroot == NULL) { 285 292 return(UNKNOWN_TRACE_LEVEL); 286 293 } … … 328 335 329 336 /***************************************************************************** 330 psPrintTraceLevels() 331 Simply print all the trace levels in the trace levelcomponent tree.332 Inputs:333 none 334 Outputs:335 none 336 Returns:337 psPrintTraceLevels(): Simply print all the trace levels in the trace level 338 component tree. 339 Inputs: 340 none 341 Outputs: 342 none 343 Returns: 337 344 null 338 345 *****************************************************************************/ 339 346 void psTracePrintLevels(void) 340 347 { 341 if ( croot == NULL) {348 if (p_psCroot == NULL) { 342 349 return; 343 350 } 344 351 345 doPrintTraceLevels( croot, 0);346 } 347 348 349 /***************************************************************************** 350 p_psTrace(): we display the trace message to standard output if the trace351 level of that message, supplied by the parameter "level" is higher 352 than the trace level that is currently associated with the component 353 named by theparameter "comp".354 Input:352 doPrintTraceLevels(p_psCroot, 0); 353 } 354 355 356 /***************************************************************************** 357 p_psTrace(): we display the trace message to standard output if the trace 358 level of that message, supplied by the parameter "level" is higher than the 359 trace level that is currently associated with the component named by the 360 parameter "comp". 361 Input: 355 362 comp 356 363 level 357 364 ... a printf-style output string. 358 Output:359 none 360 Return:365 Output: 366 none 367 Return: 361 368 null 362 369 *****************************************************************************/ … … 384 391 fmt = va_arg(ap, char *); 385 392 386 if ( traceFP != NULL) {393 if (p_psTraceFP != NULL) { 387 394 // We indent each message one space for each level of the message. 388 395 for (i = 0; i < level; i++) { 389 fprintf( traceFP, " ");396 fprintf(p_psTraceFP, " "); 390 397 } 391 vfprintf( traceFP, fmt, ap);398 vfprintf(p_psTraceFP, fmt, ap); 392 399 } else { 393 400 // We indent each message one space for each level of the message. … … 405 412 void psTraceSetDestination(FILE *fp) 406 413 { 407 traceFP = fp;408 } 414 p_psTraceFP = fp; 415 }
Note:
See TracChangeset
for help on using the changeset viewer.
