Ignore:
Timestamp:
Sep 14, 2008, 1:33:03 AM (17 years ago)
Author:
[email protected]
Message:

2008-09-14 Sam Weinig <[email protected]>

Reviewed by Cameron Zwarich.

Cleanup Sampling code.

  • VM/CTI.cpp: (JSC::CTI::emitCall): (JSC::CTI::privateCompileMainPass):
  • VM/CTI.h: (JSC::CTI::execute):
  • VM/SamplingTool.cpp: (JSC::): (JSC::SamplingTool::run): (JSC::SamplingTool::dump):
  • VM/SamplingTool.h: (JSC::SamplingTool::callingHostFunction):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/VM/SamplingTool.cpp

    r36263 r36402  
    8181
    8282#if ENABLE(SAMPLING_TOOL)
    83 extern OpcodeID what;
    84 extern unsigned incall;
    85 unsigned cowdogs = 0;
    86 unsigned sampleCows[numOpcodeIDs] = {0};
    87 unsigned sampleDogs[numOpcodeIDs] = {0};
     83unsigned totalOpcodeIDCount = 0;
     84unsigned opcodeIDCountInCalledCode[numOpcodeIDs] = {0};
     85unsigned opcodeIDCountInJITCode[numOpcodeIDs] = {0};
    8886#endif
    8987
     
    9593        m_totalSamples++;
    9694#if ENABLE(SAMPLING_TOOL)
    97         if (what != (OpcodeID)-1) {
    98             ++cowdogs;
    99             if (incall)
    100                 sampleDogs[what]++;
     95        if (currentOpcodeID != static_cast<OpcodeID>(-1)) {
     96            ++totalOpcodeIDCount;
     97            if (inCalledCode)
     98                opcodeIDCountInCalledCode[currentOpcodeID]++;
    10199            else
    102                 sampleCows[what]++;
     100                opcodeIDCountInJITCode[currentOpcodeID]++;
    103101        }
    104102#endif       
     
    142140#if ENABLE(SAMPLING_TOOL)
    143141
    144 struct OpcodeSampleInfo
    145 {
     142struct OpcodeSampleInfo {
    146143    OpcodeID opcode;
    147144    long long count;
    148     long long countincall;
     145    long long countInCalledCode;
    149146};
    150147
    151 struct LineCountInfo
    152 {
     148struct LineCountInfo {
    153149    unsigned line;
    154150    unsigned count;
     
    195191        totalCodeBlockSamples += codeBlockSamples[i]->m_totalCount;
    196192    }
    197 #if HAVE(MERGESORT)
    198     mergesort(codeBlockSamples.begin(), scopeCount, sizeof(ScopeSampleRecord*), compareScopeSampleRecords);
    199 #else
     193
    200194    qsort(codeBlockSamples.begin(), scopeCount, sizeof(ScopeSampleRecord*), compareScopeSampleRecords);
    201 #endif
    202195
    203196    // (2) Print data from 'codeBlockSamples' array, calculate 'totalOpcodeSamples', populate 'opcodeSampleCounts' array.
     
    209202    printf("Total blocks sampled (total samples): %lld (%lld)\n\n", totalCodeBlockSamples, m_totalSamples);
    210203
    211     for (int i=0; i < scopeCount; i++) {
     204    for (int i = 0; i < scopeCount; ++i) {
    212205        ScopeSampleRecord* record = codeBlockSamples[i];
    213206        CodeBlock* codeBlock = record->m_codeBlock;
     
    238231                    lineCountInfo[lineno].count = iter->second;
    239232                }
    240 #if HAVE(MERGESORT)
    241                 mergesort(lineCountInfo.begin(), linesCount, sizeof(LineCountInfo), compareLineCountInfoSampling);
    242 #else
     233
    243234                qsort(lineCountInfo.begin(), linesCount, sizeof(LineCountInfo), compareLineCountInfoSampling);
    244 #endif
     235
    245236                for (lineno = 0; lineno < linesCount; ++lineno) {
    246237                    printf("    Line #%d has sample count %d.\n", lineCountInfo[lineno].line, lineCountInfo[lineno].count);
     
    267258    OpcodeSampleInfo opcodeSampleInfo[numOpcodeIDs];
    268259    for (int i = 0; i < numOpcodeIDs; ++i) {
    269         opcodeSampleInfo[i].opcode = (OpcodeID)i;
    270         opcodeSampleInfo[i].count = sampleCows[i]+sampleDogs[i];
    271         opcodeSampleInfo[i].countincall = sampleDogs[i];
    272     }
    273 #if HAVE(MERGESORT)
    274     mergesort(opcodeSampleInfo, numOpcodeIDs, sizeof(OpcodeSampleInfo), compareOpcodeIndicesSampling);
    275 #else
     260        opcodeSampleInfo[i].opcode = static_cast<OpcodeID>(i);
     261        opcodeSampleInfo[i].count = opcodeIDCountInJITCode[i] + opcodeIDCountInCalledCode[i];
     262        opcodeSampleInfo[i].countInCalledCode = opcodeIDCountInCalledCode[i];
     263    }
     264
    276265    qsort(opcodeSampleInfo, numOpcodeIDs, sizeof(OpcodeSampleInfo), compareOpcodeIndicesSampling);
    277 #endif
    278266
    279267    // (4) Print Opcode sampling results.
    280268
    281 
    282269    printf("\nOpcode sampling results\n\n");
    283    
    284 //    printf("Total opcodes sampled (total samples): %lld (%lld)\n\n", totalOpcodeSamples, m_totalSamples);
    285 //    printf("Opcodes in order:\n\n");
    286 //    for (int i = 0; i < numOpcodeIDs; ++i) {
    287 //        long long count = opcodeSampleCounts[i];
    288 //        printf("%s:%s%6lld\t%.3f%%\t(%.3f%%)\n", opcodeNames[i], padOpcodeName(static_cast<OpcodeID>(i), 20), count, (static_cast<double>(count) * 100) / totalOpcodeSamples, (static_cast<double>(count) * 100) / m_totalSamples);   
    289 //    }
    290 //    printf("\n");
    291 //    printf("Opcodes by sample count:\n\n");
    292270
    293271    for (int i = 0; i < numOpcodeIDs; ++i) {
    294272        OpcodeID opcode = opcodeSampleInfo[i].opcode;
    295273        long long count = opcodeSampleInfo[i].count;
    296 //        printf("%s:%s%6lld\t%.3f%%\t(%.3f%%)\n", opcodeNames[opcode], padOpcodeName(opcode, 20), count, (static_cast<double>(count) * 100) / totalOpcodeSamples, (static_cast<double>(count) * 100) / m_totalSamples);   
    297         long long countincall = opcodeSampleInfo[i].countincall;
    298         fprintf(stdout, "%s:%s%6lld\t%6lld\t%.3f%%\t%.3f%%\t(%.3f%%)\n", opcodeNames[opcode], padOpcodeName(opcode, 20), count, countincall, ((double)count * 100)/cowdogs, ((double)count * 100)/m_totalSamples, ((double)countincall * 100)/m_totalSamples);   
     274        long long countInCalledCode = opcodeSampleInfo[i].countInCalledCode;
     275        fprintf(stdout, "%s:%s%6lld\t%6lld\t%.3f%%\t%.3f%%\t(%.3f%%)\n", opcodeNames[opcode], padOpcodeName(opcode, 20), count, countInCalledCode, (static_cast<double>(count) * 100) / totalOpcodeIDCount, (static_cast<double>(count) * 100) / m_totalSamples, (static_cast<double>(countInCalledCode) * 100) / m_totalSamples);   
    299276    }
    300277    printf("\n");
Note: See TracChangeset for help on using the changeset viewer.