IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1640


Ignore:
Timestamp:
Aug 27, 2004, 11:45:01 AM (22 years ago)
Author:
gusciora
Message:

...

Location:
trunk/psLib
Files:
5 edited

Legend:

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

    r1441 r1640  
    1 
    21/** @file psTrace.c
    32 *  \brief basic run-time trace facilities
     
    109 *  @author George Gusciora, MHPCC
    1110 *
    12  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-08-09 23:40:55 $
     11 *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-08-27 21:45:01 $
    1413 *
    1514 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4443#include "psString.h"
    4544#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.
     45#include "psAbort.h"
     46
     47static p_psComponent* cRoot = NULL; // The root of the trace component
     48static FILE *traceFP = NULL;        // File destination for messages.
    4949
    5050static void componentFree(p_psComponent* comp);
     
    9191static void initTrace(void)
    9292{
    93     if (p_psCroot == NULL) {
    94         p_psCroot = componentAlloc(".", PS_DEFAULT_TRACE_LEVEL);
     93    if (cRoot == NULL) {
     94        cRoot = componentAlloc(".", PS_DEFAULT_TRACE_LEVEL);
    9595    }
    9696}
     
    124124void psTraceReset()
    125125{
    126     p_psTraceReset(p_psCroot);
     126    componentFree(cRoot);
     127    cRoot = NULL;
    127128}
    128129
     
    132133void psTraceFree()
    133134{
    134     psFree(p_psCroot);
     135    psTraceReset();
    135136}
    136137
     
    147148    char *pname = name;
    148149    char *firstComponent = NULL;        // first component of name
    149     p_psComponent* currentNode = p_psCroot;
     150    p_psComponent* currentNode = cRoot;
    150151    int nodeExists = 0;
     152
     153    // XXX: Verify that this is the correct behavior.
     154    if (strcmp("", addNodeName) == 0) {
     155        psAbort(__func__, "Failed to add null component to trace tree.\n");
     156    }
    151157
    152158    // Is this the root node? If so, simply set level and return.
    153159    if (strcmp(".", addNodeName) == 0) {
    154         p_psCroot->level = level;
     160        cRoot->level = level;
    155161        return;
    156162    }
     
    185191            currentNode->n = (currentNode->n) + 1;
    186192
    187             currentNode->subcomp[(currentNode->n) - 1] = componentAlloc(firstComponent, level);
     193            if (pname == NULL) {
     194                currentNode->subcomp[(currentNode->n) - 1] = componentAlloc(firstComponent, level);
     195            } else {
     196                currentNode->subcomp[(currentNode->n) - 1] = componentAlloc(firstComponent, currentNode->level);
     197            }
     198            currentNode = currentNode->subcomp[(currentNode->n) - 1];
    188199        }
    189200    }
     
    205216{
    206217    // If the root component tree does not exist, then initialize it.
    207     if (p_psCroot == NULL) {
     218    if (cRoot == NULL) {
    208219        initTrace();
    209220    }
     
    234245    char *pname = name;
    235246    char *firstComponent = NULL;        // first component of name
    236     p_psComponent* currentNode = p_psCroot;
     247    p_psComponent* currentNode = cRoot;
    237248    int i = 0;
    238249
     
    242253
    243254    if (strcmp(".", aname) == 0) {
    244         return (p_psCroot->level);
     255        return (cRoot->level);
    245256    }
    246257
     
    284295int psTraceGetLevel(const char *name)
    285296{
    286     if (p_psCroot == NULL) {
     297    if (cRoot == NULL) {
    287298        return (PS_UNKNOWN_TRACE_LEVEL);
    288299    }
     
    335346void psTracePrintLevels(void)
    336347{
    337     if (p_psCroot == NULL) {
     348    if (cRoot == NULL) {
    338349        return;
    339350    }
    340351
    341     doPrintTraceLevels(p_psCroot, 0);
     352    doPrintTraceLevels(cRoot, 0);
    342353}
    343354
     
    377388        fmt = va_arg(ap, char *);
    378389
    379         if (p_psTraceFP != NULL) {
     390        if (traceFP != NULL) {
    380391            // We indent each message one space for each level of the message.
    381392            for (i = 0; i < level; i++) {
    382                 fprintf(p_psTraceFP, " ");
    383             }
    384             vfprintf(p_psTraceFP, fmt, ap);
     393                fprintf(traceFP, " ");
     394            }
     395            vfprintf(traceFP, fmt, ap);
    385396        } else {
    386397            // We indent each message one space for each level of the message.
     
    397408void psTraceSetDestination(FILE * fp)
    398409{
    399     p_psTraceFP = fp;
     410    traceFP = fp;
    400411}
    401412
  • trunk/psLib/src/sys/psTrace.h

    r1441 r1640  
    1010 *  @author George Gusciora, MHPCC
    1111 *
    12  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-08-09 23:40:55 $
     12 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-08-27 21:45:01 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  • trunk/psLib/src/sysUtils/psTrace.c

    r1441 r1640  
    1 
    21/** @file psTrace.c
    32 *  \brief basic run-time trace facilities
     
    109 *  @author George Gusciora, MHPCC
    1110 *
    12  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-08-09 23:40:55 $
     11 *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-08-27 21:45:01 $
    1413 *
    1514 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4443#include "psString.h"
    4544#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.
     45#include "psAbort.h"
     46
     47static p_psComponent* cRoot = NULL; // The root of the trace component
     48static FILE *traceFP = NULL;        // File destination for messages.
    4949
    5050static void componentFree(p_psComponent* comp);
     
    9191static void initTrace(void)
    9292{
    93     if (p_psCroot == NULL) {
    94         p_psCroot = componentAlloc(".", PS_DEFAULT_TRACE_LEVEL);
     93    if (cRoot == NULL) {
     94        cRoot = componentAlloc(".", PS_DEFAULT_TRACE_LEVEL);
    9595    }
    9696}
     
    124124void psTraceReset()
    125125{
    126     p_psTraceReset(p_psCroot);
     126    componentFree(cRoot);
     127    cRoot = NULL;
    127128}
    128129
     
    132133void psTraceFree()
    133134{
    134     psFree(p_psCroot);
     135    psTraceReset();
    135136}
    136137
     
    147148    char *pname = name;
    148149    char *firstComponent = NULL;        // first component of name
    149     p_psComponent* currentNode = p_psCroot;
     150    p_psComponent* currentNode = cRoot;
    150151    int nodeExists = 0;
     152
     153    // XXX: Verify that this is the correct behavior.
     154    if (strcmp("", addNodeName) == 0) {
     155        psAbort(__func__, "Failed to add null component to trace tree.\n");
     156    }
    151157
    152158    // Is this the root node? If so, simply set level and return.
    153159    if (strcmp(".", addNodeName) == 0) {
    154         p_psCroot->level = level;
     160        cRoot->level = level;
    155161        return;
    156162    }
     
    185191            currentNode->n = (currentNode->n) + 1;
    186192
    187             currentNode->subcomp[(currentNode->n) - 1] = componentAlloc(firstComponent, level);
     193            if (pname == NULL) {
     194                currentNode->subcomp[(currentNode->n) - 1] = componentAlloc(firstComponent, level);
     195            } else {
     196                currentNode->subcomp[(currentNode->n) - 1] = componentAlloc(firstComponent, currentNode->level);
     197            }
     198            currentNode = currentNode->subcomp[(currentNode->n) - 1];
    188199        }
    189200    }
     
    205216{
    206217    // If the root component tree does not exist, then initialize it.
    207     if (p_psCroot == NULL) {
     218    if (cRoot == NULL) {
    208219        initTrace();
    209220    }
     
    234245    char *pname = name;
    235246    char *firstComponent = NULL;        // first component of name
    236     p_psComponent* currentNode = p_psCroot;
     247    p_psComponent* currentNode = cRoot;
    237248    int i = 0;
    238249
     
    242253
    243254    if (strcmp(".", aname) == 0) {
    244         return (p_psCroot->level);
     255        return (cRoot->level);
    245256    }
    246257
     
    284295int psTraceGetLevel(const char *name)
    285296{
    286     if (p_psCroot == NULL) {
     297    if (cRoot == NULL) {
    287298        return (PS_UNKNOWN_TRACE_LEVEL);
    288299    }
     
    335346void psTracePrintLevels(void)
    336347{
    337     if (p_psCroot == NULL) {
     348    if (cRoot == NULL) {
    338349        return;
    339350    }
    340351
    341     doPrintTraceLevels(p_psCroot, 0);
     352    doPrintTraceLevels(cRoot, 0);
    342353}
    343354
     
    377388        fmt = va_arg(ap, char *);
    378389
    379         if (p_psTraceFP != NULL) {
     390        if (traceFP != NULL) {
    380391            // We indent each message one space for each level of the message.
    381392            for (i = 0; i < level; i++) {
    382                 fprintf(p_psTraceFP, " ");
    383             }
    384             vfprintf(p_psTraceFP, fmt, ap);
     393                fprintf(traceFP, " ");
     394            }
     395            vfprintf(traceFP, fmt, ap);
    385396        } else {
    386397            // We indent each message one space for each level of the message.
     
    397408void psTraceSetDestination(FILE * fp)
    398409{
    399     p_psTraceFP = fp;
     410    traceFP = fp;
    400411}
    401412
  • trunk/psLib/test/sysUtils/tst_psTrace03.c

    r1638 r1640  
    99int main()
    1010{
    11     (void)psTraceSetLevel(".A.B.C.D.E", 2);
    12     psTracePrintLevels();
    13     (void)psTraceSetLevel(".A.B", 5);
    14     psTracePrintLevels();
    15     psTraceReset();
    16 
    17 
    1811    printPositiveTestHeader(stdout,
    1912                            "psTrace functions",
  • trunk/psLib/test/sysUtils/tst_psTrace04.c

    r1638 r1640  
    2929    psTraceReset();
    3030
    31     if (psTraceGetLevel(".") ||
    32             psTraceGetLevel(".a") ||
    33             psTraceGetLevel(".b") ||
    34             psTraceGetLevel(".c") ||
    35             psTraceGetLevel(".a.a") ||
    36             psTraceGetLevel(".a.b") ||
    37             psTraceGetLevel(".b.a") ||
    38             psTraceGetLevel(".b.b") ||
    39             psTraceGetLevel(".c.a") ||
    40             psTraceGetLevel(".c.b") ||
    41             psTraceGetLevel(".c.c")) {
     31    if ((psTraceGetLevel(".")!=PS_DEFAULT_TRACE_LEVEL) ||
     32            (psTraceGetLevel(".a")!=PS_DEFAULT_TRACE_LEVEL) ||
     33            (psTraceGetLevel(".b")!=PS_DEFAULT_TRACE_LEVEL) ||
     34            (psTraceGetLevel(".c")!=PS_DEFAULT_TRACE_LEVEL) ||
     35            (psTraceGetLevel(".a.a")!=PS_DEFAULT_TRACE_LEVEL) ||
     36            (psTraceGetLevel(".a.b")!=PS_DEFAULT_TRACE_LEVEL) ||
     37            (psTraceGetLevel(".b.a")!=PS_DEFAULT_TRACE_LEVEL) ||
     38            (psTraceGetLevel(".b.b")!=PS_DEFAULT_TRACE_LEVEL) ||
     39            (psTraceGetLevel(".c.a")!=PS_DEFAULT_TRACE_LEVEL) ||
     40            (psTraceGetLevel(".c.b")!=PS_DEFAULT_TRACE_LEVEL) ||
     41            (psTraceGetLevel(".c.c")!=PS_DEFAULT_TRACE_LEVEL)) {
    4242        printFooter(stdout,
    4343                    "psTrace functions",
Note: See TracChangeset for help on using the changeset viewer.