Ignore:
Timestamp:
Dec 1, 2014, 7:09:11 AM (5 years ago)
Author:
ldelgass
Message:

Stats log fixes, also bump version

Location:
nanovis/branches/1.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nanovis/branches/1.1

  • nanovis/branches/1.1/nanovis.cpp

    r4612 r4802  
    9191#define FALSE   0
    9292
    93 typedef struct {
    94     pid_t pid;
    95     size_t nFrames;            /**< # of frames sent to client. */
    96     size_t nBytes;             /**< # of bytes for all frames. */
    97     size_t nCommands;          /**< # of commands executed */
    98     double cmdTime;            /**< Elasped time spend executing
    99                                 * commands. */
    100     struct timeval start;      /**< Start of elapsed time. */
    101 } Stats;
    102 
    103 static Stats stats;
    104 
    10593// STATIC MEMBER DATA
    10694
     
    10997FILE *NanoVis::recfile = NULL;
    11098
     99NanoVis::Stats NanoVis::stats;
    111100int NanoVis::statsFile = -1;
    112101
     
    114103bool NanoVis::debugFlag = false;
    115104bool NanoVis::axisOn = true;
    116 struct timeval NanoVis::startTime;
    117105
    118106int NanoVis::winWidth = NPIX;
     
    253241{
    254242    Tcl_DString ds;
    255     Tcl_Obj **objv;
    256     int objc;
    257     int i;
    258243    char fileName[33];
     244    char pidstr[200];
    259245    const char *path;
    260246    md5_state_t state;
     
    266252        return statsFile;
    267253    }
    268     if (Tcl_ListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK) {
    269         return -1;
    270     }
    271     Tcl_ListObjAppendElement(interp, objPtr, Tcl_NewStringObj("pid", 3));
    272     Tcl_ListObjAppendElement(interp, objPtr, Tcl_NewIntObj(getpid()));
     254    /* By itself the client's key/value pairs aren't unique.  Add in the
     255     * process id of this render server. */
     256    sprintf(pidstr, "%ld", (long)stats.pid);
     257
     258    /* Create an md5 hash of the key/value pairs and use it as the file name. */
    273259    string = Tcl_GetStringFromObj(objPtr, &length);
    274 
    275260    md5_init(&state);
    276     md5_append(&state, (const md5_byte_t *)string, length);
     261    md5_append(&state, (const md5_byte_t *)string, strlen(string));
     262    md5_append(&state, (const md5_byte_t *)pidstr, strlen(pidstr));
    277263    md5_finish(&state, digest);
    278     for (i = 0; i < 16; i++) {
     264    for (int i = 0; i < 16; i++) {
    279265        sprintf(fileName + i * 2, "%02x", digest[i]);
    280266    }
     
    315301    Tcl_DString ds;
    316302    int result;
    317     int f;
    318303
    319304    {
     
    323308        gettimeofday(&tv, NULL);
    324309        finish = CVT2SECS(tv);
    325         tv = stats.start;
     310        tv = NanoVis::stats.start;
    326311        start = CVT2SECS(tv);
    327312    }
     
    353338    /* pid */
    354339    Tcl_DStringAppendElement(&ds, "pid");
    355     sprintf(buf, "%d", getpid());
     340    sprintf(buf, "%d", NanoVis::stats.pid);
    356341    Tcl_DStringAppendElement(&ds, buf);
    357342    /* host */
     
    362347    /* date */
    363348    Tcl_DStringAppendElement(&ds, "date");
    364     strcpy(buf, ctime(&stats.start.tv_sec));
     349    strcpy(buf, ctime(&NanoVis::stats.start.tv_sec));
    365350    buf[strlen(buf) - 1] = '\0';
    366351    Tcl_DStringAppendElement(&ds, buf);
    367352    /* date_secs */
    368353    Tcl_DStringAppendElement(&ds, "date_secs");
    369     sprintf(buf, "%ld", stats.start.tv_sec);
     354    sprintf(buf, "%ld", NanoVis::stats.start.tv_sec);
    370355    Tcl_DStringAppendElement(&ds, buf);
    371356    /* num_frames */
    372357    Tcl_DStringAppendElement(&ds, "num_frames");
    373     sprintf(buf, "%lu", (unsigned long int)stats.nFrames);
     358    sprintf(buf, "%lu", (unsigned long int)NanoVis::stats.nFrames);
    374359    Tcl_DStringAppendElement(&ds, buf);
    375360    /* frame_bytes */
    376361    Tcl_DStringAppendElement(&ds, "frame_bytes");
    377     sprintf(buf, "%lu", (unsigned long int)stats.nBytes);
     362    sprintf(buf, "%lu", (unsigned long int)NanoVis::stats.nBytes);
    378363    Tcl_DStringAppendElement(&ds, buf);
    379364    /* num_commands */
    380365    Tcl_DStringAppendElement(&ds, "num_commands");
    381     sprintf(buf, "%lu", (unsigned long int)stats.nCommands);
     366    sprintf(buf, "%lu", (unsigned long int)NanoVis::stats.nCommands);
    382367    Tcl_DStringAppendElement(&ds, buf);
    383368    /* cmd_time */
    384369    Tcl_DStringAppendElement(&ds, "cmd_time");
    385     sprintf(buf, "%g", stats.cmdTime);
     370    sprintf(buf, "%g", NanoVis::stats.cmdTime);
    386371    Tcl_DStringAppendElement(&ds, buf);
    387372    /* session_time */
     
    418403    }
    419404    Tcl_DStringAppend(&ds, "\n", -1);
    420     f = NanoVis::getStatsFile(NULL);
     405    int f = NanoVis::getStatsFile(NULL);
    421406    result = NanoVis::writeToStatsFile(f, Tcl_DStringValue(&ds),
    422407                                       Tcl_DStringLength(&ds));
     
    495480    std::string cmd(str);
    496481    cmd.erase(cmd.find_last_not_of(" \n\r\t")+1);
    497     TRACE("command %lu: '%s'", stats.nCommands+1, cmd.c_str());
     482    TRACE("command %lu: '%s'", NanoVis::stats.nCommands+1, cmd.c_str());
    498483#endif
    499484
     
    511496    finish = CVT2SECS(tv);
    512497
    513     stats.cmdTime += finish - start;
    514     stats.nCommands++;
     498    NanoVis::stats.cmdTime += finish - start;
     499    NanoVis::stats.nCommands++;
    515500    TRACE("Leave status=%d", result);
    516501    return result;
     
    19811966
    19821967    openlog("nanovis", LOG_CONS | LOG_PERROR | LOG_PID, LOG_USER);
    1983     gettimeofday(&NanoVis::startTime, NULL);
    1984     stats.start = NanoVis::startTime;
     1968    memset(&NanoVis::stats, 0, sizeof(NanoVis::Stats));
     1969    NanoVis::stats.pid = getpid();
     1970    gettimeofday(&NanoVis::stats.start, NULL);
    19851971
    19861972    /* Initialize GLUT here so it can parse and remove GLUT-specific
Note: See TracChangeset for help on using the changeset viewer.