MCPcopy Index your code
hub / github.com/nodejs/node / generateSourceView

Method generateSourceView

deps/v8/tools/profview/profview.js:1590–1621  ·  view source on GitHub ↗
(functionId)

Source from the content-addressed store, hash-verified

1588 }
1589
1590 generateSourceView(functionId) {
1591 console.assert(this.hasSource(functionId));
1592 let data = this.functions.get(functionId);
1593 let scriptId = data.scriptId;
1594 let script = this.getScript(scriptId);
1595 let firstLineNumber =
1596 this.getLineForScriptOffset(script, data.startScriptOffset);
1597 let lastLineNumber =
1598 this.getLineForScriptOffset(script, data.endScriptOffset);
1599 let lines = script.slice(firstLineNumber, lastLineNumber + 1);
1600 normalizeLeadingWhitespace(lines);
1601
1602 let samplesTotal = 0;
1603 let lineSampleCounts = [];
1604 for (let [codeId, block] of data.codes) {
1605 block.offsets.forEach((sampleCount, codeOffset) => {
1606 let sourceOffset = block.positionTable.getScriptOffset(codeOffset);
1607 let lineNumber =
1608 this.getLineForScriptOffset(script, sourceOffset) - firstLineNumber;
1609 samplesTotal += sampleCount;
1610 lineSampleCounts[lineNumber] =
1611 (lineSampleCounts[lineNumber] || 0) + sampleCount;
1612 });
1613 }
1614
1615 return {
1616 source: lines,
1617 lineSampleCounts: lineSampleCounts,
1618 samplesTotal: samplesTotal,
1619 firstLineNumber: firstLineNumber + 1 // Source code is 1-indexed.
1620 };
1621 }
1622}
1623
1624class FunctionSourceData {

Callers 1

renderMethod · 0.80

Calls 9

hasSourceMethod · 0.95
getScriptMethod · 0.95
assertMethod · 0.80
getMethod · 0.65
sliceMethod · 0.65
forEachMethod · 0.65
getScriptOffsetMethod · 0.45

Tested by

no test coverage detected