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

Function collectFunctions

Lib/profiling/sampling/_flamegraph_assets/flamegraph.js:1045–1098  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

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
1072 const funcKey = `${filename}:${node.lineno || '?'}:${funcname}`;
1073
1074 if (functionMap.has(funcKey)) {
1075 const existing = functionMap.get(funcKey);
1076 existing.directSamples += directSamples;
1077 existing.directPercent = (existing.directSamples / totalSamples) * 100;
1078 if (directSamples > existing.maxSingleSamples) {
1079 existing.filename = filename;
1080 existing.lineno = node.lineno || '?';
1081 existing.maxSingleSamples = directSamples;
1082 }
1083 } else {
1084 functionMap.set(funcKey, {
1085 filename: filename,
1086 lineno: node.lineno || '?',
1087 funcname: funcname,
1088 directSamples,
1089 directPercent: (directSamples / totalSamples) * 100,
1090 maxSingleSamples: directSamples
1091 });
1092 }
1093 }
1094
1095 if (node.children) {
1096 node.children.forEach(child => collectFunctions(child));
1097 }
1098 }
1099
1100 collectFunctions(hotspotSource);
1101

Callers 1

populateStatsFunction · 0.85

Calls 7

resolveStringFunction · 0.85
reduceMethod · 0.80
matchMethod · 0.45
maxMethod · 0.45
hasMethod · 0.45
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…