Changeset 37919 in webkit for trunk/JavaScriptCore/VM/SamplingTool.cpp
- Timestamp:
- Oct 27, 2008, 7:40:13 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/VM/SamplingTool.cpp
r37901 r37919 42 42 void ScopeSampleRecord::sample(CodeBlock* codeBlock, Instruction* vPC) 43 43 { 44 if (!m_ vpcCounts) {44 if (!m_samples) { 45 45 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))); 47 47 m_codeBlock = codeBlock; 48 48 } 49 49 50 unsigned codeOffset = vPC - codeBlock->instructions.begin(); 50 ++m_sampleCount; 51 52 unsigned offest = vPC - codeBlock->instructions.begin(); 51 53 // Since we don't read and write codeBlock and vPC atomically, this check 52 54 // 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++; 56 58 } 57 59 } … … 173 175 const ScopeSampleRecord* const rightValue = *static_cast<const ScopeSampleRecord* const *>(right); 174 176 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; 176 178 } 177 179 … … 226 228 printf("\tcti %% of self:\tcti count / sample count\n"); 227 229 228 // (3) Calculate 'codeBlockSampleCount', build and sort 'codeBlockSamples' array.230 // (3) Build and sort 'codeBlockSamples' array. 229 231 230 232 int scopeCount = m_scopeSampleMap->size(); 231 long long codeBlockSampleCount = 0;232 233 Vector<ScopeSampleRecord*> codeBlockSamples(scopeCount); 233 234 ScopeSampleRecordMap::iterator iter = m_scopeSampleMap->begin(); 234 for (int i = 0; i < scopeCount; ++i, ++iter) {235 for (int i = 0; i < scopeCount; ++i, ++iter) 235 236 codeBlockSamples[i] = iter->second; 236 codeBlockSampleCount += codeBlockSamples[i]->m_totalCount;237 }238 237 239 238 qsort(codeBlockSamples.begin(), scopeCount, sizeof(ScopeSampleRecord*), compareScopeSampleRecords); … … 241 240 // (4) Print data from 'codeBlockSamples' array. 242 241 243 printf("\nCodeBlock samples [*]\n\n");242 printf("\nCodeBlock samples\n\n"); 244 243 245 244 for (int i = 0; i < scopeCount; ++i) { … … 247 246 CodeBlock* codeBlock = record->m_codeBlock; 248 247 249 double blockPercent = (record->m_ totalCount * 100.0) / codeBlockSampleCount;248 double blockPercent = (record->m_sampleCount * 100.0) / m_sampleCount; 250 249 251 250 if (blockPercent >= 1) { 252 251 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); 254 253 if (i < 10) { 255 254 HashMap<unsigned,unsigned> lineCounts; 256 255 codeBlock->dump(exec); 256 257 printf(" Opcode and line number samples [*]\n\n"); 257 258 for (unsigned op = 0; op < record->m_size; ++op) { 258 int count = record->m_ vpcCounts[op];259 int count = record->m_samples[op]; 259 260 if (count) { 260 261 printf(" [% 4d] has sample count: % 4d\n", op, count); … … 264 265 } 265 266 printf("\n"); 267 266 268 int linesCount = lineCounts.size(); 267 269 Vector<LineCountInfo> lineCountInfo(linesCount); … … 278 280 } 279 281 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); 280 285 } 281 286 } 282 287 } 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);287 288 } 288 289
Note:
See TracChangeset
for help on using the changeset viewer.