Quick Answer: Critical path analysis finds the longest chain of dependent work in a program. That chain sets the minimum runtime no matter how many CPUs you add. To speed up a build, you have to shorten the critical path. In one libuv example, the path was 47.4 seconds even on 64 cores, and two-thirds of it was threads asleep, not computing.
If your build still takes 47 seconds on 64 cores, adding hardware won't fix it. Most engineers reach for a CPU profiler next, and that's the wrong tool. The work you're waiting on is often not computing at all. Brendan Gregg spent years pushing the field to look at where threads block, not only where they burn cycles. Felix Zakaria applied that thinking to a deterministic VM called Rewind, and his Hacker News post walks through critical path analysis on a libuv build and test run. Here's the method, and where it breaks down.
The critical path sets a floor you can't buy your way under
The critical path is the longest chain of steps where each one had to wait for the one before it. Take three tasks where B, C, and D can run concurrently, but C depends on A and E depends on C. Extra CPUs can run B and D alongside everything else, but A → C → E still takes the same time. That chain is the floor.
The libuv run makes this concrete. On the VM's single CPU, the build and test took 78.0 seconds. The critical path came to 47.4 seconds. No number of CPUs gets you below 47.4, so the gap between those two numbers is the most parallelism can ever buy you.
Here's the practical move: before you buy machines or add runners, measure both numbers. If elapsed time on one CPU and the critical path are already close, parallelism is exhausted, and the only lever left is shortening the chain itself.
Why a CPU profile misses the real bottleneck
This is the counter-intuitive part. The hottest function in a CPU profile is often irrelevant to how long your build takes. A CPU profiler samples threads that are running on a core. A thread waiting on a timer, a socket, or a futex never shows up in those samples.
In the libuv run, the critical path was 67% asleep: 23.1 seconds in epoll_pwait, 8.53 seconds in clock_nanosleep, and 100 ms in futex. Only 33% of the path was computing. A CPU profile would have shown you the third that mattered least.
Gregg's answer is off-CPU analysis, which looks at where threads block and why. His thread state analysis sorts time into states such as running, runnable, and sleeping. Here's the catch: on a live Linux machine, off-CPU analysis is expensive. You generally have to trace before the slow run happens, and most captured sleeps turn out to be noise. You can trace a few runs, and you have to guess which ones matter.
Reading a critical path report, step by step
Once you have a recording, the report works top-down. Use this order, because each step narrows the search:
- Check the two headline numbers. Elapsed time on one CPU versus critical path tells you how much parallelism can help.
- Read the phase breakdown. In the libuv run,
configurePhasetook 3.54 s,buildPhase1.67 s, andcheckPhase42.0 s. The test phase was the problem, not the compile. - Walk the process tree.
make checkaccounted for 41.9 seconds of the path, and 36.4 of those seconds belonged tolt-run-tests, libuv's test runner. - Read the "if this took no time" table. This is your prioritization list, covered below.
- Drill into one process with
--in,--foldedforflamegraph.plor speedscope, or--perfettofor a timeline.
Step three is where the real insight lives. The runner invoked 287 tests, each taking one to three seconds. All of them sat on the path, which means the runner executed them one after another. Most of each test was asleep, waiting on timers. The fix belongs in the test scheduling, not in compiler flags.
Path versus drag: which fix actually pays off
Two numbers answer different questions, and mixing them up leads to wasted effort. Path tells you where time sits on the chain. Drag tells you how much would be saved if a piece of work took no time at all.
| Lens | Question it answers | Blind spot | Best use |
|---|---|---|---|
| CPU profile | Where do cycles go? | Ignores sleeping and blocked threads | Compute-bound hotspots |
| Off-CPU analysis | Where do threads block, and on what? | Doesn't show whether a block is on the critical path | Timer waits, lock contention, I/O |
| Critical path | Which chain sets the minimum runtime? | Shows the chain, not the cause inside each step | Deciding what to parallelize or shorten |
| Drag | How much would removing this save? | Assumes the rest of the chain stays unchanged | Ranking candidate fixes |
In the libuv report, drag said that if every lt-run-tests process took no time, the run would finish 36.1 seconds sooner. Compilation of cc1 was worth only 6.66 seconds of drag. Drag is usually the number you want for prioritizing, since it accounts for what's left on the chain once you remove a step.
Drilling into one step without guessing
Here's the part most guides skip: a large item on the path isn't always a bug. The hrtime test sat on the path for 3.38 seconds, about 7% of the total. It was 100% asleep in clock_nanosleep, across 75 separate sleeps.
Rewind's rewind where replays the run to the step where the sleep began and asks gdb where the thread was. The stack showed uv_sleep(45) called from line 39 of test/test-hrtime.c. The test sleeps 45 ms at a time on purpose, because it checks how far uv_hrtime advances across a sleep. Nothing needed fixing.
This is the workflow to copy: the path tells you where to look, the stack tells you why, and only then do you decide whether the sleep is a bug. Because the run is deterministic, step 115,894 is the same instruction on every replay, so you can reopen the exact moment as often as you need. That repeatability is what makes the investigation trustworthy, but it depends on having recorded the run in the first place.
Caveats before you trust the path
A critical path is only as accurate as the dependencies it captures. Wakeup tracking shows which thread woke which, but it won't capture every shared resource, such as a file both steps touch without a wakeup. Treat the path as a strong hypothesis, not a proof.
Also, one run is one sample. Test suites vary between runs, so compare two or three recordings before you reorganize a pipeline around one chain. And short-lived processes matter: a ps snapshot can miss them, which is why a complete recording is more reliable than polling for processes.
Finally, don't abandon the classics. Brendan Gregg's flame graphs remain the right tool for compute-bound code. Critical path analysis answers a different question: which chain sets your floor?
Frequently Asked Questions
What is the critical path in a build?
The critical path in a build is the longest sequence of steps where each one had to wait for the previous one to finish. It sets the minimum possible build time, no matter how many CPUs or cores you add. Steps off the path can run in parallel without changing the finish time. Shortening the path is the only way to make the build finish sooner.
Why does a CPU profile miss slow builds?
A CPU profile only samples threads that are running on a core. Build steps that sleep on timers, sockets, or futexes don't appear in those samples, even when they dominate elapsed time. In the libuv example, about two-thirds of the critical path was sleeping. Off-CPU analysis, which tracks where threads block, is the better tool for that kind of delay.
How do I find the critical path of a build?
Record the build with a tool that logs every fork, context switch, and wakeup, then compute the longest dependency chain from that data. Compare elapsed time on one CPU with the path length to see how much parallelism can help. Then read the path process by process and check which steps have the largest drag.
Should I use off-CPU analysis or a flame graph?
Use a flame graph when the build is compute-bound and your CPUs stay busy. Use off-CPU analysis when wall-clock time is much higher than CPU time, which often happens with test runners, network calls, or timer-heavy suites. Many slow builds need both: the flame graph explains the cost of each step, and the off-CPU view explains the idle time between steps.
Next time your build stalls, don't reach for more cores first. Measure the critical path, compare it with the single-CPU time, and check the drag before you change anything. Share this with a teammate who keeps adding runners to a pipeline that is still waiting on one slow test.