Ignore:
Timestamp:
Oct 27, 2008, 7:40:13 PM (17 years ago)
Author:
[email protected]
Message:

2008-10-27 Geoffrey Garen <[email protected]>

Reviewed by Maciej Stachowiak.


Stop discarding CodeBlock samples that can't be charged to a specific
opcode. Instead, charge the relevant CodeBlock, and provide a footnote
explaining the situation.


This will help us tell which CodeBlocks are hot, even if we can't
identify specific lines of code within the CodeBlocks.

  • VM/SamplingTool.cpp: (JSC::ScopeSampleRecord::sample): (JSC::compareScopeSampleRecords): (JSC::SamplingTool::dump):
  • VM/SamplingTool.h: (JSC::ScopeSampleRecord::ScopeSampleRecord): (JSC::ScopeSampleRecord::~ScopeSampleRecord):
File:
1 edited

Legend:

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

    r37901 r37919  
    4242void ScopeSampleRecord::sample(CodeBlock* codeBlock, Instruction* vPC)
    4343{
    44     if (!m_vpcCounts) {
     44    if (!m_samples) {
    4545        m_size = codeBlock->instructions.size();
    46         m_vpcCounts = static_cast<int*>(calloc(m_size, sizeof(int)));
     46        m_samples = static_cast<int*>(calloc(m_size, sizeof(int)));
    4747        m_codeBlock = codeBlock;
    4848    }
    4949
    50     unsigned codeOffset = vPC - codeBlock->instructions.begin();
     50    ++m_sampleCount;
     51
     52    unsigned offest = vPC - codeBlock->instructions.begin();
    5153    // Since we don't read and write codeBlock and vPC atomically, this check
    5254    // can fail if we sample mid op_call / op_ret.
    53     if (codeOffset < m_size) {
    54         m_vpcCounts[codeOffset]++;
    55         m_totalCount++;
     55    if (offest < m_size) {
     56        m_samples[offest]++;
     57        m_opcodeSampleCount++;
    5658    }
    5759}
     
    173175    const ScopeSampleRecord* const rightValue = *static_cast<const ScopeSampleRecord* const *>(right);
    174176
    175     return (leftValue->m_totalCount < rightValue->m_totalCount) ? 1 : (leftValue->m_totalCount > rightValue->m_totalCount) ? -1 : 0;
     177    return (leftValue->m_sampleCount < rightValue->m_sampleCount) ? 1 : (leftValue->m_sampleCount > rightValue->m_sampleCount) ? -1 : 0;
    176178}
    177179
     
    226228    printf("\tcti %% of self:\tcti count / sample count\n");
    227229   
    228     // (3) Calculate 'codeBlockSampleCount', build and sort 'codeBlockSamples' array.
     230    // (3) Build and sort 'codeBlockSamples' array.
    229231
    230232    int scopeCount = m_scopeSampleMap->size();
    231     long long codeBlockSampleCount = 0;
    232233    Vector<ScopeSampleRecord*> codeBlockSamples(scopeCount);
    233234    ScopeSampleRecordMap::iterator iter = m_scopeSampleMap->begin();
    234     for (int i = 0; i < scopeCount; ++i, ++iter) {
     235    for (int i = 0; i < scopeCount; ++i, ++iter)
    235236        codeBlockSamples[i] = iter->second;
    236         codeBlockSampleCount += codeBlockSamples[i]->m_totalCount;
    237     }
    238237
    239238    qsort(codeBlockSamples.begin(), scopeCount, sizeof(ScopeSampleRecord*), compareScopeSampleRecords);
     
    241240    // (4) Print data from 'codeBlockSamples' array.
    242241
    243     printf("\nCodeBlock samples [*]\n\n");
     242    printf("\nCodeBlock samples\n\n");
    244243
    245244    for (int i = 0; i < scopeCount; ++i) {
     
    247246        CodeBlock* codeBlock = record->m_codeBlock;
    248247
    249         double blockPercent = (record->m_totalCount * 100.0) / codeBlockSampleCount;
     248        double blockPercent = (record->m_sampleCount * 100.0) / m_sampleCount;
    250249
    251250        if (blockPercent >= 1) {
    252251            Instruction* code = codeBlock->instructions.begin();
    253             printf("#%d: %s:%d: %d / %lld (%.3f%%)\n", i + 1, record->m_scope->sourceURL().UTF8String().c_str(), codeBlock->lineNumberForVPC(code), record->m_totalCount, codeBlockSampleCount, blockPercent);
     252            printf("#%d: %s:%d: %d / %lld (%.3f%%)\n", i + 1, record->m_scope->sourceURL().UTF8String().c_str(), codeBlock->lineNumberForVPC(code), record->m_sampleCount, m_sampleCount, blockPercent);
    254253            if (i < 10) {
    255254                HashMap<unsigned,unsigned> lineCounts;
    256255                codeBlock->dump(exec);
     256
     257                printf("    Opcode and line number samples [*]\n\n");
    257258                for (unsigned op = 0; op < record->m_size; ++op) {
    258                     int count = record->m_vpcCounts[op];
     259                    int count = record->m_samples[op];
    259260                    if (count) {
    260261                        printf("    [% 4d] has sample count: % 4d\n", op, count);
     
    264265                }
    265266                printf("\n");
     267
    266268                int linesCount = lineCounts.size();
    267269                Vector<LineCountInfo> lineCountInfo(linesCount);
     
    278280                }
    279281                printf("\n");
     282                printf("    [*] Samples inside host code are charged to the calling Opcode.\n");
     283                printf("        Samples on a call / return boundary are not charged to a specific opcode or line.\n\n");
     284                printf("            Samples on a call / return boundary: %d / %d (%.3f%%)\n\n", record->m_sampleCount - record->m_opcodeSampleCount, record->m_sampleCount, (static_cast<double>(record->m_sampleCount - record->m_opcodeSampleCount) * 100) / record->m_sampleCount);
    280285            }
    281286        }
    282287    }
    283 
    284     printf("\n[*] Samples inside host code are charged to the calling Opcode.\n");
    285     printf("    Samples that fall on a call / return boundary are discarded.\n\n");
    286     printf("\tSamples discarded:\t\t%lld / %lld (%.3f%%)\n\n", m_sampleCount - codeBlockSampleCount, m_sampleCount, (static_cast<double>(m_sampleCount - codeBlockSampleCount) * 100) / m_sampleCount);
    287288}
    288289
Note: See TracChangeset for help on using the changeset viewer.