IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 7, 2004, 8:00:49 PM (22 years ago)
Author:
gusciora
Message:

...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psTrace.c

    r1713 r1718  
    99 *  @author George Gusciora, MHPCC
    1010 *
    11  *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-09-08 00:09:06 $
     11 *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-09-08 05:59:41 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2727 not the same thing as a node's "level", which corresponds to the
    2828 trace level of that node.
     29 
     30I 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
    2937 
    3038 *****************************************************************************/
     
    4048#include "psString.h"
    4149#include "psError.h"
    42 #include "psLogMsg.h"
    43 
    44 #include "psSysUtilsErrors.h"
    45 #define ERRORNAME_PREFIX PS_ERRORNAME_DOMAIN ".psTrace."
     50#include "psAbort.h"
    4651
    4752static p_psComponent* cRoot = NULL; // The root of the trace component
     
    98103/*****************************************************************************
    99104Set all trace levels to zero.
     105 
     106XXX: Currently, no function calls this routine.
    100107 *****************************************************************************/
    101108void p_psTraceReset(p_psComponent* currentNode)
     
    110117    for (i = 0; i < currentNode->n; i++) {
    111118        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);
    115121        } else {
    116122            p_psTraceReset(currentNode->subcomp[i]);
     
    125131void psTraceReset()
    126132{
    127     psFree(cRoot);
     133    componentFree(cRoot);
    128134    cRoot = NULL;
    129135}
     
    135141to ANSI-C.
    136142 *****************************************************************************/
    137 static bool componentAdd(const char *addNodeName, int level)
     143static void componentAdd(const char *addNodeName, int level)
    138144{
    139145    int i = 0;                  // Loop index variable.
     
    146152    // XXX: Verify that this is the correct behavior.
    147153    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");
    151155    }
    152156
     
    154158    if (strcmp(".", addNodeName) == 0) {
    155159        cRoot->level = level;
    156         return true;
     160        return;
    157161    }
    158162
    159163    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);
    164166    }
    165167
     
    186188            currentNode->subcomp = psRealloc(currentNode->subcomp,
    187189                                             (currentNode->n + 1) * sizeof(p_psComponent* ));
    188             currentNode->n++;
     190            currentNode->n = (currentNode->n) + 1;
    189191
    190192            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);
    192195            } 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    }
    200207}
    201208
     
    211218 zero
    212219*****************************************************************************/
    213 bool psTraceSetLevel(const char *comp,   // component of interest
    214                      int level)  // desired trace level
     220int psTraceSetLevel(const char *comp,   // component of interest
     221                    int level)  // desired trace level
    215222{
    216223    // If the root component tree does not exist, then initialize it.
     
    219226    }
    220227    // 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
    226230    // return 0 on success.
    227     return true;
     231    return 0;
    228232}
    229233
     
    249253    p_psComponent* currentNode = cRoot;
    250254    int i = 0;
     255    int defaultLevel = 0;
    251256
    252257    if (NULL == currentNode) {
     
    262267    }
    263268
     269    defaultLevel = cRoot->level;
    264270    strcpy(name, aname);
    265271    pname = &name[1];
     
    268274        for (i = 0; i < currentNode->n; i++) {
    269275            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);
    273278            }
    274279
    275280            if (strcmp(currentNode->subcomp[i]->name, firstComponent) == 0) {
    276281                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:
    277288                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                    }
    279294                }
    280295            }
    281296        }
    282297    }
    283     return (PS_UNKNOWN_TRACE_LEVEL);
    284 }
    285 
    286 /*****************************************************************************
    287     psGetTraceLevel()
     298    return(defaultLevel);
     299}
     300
     301/*****************************************************************************
     302    psTraceLevelGet()
    288303 Return a trace level of "name" in the root component tree.  If the
    289304 exact string of components in "name" does not exist in the root
     
    303318    // Search the component root tree, determine the trace level.
    304319    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 *****************************************************************************/
     334static 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    }
    305353}
    306354
     
    317365 null
    318366 *****************************************************************************/
    319 static void doPrintTraceLevels(const p_psComponent* comp, int depth)
     367static void doPrintTraceLevels(const p_psComponent* comp,
     368                               int depth,
     369                               int defLevel)
    320370{
    321371    int i = 0;
    322372
    323373    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");
    326375    } 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);
    329379        } 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);
    331382        }
    332383    }
    333384
    334385    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
    338394
    339395/*****************************************************************************
     
    353409    }
    354410
    355     doPrintTraceLevels(cRoot, 0);
     411    doPrintTraceLevels(cRoot, 0, PS_DEFAULT_TRACE_LEVEL);
    356412}
    357413
     
    379435
    380436    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");
    385438    }
    386439    // Only display this message if it's trace level is less than the level
Note: See TracChangeset for help on using the changeset viewer.