Changeset 1718 for trunk/psLib/src/sysUtils/psTrace.c
- Timestamp:
- Sep 7, 2004, 8:00:49 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sysUtils/psTrace.c (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sysUtils/psTrace.c
r1713 r1718 9 9 * @author George Gusciora, MHPCC 10 10 * 11 * @version $Revision: 1.2 1$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-09-08 0 0:09:06$11 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-09-08 05:59:41 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 27 27 not the same thing as a node's "level", which corresponds to the 28 28 trace level of that node. 29 30 I think the following is the correct behavior, but not sure: 31 PS_UNKNOWN_TRACE_LEVEL: We never set the level of a component to this 32 value. This value is only used when psTraceGetLevel is called with 33 a bad component name, or if the component root is undefined, I think. 34 35 PS_DEFAULT_TRACE_LEVEL: This should only be used when adding the 36 intermediate components of a long name. Ie. the "B" in .A.B.C 29 37 30 38 *****************************************************************************/ … … 40 48 #include "psString.h" 41 49 #include "psError.h" 42 #include "psLogMsg.h" 43 44 #include "psSysUtilsErrors.h" 45 #define ERRORNAME_PREFIX PS_ERRORNAME_DOMAIN ".psTrace." 50 #include "psAbort.h" 46 51 47 52 static p_psComponent* cRoot = NULL; // The root of the trace component … … 98 103 /***************************************************************************** 99 104 Set all trace levels to zero. 105 106 XXX: Currently, no function calls this routine. 100 107 *****************************************************************************/ 101 108 void p_psTraceReset(p_psComponent* currentNode) … … 110 117 for (i = 0; i < currentNode->n; i++) { 111 118 if (NULL == currentNode->subcomp[i]) { 112 psLogMsg(ERRORNAME_PREFIX "p_psTraceReset", PS_LOG_WARN, 113 PS_ERRORTEXT_psTrace_NULL_SUBCOMPONENT, 114 i, currentNode->name); 119 psError(__func__, 120 "Sub-component %d of node %s in the trace tree is NULL.\n", i, currentNode->name); 115 121 } else { 116 122 p_psTraceReset(currentNode->subcomp[i]); … … 125 131 void psTraceReset() 126 132 { 127 psFree(cRoot);133 componentFree(cRoot); 128 134 cRoot = NULL; 129 135 } … … 135 141 to ANSI-C. 136 142 *****************************************************************************/ 137 static boolcomponentAdd(const char *addNodeName, int level)143 static void componentAdd(const char *addNodeName, int level) 138 144 { 139 145 int i = 0; // Loop index variable. … … 146 152 // XXX: Verify that this is the correct behavior. 147 153 if (strcmp("", addNodeName) == 0) { 148 psErrorMsg(ERRORNAME_PREFIX "componentAdd",PS_ERR_BAD_PARAMETER_NULL,true, 149 PS_ERRORTEXT_psTrace_ADD_NULL_COMPONENT); 150 return false; 154 psAbort(__func__, "Failed to add null component to trace tree.\n"); 151 155 } 152 156 … … 154 158 if (strcmp(".", addNodeName) == 0) { 155 159 cRoot->level = level; 156 return true;160 return; 157 161 } 158 162 159 163 if (addNodeName[0] != '.') { 160 psErrorMsg(ERRORNAME_PREFIX "componentAdd",PS_ERR_BAD_PARAMETER_VALUE,true, 161 PS_ERRORTEXT_psTrace_MALFORMED_COMPONENT_NAME, 162 addNodeName); 163 return false; 164 printf("ERROR: failed to add %s to the root component tree.\n", addNodeName); 165 exit(1); 164 166 } 165 167 … … 186 188 currentNode->subcomp = psRealloc(currentNode->subcomp, 187 189 (currentNode->n + 1) * sizeof(p_psComponent* )); 188 currentNode->n ++;190 currentNode->n = (currentNode->n) + 1; 189 191 190 192 if (pname == NULL) { 191 currentNode->subcomp[currentNode->n - 1] = componentAlloc(firstComponent, level); 193 // This is the final component to add. 194 currentNode->subcomp[(currentNode->n) - 1] = componentAlloc(firstComponent, level); 192 195 } else { 193 currentNode->subcomp[currentNode->n - 1] = componentAlloc(firstComponent, currentNode->level); 194 } 195 currentNode = currentNode->subcomp[currentNode->n - 1]; 196 } 197 } 198 199 return true; 196 // We are adding an intermediate component. The trace level 197 // is not defined. An undefined trace level inherits the 198 // trace level of it's parent. However, we do not set that 199 // specifically here since that would inheritance to be a 200 // static, one-time, type of behavior. 201 202 currentNode->subcomp[(currentNode->n) - 1] = componentAlloc(firstComponent, PS_DEFAULT_TRACE_LEVEL); 203 } 204 currentNode = currentNode->subcomp[(currentNode->n) - 1]; 205 } 206 } 200 207 } 201 208 … … 211 218 zero 212 219 *****************************************************************************/ 213 boolpsTraceSetLevel(const char *comp, // component of interest214 int level) // desired trace level220 int psTraceSetLevel(const char *comp, // component of interest 221 int level) // desired trace level 215 222 { 216 223 // If the root component tree does not exist, then initialize it. … … 219 226 } 220 227 // Add the new component to the component tree. 221 if ( !componentAdd(comp, level) ) { 222 psErrorMsg(ERRORNAME_PREFIX "psTraceSetLevel", PS_ERR_UNKNOWN, false, 223 PS_ERRORTEXT_psTrace_FAILED_TO_ADD_COMPONENT,level,comp); 224 return false; 225 } 228 componentAdd(comp, level); 229 226 230 // return 0 on success. 227 return true;231 return 0; 228 232 } 229 233 … … 249 253 p_psComponent* currentNode = cRoot; 250 254 int i = 0; 255 int defaultLevel = 0; 251 256 252 257 if (NULL == currentNode) { … … 262 267 } 263 268 269 defaultLevel = cRoot->level; 264 270 strcpy(name, aname); 265 271 pname = &name[1]; … … 268 274 for (i = 0; i < currentNode->n; i++) { 269 275 if (NULL == currentNode->subcomp[i]) { 270 psLogMsg(ERRORNAME_PREFIX "p_psTraceReset", PS_LOG_WARN, 271 PS_ERRORTEXT_psTrace_NULL_SUBCOMPONENT, 272 i, currentNode->name); 276 psError(__func__, 277 "Sub-component %d of node %s in trace tree is NULL.\n", i, currentNode->name); 273 278 } 274 279 275 280 if (strcmp(currentNode->subcomp[i]->name, firstComponent) == 0) { 276 281 currentNode = currentNode->subcomp[i]; 282 // For level inheritance purpose, we save the level of this 283 // component if it is not DEFAULT. 284 if (currentNode->level != PS_DEFAULT_TRACE_LEVEL) { 285 defaultLevel = currentNode->level; 286 } 287 // Determine if thisis the last component: 277 288 if (pname == NULL) { 278 return (currentNode->level); 289 if (currentNode->level != PS_DEFAULT_TRACE_LEVEL) { 290 return (currentNode->level); 291 } else { 292 return(PS_DEFAULT_TRACE_LEVEL); 293 } 279 294 } 280 295 } 281 296 } 282 297 } 283 return (PS_UNKNOWN_TRACE_LEVEL);284 } 285 286 /***************************************************************************** 287 ps GetTraceLevel()298 return(defaultLevel); 299 } 300 301 /***************************************************************************** 302 psTraceLevelGet() 288 303 Return a trace level of "name" in the root component tree. If the 289 304 exact string of components in "name" does not exist in the root … … 303 318 // Search the component root tree, determine the trace level. 304 319 return (doGetTraceLevel(name)); 320 } 321 322 /***************************************************************************** 323 doPrintTraceLevelsOld() 324 This function recursively searches the component tree supplied by the 325 parameter "comp" and prints the name and level of each component. 326 Inputs: 327 comp: a node in the component tree. 328 level: the level of that node 329 Outputs: 330 none 331 Returns: 332 null 333 *****************************************************************************/ 334 static void doPrintTraceLevelsOld(const p_psComponent* comp, int depth) 335 { 336 int i = 0; 337 338 if (comp->name[0] == '\0') { 339 printf("%*s%-*s %d\n", depth, "", 20 - depth, 340 "(root)", (comp->level == PS_DEFAULT_TRACE_LEVEL) ? 0 : comp->level); 341 } else { 342 if (comp->level == PS_DEFAULT_TRACE_LEVEL) { 343 printf("%*s%-*s %s\n", depth, "", 20 - depth, comp->name, "."); 344 } else { 345 printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name, 346 comp->level); 347 } 348 } 349 350 for (i = 0; i < comp->n; i++) { 351 doPrintTraceLevelsOld(comp->subcomp[i], depth + 1); 352 } 305 353 } 306 354 … … 317 365 null 318 366 *****************************************************************************/ 319 static void doPrintTraceLevels(const p_psComponent* comp, int depth) 367 static void doPrintTraceLevels(const p_psComponent* comp, 368 int depth, 369 int defLevel) 320 370 { 321 371 int i = 0; 322 372 323 373 if (comp->name[0] == '\0') { 324 printf("%*s%-*s %d\n", depth, "", 20 - depth, 325 "(root)", (comp->level == PS_UNKNOWN_TRACE_LEVEL) ? 0 : comp->level); 374 psAbort(__func__, "component name is NULL\n"); 326 375 } else { 327 if (comp->level == PS_UNKNOWN_TRACE_LEVEL) { 328 printf("%*s%-*s %s\n", depth, "", 20 - depth, comp->name, "."); 376 if (comp->level == PS_DEFAULT_TRACE_LEVEL) { 377 printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name, 378 defLevel); 329 379 } else { 330 printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level); 380 printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name, 381 comp->level); 331 382 } 332 383 } 333 384 334 385 for (i = 0; i < comp->n; i++) { 335 doPrintTraceLevels(comp->subcomp[i], depth + 1); 336 } 337 } 386 if (comp->level == PS_DEFAULT_TRACE_LEVEL) { 387 doPrintTraceLevels(comp->subcomp[i], depth + 1, defLevel); 388 } else { 389 doPrintTraceLevels(comp->subcomp[i], depth + 1, comp->level); 390 } 391 } 392 } 393 338 394 339 395 /***************************************************************************** … … 353 409 } 354 410 355 doPrintTraceLevels(cRoot, 0 );411 doPrintTraceLevels(cRoot, 0, PS_DEFAULT_TRACE_LEVEL); 356 412 } 357 413 … … 379 435 380 436 if (NULL == comp) { 381 psErrorMsg(ERRORNAME_PREFIX "psTrace", PS_ERR_BAD_PARAMETER_NULL, true, 382 PS_ERRORTEXT_psTrace_NULL_TRACETREE, 383 __func__); 384 return; 437 psError(__func__, "p_psTrace() called on a NULL trace level tree\n"); 385 438 } 386 439 // Only display this message if it's trace level is less than the level
Note:
See TracChangeset
for help on using the changeset viewer.
