예제 #1
0
void printStats(AcRxDictionary* statDict) {
    AcRxDictionaryIterator* iter;
    
    acutPrintf("\n\nCommand                 Count     Elapsed Time\n");
    acutPrintf("----------------------  -------   ----------\n");
    for (iter = statDict->newIterator(AcRx::kDictSorted); !iter->done(); iter->next()) {
        // Write out the command string.
        acutPrintf("%s", iter->key());

    // Try for a little reasonable text alignment,
    // assuming 24 characters for a command or lisp name is sufficient.
    // But, we'll go to the MAX_CMD_LENGTH, plus one blank, if we must.
    int nbrOfSpaces = 24 - strlen(iter->key());
    do
        acutPrintf(" ");
    while (--nbrOfSpaces > 0);

        // Now the count, plus elapsed time, in primate-comprehensible form.
    int TempElapsedTime = (int)
                          (((AsdkCommandRecord*) iter->object())->elapsedTime);
    int hours = TempElapsedTime / 3600;
    int minutes = (TempElapsedTime % 3600) / 60;
    acutPrintf("%7i   %4d:%0*d:%0*.*f\n",
               ((AsdkCommandRecord*)iter->object())->count,
               hours,
               2, minutes,
               5, 2,
               ((AsdkCommandRecord*) iter->object())->elapsedTime
               - (hours * 3600) - (minutes * 60));
           
    }

    delete iter;
}
예제 #2
0
Adesk::Boolean updateCumulativeStats()
{
    // If anything is going on in any document, now is NOT a good
    // time to accumulate stats, because each command/LISP expression
    // in progress has pointers into session stats.
    // This could be fixed with more recoding than I have time to do
    // now.  WCA 7/15/98
    for (int i = docData.length() - 1; i >= 0; i--) {
        // Make sure our info is up to date.
        if (docData[i].doc == curDocGlobals.doc)
            docData[i] = curDocGlobals;
        if ((docData[i].cmdIndex > 0) ||
            (docData[i].lispRcd != NULL))
            return Adesk::kFalse;
    }

    if (!readCumulativeStats()) {
        acutPrintf("\nWarning: Could not find Command Statistics file.\n");
        acutPrintf("Will try to create it.\n");
    }

    AcRxDictionaryIterator* iter;

    // Loop over current session stats, and merge them into cumulative stats.
    for (iter = sessionStats->newIterator(); !iter->done(); iter->next()) {
        AsdkCommandRecord* sessionCmdRcd = (AsdkCommandRecord*) iter->object();
        AsdkCommandRecord* cumulativeCmdRcd = (AsdkCommandRecord*)
                                          cumulativeStats->at(iter->key());
        if (!cumulativeCmdRcd)
            // First time, add it.
            cumulativeStats->atPut(iter->key(),
                                   new AsdkCommandRecord(sessionCmdRcd->count,
                                                     sessionCmdRcd->elapsedTime));
        else {
            // Not the first time, so bump it.
            cumulativeCmdRcd->count += sessionCmdRcd->count;
            cumulativeCmdRcd->elapsedTime += sessionCmdRcd->elapsedTime;
        }
    }

    delete iter;

    // Now that it has been added in, wipe out the current session Stats;
    delete sessionStats;
    sessionStats = initStatDictionary();

    // Open the cumulative stat file, creating it if necessary.
    char statFilePath[MAX_PATH_LENGTH];
    
    int ret = cmdcount_findfile(statFileName, statFilePath,true);
    assert(ret==RTNORM);//this should always succeed

    // Open the file
    FILE* statFile = fopen(statFilePath, /*NOXLATE*/"w");

    if (statFile == NULL) {
        // Bad permission in our chosen directory.  Give up.
        acedAlert("Warning: Could not create Command Statistics file.");
        return Adesk::kTrue;
    }

    // Print version number of STATFILE
    fprintf(statFile, "v%04.1f\n", STAT_FILENAME_VERSION);

    // Print create date of STATFILE
    if (!*createDate) {
        fprintf(statFile, "Created:               ");
        printCurrentDateTime(statFile);
        fprintf(statFile, "\n");
    } else
        fprintf(statFile, "%s\n", createDate);

    // Print date last modified for STATFILE
    fprintf(statFile, "Last Modified:         ");
    printCurrentDateTime(statFile);
    fprintf(statFile, "\n");
    
    resbuf tempRes;
    // Print LOGINNAME
    if (acedGetVar(/*NOXLATE*/"LOGINNAME", &tempRes) != RTNORM) {
        sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1",
                PRODUCTL, getProductName());
        acrx_abort(abort_msg);
    }
    fprintf(statFile, /*NOXLATE*/"LOGINNAME:             %s\n", tempRes.resval.rstring);
    acdbFree (tempRes.resval.rstring) ;
    // Print ACAD serial number
    if (acedGetVar(/*NOXLATE*/"_PKSER", &tempRes) != RTNORM) {
        sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1",
                PRODUCTL, getProductName());
        acrx_abort(abort_msg);
    }
    fprintf(statFile, /*NOXLATE*/"%.*s Serial Number: %s\n", PRODUCTL, getProductName(),
                            tempRes.resval.rstring);
    acdbFree (tempRes.resval.rstring) ;

    // Print ACAD version
    if (acedGetVar(/*NOXLATE*/"_VERNUM", &tempRes) != RTNORM) {
        sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1",
                PRODUCTL, getProductName());
        acrx_abort(abort_msg);
    }
    fprintf(statFile, /*NOXLATE*/"%.*s version:       %s\n", PRODUCTL, getProductName(),
                        tempRes.resval.rstring);
    acdbFree (tempRes.resval.rstring) ;


    for (iter = cumulativeStats->newIterator(AcRx::kDictSorted); !iter->done(); iter->next()) {
        // Write out the command string.
        fprintf(statFile, "%s", iter->key());

        // Try for reasonable text alignment, such as allowing 24 chars
        // for the command name.  But have at least 1 space as a delimiter.
        int nbrOfSpaces = 24 - strlen(iter->key());
        do
            fprintf(statFile, " ");
        while (--nbrOfSpaces > 0);

        // Now the count and elapsed time in seconds (assume 1 billion seconds
        // maximum, which should exceed a typical beta survey period).
        fprintf(statFile, "%7i   %12.2f\n",
                ((AsdkCommandRecord*) iter->object())->count,
                ((AsdkCommandRecord*) iter->object())->elapsedTime);
    }

    fclose(statFile);

    delete iter;
    return Adesk::kTrue;
}