Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tools/profiler/report-profile.ts
6435 views
1
import { loadProfilerData } from "./lua-profiler-data-loader.ts";
2
import { LuaStack } from "./types.ts";
3
4
const filename = Deno.args[0];
5
const frameSkip = Deno.args[1] === undefined ? 3 : Number(Deno.args[1]);
6
const stacks = loadProfilerData(filename, frameSkip);
7
8
const estimateSampleRate = (stacks: LuaStack[]) => {
9
return (stacks[stacks.length - 1].time - stacks[0].time) / (stacks.length - 1);
10
}
11
12
const totalTime = stacks[stacks.length - 1].time - stacks[0].time;
13
const sampleRate = estimateSampleRate(stacks);
14
15
const selfTimes = new Map<string, number>();
16
17
for (const stack of stacks) {
18
const topFrame = stack.frames[0];
19
const location = topFrame.location;
20
if (!selfTimes.has(location)) {
21
selfTimes.set(location, 0);
22
}
23
selfTimes.set(location, selfTimes.get(location)! + sampleRate);
24
}
25
26
const roundToDigits = (num: number, digits: number) => {
27
const factor = 10 ** digits;
28
return Math.round(num * factor) / factor;
29
}
30
31
console.log(
32
Array.from(selfTimes.entries())
33
.sort((a, b) => b[1] - a[1])
34
.map(([location, time]) => `${roundToDigits(100 * time / totalTime, 1)}% (${roundToDigits(time, 3)}): ${location}`).join("\n"));
35