Master the fundamental concepts of profiling & measurement through this focused micro-challenge.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksFlame graphs turn thousands of perf record stack samples into one SVG where width equals sample count. Brendan Gregg invented them to answer which functions dominate CPU time across whole call chains, not just flat self time. Kernel developers, database teams, and game studios use the same workflow when a service is hot but the culprit function is buried five frames deep.
Record at high frequency, collapse stacks, feed them to flamegraph.pl. The y-axis is stack depth; the x-axis is proportion of samples. Wide plateaus are where you optimize first.
bashLoading…
-g so call chains appear, not just leaf symbolsKeep the relevant documentation open while you implement. When your output disagrees with the reference, trace one failing case by hand before changing random lines.
You will write a program with deliberate hotspots and generate a flame graph from perf record output. This exercise requires you to identify the widest frame and tie it back to a specific loop in your source.
A flame graph is built from "folded" stack samples, the format that stackcollapse-perf.pl produces from perf record -g. Each line is a call stack from the root to the leaf, plus the number of samples in which that exact stack was on-CPU. Merge the stacks into a tree, draw it (a text "icicle" version of the flame graph), rank functions by self time (samples where the function was the leaf), and zoom into one function with focus.
cLoading…
Stack lines may appear anywhere, and commands see all the stacks read so far.
[BAR] NAME COUNT PCT. BAR has WIDTH characters, with round(count * WIDTH / base) of them # (half up) and the rest spaces. The base is the total sample count.bad line: TEXT, focus FUNC: not found, and graph: width 1..80.cLoading…
Top lines use " %-12s self ...".
Input:
cLoading…
Output:
cLoading…
Hidden tests cover deep recursion (a function appearing several times in one stack), several roots (stacks that do not all start at main), a narrow bar width, top with ties, a focus function that appears under several parents, and malformed lines.