Changeset 1407 for trunk/psLib/src/sysUtils/psTrace.c
- Timestamp:
- Aug 6, 2004, 2:06:06 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sysUtils/psTrace.c (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sysUtils/psTrace.c
r1406 r1407 1 1 2 /** @file psTrace.c 2 3 * \brief basic run-time trace facilities … … 9 10 * @author George Gusciora, MHPCC 10 11 * 11 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-08-0 6 22:34:05$12 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-08-07 00:06:06 $ 13 14 * 14 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 15 16 */ 17 16 18 /***************************************************************************** 17 19 NOTES: … … 34 36 #ifndef PS_NO_TRACE 35 37 36 # include <stdlib.h>37 # include <stdio.h>38 # include <string.h>39 # include <stdarg.h>40 # include "psMemory.h"41 # include "psTrace.h"42 # include "psString.h"43 # include "psError.h"44 45 static p_psComponent *p_psCroot = NULL; // The root of the trace component46 static FILE *p_psTraceFP = NULL; // File destination for messages.47 48 static void componentFree(p_psComponent * comp);49 static p_psComponent *componentAlloc(const char *name, int level);38 # include <stdlib.h> 39 # include <stdio.h> 40 # include <string.h> 41 # include <stdarg.h> 42 # include "psMemory.h" 43 # include "psTrace.h" 44 # include "psString.h" 45 # include "psError.h" 46 47 static p_psComponent *p_psCroot = NULL; // The root of the trace component 48 static FILE *p_psTraceFP = NULL; // File destination for messages. 49 50 static void componentFree(p_psComponent * comp); 51 static p_psComponent *componentAlloc(const char *name, int level); 50 52 51 53 /***************************************************************************** 52 54 componentAlloc(): allocate memory for a new node, and initialize members. 53 55 *****************************************************************************/ 54 static p_psComponent *componentAlloc(const char *name, 55 int level) 56 static p_psComponent *componentAlloc(const char *name, int level) 56 57 { 57 58 p_psComponent *comp = psAlloc(sizeof(p_psComponent)); 58 p_psMemSetDeallocator(comp,(psFreeFcn)componentFree); 59 60 p_psMemSetDeallocator(comp, (psFreeFcn) componentFree); 59 61 comp->name = psStringCopy(name); 60 62 comp->level = level; … … 64 66 } 65 67 66 67 68 /***************************************************************************** 68 69 componentFree(): free the current node in the root tree, and all children 69 70 nodes as well. 70 71 *****************************************************************************/ 71 static void componentFree(p_psComponent * comp)72 static void componentFree(p_psComponent * comp) 72 73 { 73 74 if (comp == NULL) { … … 85 86 } 86 87 87 88 88 /***************************************************************************** 89 89 initTrace(): simply initialize the component root tree. … … 96 96 } 97 97 98 99 98 /***************************************************************************** 100 99 Set all trace levels to zero. 101 100 *****************************************************************************/ 102 void p_psTraceReset(p_psComponent * currentNode)101 void p_psTraceReset(p_psComponent * currentNode) 103 102 { 104 103 int i = 0; … … 109 108 110 109 currentNode->level = 0; 111 for (i =0;i<currentNode->n;i++) {110 for (i = 0; i < currentNode->n; i++) { 112 111 if (NULL == currentNode->subcomp[i]) { 113 112 psError(__func__, 114 "Sub-component %d of node %s in the trace tree is NULL.\n", 115 i, currentNode->name); 113 "Sub-component %d of node %s in the trace tree is NULL.\n", i, currentNode->name); 116 114 } else { 117 115 p_psTraceReset(currentNode->subcomp[i]); … … 129 127 } 130 128 131 132 129 /***************************************************************************** 133 130 Free all nodes in the component tree. … … 137 134 psFree(p_psCroot); 138 135 } 139 140 136 141 137 /***************************************************************************** … … 145 141 to ANSI-C. 146 142 *****************************************************************************/ 147 static void componentAdd(const char *addNodeName, 148 int level) 149 { 150 int i = 0; // Loop index variable. 151 char name[strlen(addNodeName) + 1]; // buffer for writeable copy. 152 char *pname=name; 153 char *firstComponent = NULL; // first component of name 143 static void componentAdd(const char *addNodeName, int level) 144 { 145 int i = 0; // Loop index variable. 146 char name[strlen(addNodeName) + 1]; // buffer for writeable copy. 147 char *pname = name; 148 char *firstComponent = NULL; // first component of name 154 149 p_psComponent *currentNode = p_psCroot; 155 int nodeExists = 0;156 157 // Is this the root node? If so, simply set level and return.150 int nodeExists = 0; 151 152 // Is this the root node? If so, simply set level and return. 158 153 if (strcmp(".", addNodeName) == 0) { 159 154 p_psCroot->level = level; … … 162 157 163 158 if (addNodeName[0] != '.') { 164 printf("ERROR: failed to add %s to the root component tree.\n", 165 addNodeName); 159 printf("ERROR: failed to add %s to the root component tree.\n", addNodeName); 166 160 exit(1); 167 161 } … … 188 182 if (nodeExists == 0) { 189 183 currentNode->subcomp = psRealloc(currentNode->subcomp, 190 (currentNode->n + 1) * sizeof(p_psComponent*)); 191 currentNode->n = (currentNode->n)+1; 192 193 currentNode->subcomp[(currentNode->n)-1] = 194 componentAlloc(firstComponent, level); 195 } 196 } 197 } 198 184 (currentNode->n + 1) * sizeof(p_psComponent *)); 185 currentNode->n = (currentNode->n) + 1; 186 187 currentNode->subcomp[(currentNode->n) - 1] = componentAlloc(firstComponent, level); 188 } 189 } 190 } 199 191 200 192 /***************************************************************************** … … 210 202 *****************************************************************************/ 211 203 int psTraceSetLevel(const char *comp, // component of interest 212 int level) // desired trace level204 int level) // desired trace level 213 205 { 214 206 // If the root component tree does not exist, then initialize it. … … 216 208 initTrace(); 217 209 } 218 219 210 // Add the new component to the component tree. 220 211 componentAdd(comp, level); … … 223 214 return 0; 224 215 } 225 226 216 227 217 /***************************************************************************** … … 241 231 static int doGetTraceLevel(const char *aname) 242 232 { 243 char name[strlen(aname) + 1];// need a writeable copy: for strsep()244 char *pname=name;245 char *firstComponent = NULL;// first component of name233 char name[strlen(aname) + 1]; // need a writeable copy: for strsep() 234 char *pname = name; 235 char *firstComponent = NULL; // first component of name 246 236 p_psComponent *currentNode = p_psCroot; 247 int i = 0;237 int i = 0; 248 238 249 239 if (NULL == currentNode) { 250 return (PS_UNKNOWN_TRACE_LEVEL);240 return (PS_UNKNOWN_TRACE_LEVEL); 251 241 } 252 242 253 243 if (strcmp(".", aname) == 0) { 254 return (p_psCroot->level);244 return (p_psCroot->level); 255 245 } 256 246 257 247 if (aname[0] != '.') { 258 return (PS_UNKNOWN_TRACE_LEVEL);248 return (PS_UNKNOWN_TRACE_LEVEL); 259 249 } 260 250 … … 266 256 if (NULL == currentNode->subcomp[i]) { 267 257 psError(__func__, 268 "Sub-component %d of node %s in trace tree is NULL.\n", 269 i, currentNode->name); 258 "Sub-component %d of node %s in trace tree is NULL.\n", i, currentNode->name); 270 259 } 271 260 … … 273 262 currentNode = currentNode->subcomp[i]; 274 263 if (pname == NULL) { 275 return (currentNode->level);264 return (currentNode->level); 276 265 } 277 266 } 278 267 } 279 268 } 280 return(PS_UNKNOWN_TRACE_LEVEL); 281 } 282 269 return (PS_UNKNOWN_TRACE_LEVEL); 270 } 283 271 284 272 /***************************************************************************** … … 297 285 { 298 286 if (p_psCroot == NULL) { 299 return(PS_UNKNOWN_TRACE_LEVEL); 300 } 301 287 return (PS_UNKNOWN_TRACE_LEVEL); 288 } 302 289 // Search the component root tree, determine the trace level. 303 return(doGetTraceLevel(name)); 304 } 305 290 return (doGetTraceLevel(name)); 291 } 306 292 307 293 /***************************************************************************** … … 317 303 null 318 304 *****************************************************************************/ 319 static void doPrintTraceLevels(const p_psComponent *comp, 320 int depth) 305 static void doPrintTraceLevels(const p_psComponent * comp, int depth) 321 306 { 322 307 int i = 0; … … 327 312 } else { 328 313 if (comp->level == PS_UNKNOWN_TRACE_LEVEL) { 329 printf("%*s%-*s %s\n", depth, "", 20 - depth, 330 comp->name, "."); 314 printf("%*s%-*s %s\n", depth, "", 20 - depth, comp->name, "."); 331 315 } else { 332 printf("%*s%-*s %d\n", depth, "", 20 - depth, 333 comp->name, comp->level); 316 printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level); 334 317 } 335 318 } 336 319 337 320 for (i = 0; i < comp->n; i++) { 338 doPrintTraceLevels(comp->subcomp[i], depth+1); 339 } 340 } 341 321 doPrintTraceLevels(comp->subcomp[i], depth + 1); 322 } 323 } 342 324 343 325 /***************************************************************************** … … 359 341 doPrintTraceLevels(p_psCroot, 0); 360 342 } 361 362 343 363 344 /***************************************************************************** … … 376 357 *****************************************************************************/ 377 358 void p_psTrace(const char *comp, // component being traced 378 int level, // desired trace level379 ...) // arguments359 int level, // desired trace level 360 ...) // arguments 380 361 { 381 362 char *fmt = NULL; … … 384 365 385 366 if (NULL == comp) { 386 psError(__func__, 387 "p_psTrace() called on a NULL trace level tree\n"); 388 } 389 367 psError(__func__, "p_psTrace() called on a NULL trace level tree\n"); 368 } 390 369 // Only display this message if it's trace level is less than the level 391 370 // of it's associatedcomponent. … … 413 392 va_end(ap); 414 393 } 415 416 // NOTE: should we free *fmt as well? Read the man page. 417 } 418 419 void psTraceSetDestination(FILE *fp) 394 // NOTE: should we free *fmt as well? Read the man page. 395 } 396 397 void psTraceSetDestination(FILE * fp) 420 398 { 421 399 p_psTraceFP = fp;
Note:
See TracChangeset
for help on using the changeset viewer.
