new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Deno · Fundamentals · all subjects

cpu profiling

14 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

--cpu-prof flag enables CPU profiling

The --cpu-prof flag enables CPU profiling to identify performance bottlenecks. When the program exits, Deno writes a .cpuprofile file to the current directory.

CPU profile file naming convention

CPU profile files are named with the pattern CPU.<timestamp>.<pid>.cpuprofile by default, for example CPU.1769017882255.25986.cpuprofile.

CPU profiling flags reference

CPU profiling flags: --cpu-prof (enables profiling, writes profile to disk on exit), --cpu-prof-dir=<DIR> (directory for profile output, defaults to current directory, implicitly enables --cpu-prof), --cpu-prof-name=<NAME> (filename for profile, defaults to CPU.<timestamp>.<pid>.cpuprofile), --cpu-prof-interval=<MICROSECONDS> (sampling interval in microseconds, default 1000 which is 1ms, lower values give more detail but larger files), --cpu-prof-md (generates human-readable Markdown report alongside .cpuprofile), --cpu-prof-flamegraph (generates interactive SVG flamegraph alongside .cpuprofile).

CPU profiling line number limitation with TypeScript

CPU profiles report line numbers from transpiled JavaScript code, not the original TypeScript source. This is a limitation of V8's profiler, so reported line numbers in TypeScript files may not match the source code directly.

deno run --cpu-prof basic usage

Use deno run --cpu-prof your_script.ts to capture a CPU profile during program execution. The .cpuprofile file can be loaded into Chrome DevTools (Performance tab) or other V8 profile viewers.

deno eval with CPU profiling

CPU profiling works with deno eval: deno eval --cpu-prof "for (let i = 0; i < 1e8; i++) {}"

Custom CPU profile directory and filename

Save profiles to a specific directory with deno run --cpu-prof --cpu-prof-dir=./profiles your_script.ts. Use a custom filename with deno run --cpu-prof --cpu-prof-name=my-profile.cpuprofile your_script.ts.

CPU profiling interval adjustment

The --cpu-prof-interval flag controls sampling frequency. Default is 1000 microseconds (1ms), which is a good balance for most use cases. For short-lived functions requiring more detail, try 100 (0.1ms). Lower intervals capture more samples per second at the cost of larger profile files.

Analyzing .cpuprofile in Chrome DevTools

To analyze a .cpuprofile file: open Chrome DevTools (F12), go to the Performance tab, click the Load profile button (up arrow icon), and select the .cpuprofile file. DevTools displays a flame chart and detailed breakdown of where time was spent.

Generate Markdown CPU profile report

The --cpu-prof-md flag generates a Markdown summary with the .cpuprofile file. The Markdown report includes summary statistics, top 10 functions, hot functions sorted by self time, call tree showing hierarchy and time distribution, and per-function breakdown with sample counts.

Generate interactive SVG flamegraph

The --cpu-prof-flamegraph flag generates a self-contained, interactive SVG flamegraph. Open the SVG in any browser to explore interactively. Features: click any frame to zoom into subtree, Reset Zoom button to restore full view, Ctrl+F or Search button for regex-based function search with highlighting and matched percentage, Invert checkbox to flip into icicle graph with root at top, hover any frame to see function name and sample count.

Combine CPU profiling output formats

Use --cpu-prof-md and --cpu-prof-flamegraph together to generate all three outputs (.cpuprofile, .md, and .svg) in a single run: deno run --cpu-prof --cpu-prof-md --cpu-prof-flamegraph your_script.ts

Self time vs total time in CPU profiles

In profile reports, self time is time spent in a function's own code, while total time includes time in functions it calls. High self time points to the actual bottleneck. High total time with low self time means the function delegates to something expensive.

CPU profiling best practices

Profile representative workloads by sending realistic traffic to servers before stopping them. Use descriptive filenames with --cpu-prof-name (e.g., before-optimization.cpuprofile) to compare profiles side-by-side in DevTools after changes. Ensure profiled code runs long enough to collect meaningful samples, as short-lived programs may show startup overhead (module loading, JIT compilation) dominating the profile.

Give your agent this brain