Changeset 37919 in webkit for trunk/JavaScriptCore


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):
Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r37901 r37919  
     12008-10-27  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Maciej Stachowiak.
     4       
     5        Stop discarding CodeBlock samples that can't be charged to a specific
     6        opcode. Instead, charge the relevant CodeBlock, and provide a footnote
     7        explaining the situation.
     8       
     9        This will help us tell which CodeBlocks are hot, even if we can't
     10        identify specific lines of code within the CodeBlocks.
     11
     12        * VM/SamplingTool.cpp:
     13        (JSC::ScopeSampleRecord::sample):
     14        (JSC::compareScopeSampleRecords):
     15        (JSC::SamplingTool::dump):
     16
     17        * VM/SamplingTool.h:
     18        (JSC::ScopeSampleRecord::ScopeSampleRecord):
     19        (JSC::ScopeSampleRecord::~ScopeSampleRecord):
     20
    1212008-10-27  Geoffrey Garen  <[email protected]>
    222
  • 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
  • trunk/JavaScriptCore/VM/SamplingTool.h

    r37901 r37919  
    4646
    4747    struct ScopeSampleRecord {
    48         RefPtr<ScopeNode> m_scope;
    49         CodeBlock* m_codeBlock;
    50         int m_totalCount;
    51         int* m_vpcCounts;
    52         unsigned m_size;
    53        
    5448        ScopeSampleRecord(ScopeNode* scope)
    5549            : m_scope(scope)
    5650            , m_codeBlock(0)
    57             , m_totalCount(0)
    58             , m_vpcCounts(0)
     51            , m_sampleCount(0)
     52            , m_opcodeSampleCount(0)
     53            , m_samples(0)
    5954            , m_size(0)
    6055        {
     
    6358        ~ScopeSampleRecord()
    6459        {
    65             if (m_vpcCounts)
    66                 free(m_vpcCounts);
     60            if (m_samples)
     61                free(m_samples);
    6762        }
    6863       
    6964        void sample(CodeBlock*, Instruction*);
     65
     66        RefPtr<ScopeNode> m_scope;
     67        CodeBlock* m_codeBlock;
     68        int m_sampleCount;
     69        int m_opcodeSampleCount;
     70        int* m_samples;
     71        unsigned m_size;
    7072    };
    7173
Note: See TracChangeset for help on using the changeset viewer.