MCPcopy Index your code
hub / github.com/python/cpython / populateStats

Function populateStats

Lib/profiling/sampling/_flamegraph_assets/flamegraph.js:1014–1163  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

1012// ============================================================================
1013
1014function populateStats(data) {
1015 // Populate profile summary
1016 populateProfileSummary(data);
1017
1018 // Populate thread statistics if available
1019 populateThreadStats(data);
1020
1021 // Setup elided stacks toggle if this is a differential flamegraph
1022 setupElidedToggle(data);
1023
1024 // For hotspots: use normal (non-inverted) tree structure, but respect thread filtering.
1025 // In inverted view, the tree structure changes but the hottest functions remain the same.
1026 // However, if a thread filter is active, we need to show that thread's hotspots.
1027 let hotspotSource;
1028 if (!normalData) {
1029 hotspotSource = data;
1030 } else if (isInverted) {
1031 // In inverted mode, use normalData (with thread filter if active)
1032 if (currentThreadFilter !== 'all') {
1033 hotspotSource = filterDataByThread(normalData, parseInt(currentThreadFilter));
1034 } else {
1035 hotspotSource = normalData;
1036 }
1037 } else {
1038 // In normal mode, use the passed data (already has thread filter applied if any)
1039 hotspotSource = data;
1040 }
1041 const totalSamples = hotspotSource.value || 0;
1042
1043 const functionMap = new Map();
1044
1045 function collectFunctions(node) {
1046 if (!node) return;
1047
1048 let filename = resolveString(node.filename);
1049 let funcname = resolveString(node.funcname);
1050
1051 if (!filename || !funcname) {
1052 const nameStr = resolveString(node.name);
1053 if (nameStr?.includes('(')) {
1054 const match = nameStr.match(/^(.+?)\s*\((.+?):(\d+)\)$/);
1055 if (match) {
1056 funcname = funcname || match[1];
1057 filename = filename || match[2];
1058 }
1059 }
1060 }
1061
1062 filename = filename || 'unknown';
1063 funcname = funcname || 'unknown';
1064
1065 if (filename !== 'unknown' && funcname !== 'unknown' && node.value > 0) {
1066 let childrenValue = 0;
1067 if (node.children) {
1068 childrenValue = node.children.reduce((sum, child) => sum + child.value, 0);
1069 }
1070 const directSamples = Math.max(0, node.value - childrenValue);
1071

Callers 1

renderFlamegraphFunction · 0.85

Calls 14

populateProfileSummaryFunction · 0.85
populateThreadStatsFunction · 0.85
setupElidedToggleFunction · 0.85
filterDataByThreadFunction · 0.85
collectFunctionsFunction · 0.85
searchForHotspotFunction · 0.85
getElementByIdMethod · 0.80
sortMethod · 0.45
filterMethod · 0.45
fromMethod · 0.45
valuesMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…