Okay, I am the archetypal to acknowledge that I’m a bit manic alongside AI. When you are operating on a issue that has endless possibilities, it is difficult to constrain yourself to a constricted set of features.
Can I fair add one more?
I have been amazed at all the fun and helpful things that a deterministic VM akin Rewind enables. I have been using it to assistance find heisenbugs, to create profile-guided optimization reproducible, and to create Nix builds bit-reproducible. But the most fun has been using it to comprehend performance.
Turns out that achievement is yet another area anywhere Rewind shines. I have been using it to analyze the crucial way of builds.
What is the crucial path?
The crucial way is the longest sequence of reliant activity in a program. It is the minimum period that the program can obtain to complete, despite of how many resources you throw at it. The lone way to create a program faster is to shorten the crucial path.
If you adore at the altar of Brendan Gregg, you cognize he spent years turning achievement inspection from a dreary art into a science. This is a small offering to him. 🤲
I added a new rewind period command to Rewind that analyzes a record and tells you anywhere the period went and what would create the run complete sooner. You can drill into any part of that answer and see the origin lines liable for it. It’s akin Brendan Gregg’s fire graphs but on steroids for the crucial way and alongside a debugger attached.11All the ideas for the command are either inspired by or immediately influenced by Brendan Gregg’s work. Kneel before Zod!
Aside: New to Rewind? Start alongside a flaky build you lone capture once and dafuq is a deterministic VM?
Let’s see how it plant by analyzing the crucial way of a libuv build and test run. The build and test suite takes 78 seconds inner Rewind, and equal alongside 64 cores it motionless takes 47 seconds. Why?
The customary answer is to appearance at a CPU profile, and in this case a CPU overview would be nearly useless. For two thirds of those 47 seconds, the activity the build is waiting on is not computing at all: it is asleep. 💤💤💤
§Where the period goes
Every rewind period starts alongside two numbers:
$ rewind time 7a29e716 libuv-1.51.0 78.0 s elapsed on the VM's one CPU 47.4 s crucial path: the smallest it can obtain on any figure of CPUs 67% idle (epoll_pwait 23.1 s, clock_nanosleep 8.53 s, futex 100 ms), 33% computing
The archetypal is how lengthy the run took on the VM’s one virtual CPU. The second is the critical path: the longest sequence of activity anywhere all stage had to delay for the one before.
No figure of CPUs makes a run shorter than its crucial path, so the gap between the two numbers is all that parallelism can buy you.
The row under the two numbers applies Gregg’s thread province analysis. Here the biggest province is asleep: 23 seconds in epoll_pwait and 8.5 in clock_nanosleep.
A sleeping thread is invisible to a CPU profiler. Gregg’s answer is off-CPU analysis: appearance at anywhere threads block, not lone anywhere they compute.
On a live machine, off-CPU inspection is hard. Linux can trace which thread woke which, and Gregg built wakeup and off-wake profiling on top of that, but you have to be tracing before the dilatory run happens, the tracing has a cost, and most of the sleeps you grasp are noise. Rewind already logs all environment toggle since it needs them to replay, and now it records all wakeup and who caused it too. All that juicy data is in all recording. 🤤
Here is the entire output for libuv:
$ rewind time 7a29e716 libuv-1.51.0 78.0 s elapsed on the VM's one CPU 47.4 s crucial path: the smallest it can obtain on any figure of CPUs 67% idle (epoll_pwait 23.1 s, clock_nanosleep 8.53 s, futex 100 ms), 33% computing The crucial way by phase 3.54 s configurePhase ██ 1.67 s buildPhase █ 42.0 s checkPhase █████████████████████ 99 ms 5 another phases The crucial way by process on way pid process, alongside what it started 47.4 s 34 init › attack -e source-stdenv.sh default-builder.sh 41.9 s 4076 ├─ create -j8 SHELL=bash-5.3p3/bin/bash VERBOSE=y check 36.4 s 4910 │ ├─ create › attack › lt-run-tests 3.38 s 5412 │ │ ├─ lt-run-tests hrtime hrtime idle in clock_nanosleep 3.38 s 2.00 s 5013 │ │ ├─ lt-run-tests delayed_accept delayed_accept idle in epoll_pwait 2.00 s 1.62 s 5126 │ │ ├─ lt-run-tests fs_event_watch_dir fs_event_watch_dir idle in epoll_pwait 1.62 s 1.60 s 5103 │ │ ├─ lt-run-tests fs_event_close_in_callback fs_event_close_in… idle in epoll_pwait 1.60 s 1.60 s 5508 │ │ ├─ lt-run-tests metrics_idle_time metrics_idle_time idle in epoll_pwait 1.00 s, computing 600 ms 1.24 s 6095 │ │ ├─ lt-run-tests tcp_write_ready tcp_write_ready 1.14 s 5510 │ │ ├─ lt-run-tests metrics_idle_time_thread metrics_idle_time_t… idle in epoll_pwait 1.00 s 1.10 s 5132 │ │ ├─ lt-run-tests fs_event_watch_file_current_dir fs_event_wat… idle in epoll_pwait 1.10 s 22.6 s │ │ └─ 279 more 5.59 s 4077 │ └─ create test/run-tests 2.22 s 4183 │ ├─ gcc -fPIC -fstack-clash-protection -O2 -U_FORTIFY_SOURCE … 2.10 s 4189 │ │ └─ cc1 /build/source/test/test-fs.c 3.35 s │ └─ 20 more 1.99 s 68 ├─ sh ./autogen.sh 1.99 s │ └─ 9 more 1.67 s 2642 ├─ create -j8 SHELL=bash-5.3p3/bin/bash 1.67 s │ └─ 5 more 1.53 s 403 └─ attack ./configure --disable-static --disable-dependency-tracking… 1.47 s └─ 581 more What would shorten it sooner pid if this took no time 36.1 s all lt-run-tests, 600 processes 6.66 s all cc1, 283 processes 3.38 s 5412 75 sleeps in clock_nanosleep: lt-run-tests hrtime hrtime 2.00 s 5013 2 sleeps in epoll_pwait: lt-run-tests delayed_accept delayed_accept 1.76 s 4189 cc1 /build/source/test/test-fs.c 1.62 s 5126 30 sleeps in epoll_pwait: lt-run-tests fs_event_watch_dir fs_event_watc… 1.60 s 5103 16 sleeps in epoll_pwait: lt-run-tests fs_event_close_in_callback fs_ev… 1.60 s 5508 lt-run-tests metrics_idle_time metrics_idle_time 1.22 s all perl, 9 processes 1.14 s 5510 lt-run-tests metrics_idle_time_thread metrics_idle_time_thread Look closer rewind period 7a29e716 --in PID one process: its threads, sleeps and waits rewind period 7a29e716 --folded the way for flamegraph.pl or speedscope.app rewind period 7a29e716 --perfetto F all procedure on a timeline, for ui.perfetto.dev
The second array is the way as a tree of processes according to Gregg’s colony graph idea. Each row is a procedure alongside everything it started, and its period on the crucial path.22A ps snapshot power young female short-lived procedure invocations; the record has all fork, despite of how brief.
In this build, create inspect needs 41.9 of the total 47.4 seconds, and 36.4 of that is lt-run-tests, libuv’s test runner. The test runner invokes 287 tests all spending 1-3 seconds.
All of those tests are on the path, and the way is a sole chain, so the runner ran them one following another. Worse, most of all test is spent asleep, waiting on timers.
Drag can be small than period on the path.
The final array answers a distinct question: how much sooner would the run complete if this part took no time? The crucial way method calls this drag.
For the really magical part, we can jump to any part of the way and see what was happening, invoke gdb and fork the run at that moment. A profiler hands you a stack, sampled at several instant you can never go rear to. Every example in rewind period is a instant in a recording, and Rewind can replay the run to it.
--in looks inner one process,33It can obtain a pid, a program or a term of the command line. so let’s dive into the hrtime test that spent 3.38 seconds idle in clock_nanosleep:
$ rewind time 7a29e716 --in hrtime lt-run-tests hrtime hrtime (pid 5412) 3.38 s on the crucial way alongside what it started, 7% of the 47.4 s path 100% idle (clock_nanosleep 3.38 s), <1% computing What would shorten it sooner pid if this took no time 3.38 s 75 sleeps in clock_nanosleep Look closer rewind anywhere 7a29e716 115894 --pid 5412 the origin row the archetypal row's period starts at rewind period 7a29e716 --perfetto F all procedure on a timeline
Since this test spent 100% of its period asleep, the stage provided on the final row is anywhere it began. rewind anywhere replays the run to that stage and asks gdb anywhere the thread was:
$ rewind anywhere 7a29e716 115894 --pid 5412 process 5412 (lt-run-tests), thread 5412, at stage 115894 #2 uv_sleep (src/unix/core.c:1869) 1867 1868 do > 1869 rc = nanosleep(&timeout, &timeout); 1870 during (rc == -1 && errno == EINTR); 1871 arguments: msec = 45 locals: timeout = {tv_sec = 0, tv_nsec = 45000000} rc = <optimized out> __PRETTY_FUNCTION__ = <error: Cannot admission recollection at location 0x7fb172519ae8> called from #3 run_test_hrtime (test/test-hrtime.c:39) called from #4 __libc_start_call_main (../sysdeps/nptl/libc_start_call_main.h:58)
🎯 We can see that the test is calling uv_sleep(45) from row 39 of test/test-hrtime.c, and that it is sleeping for 45 milliseconds. It does that 75 times for a total of 3.38 seconds.44Turns out that the test sleeps on purpose: it is checking how far uv_hrtime moves throughout a sleep. There is nothing to optimize in this case.
As the cherry on top: the run is deterministic, so stage 115,894 is the identical education all period you replay it. You can open rewind gdb at that stage and examine to your heart’s content.
The Rewind app’s Time tab shows the identical answers. The way becomes a fire graph, colored the way Gregg colors his off-CPU fire graphs: computing is warm, idle is blue, and a procedure shades from one to the another by how much of its period it slept.
Clicking a example picks it and moves the playhead there, so the build log, the procedure tree and the records all display that moment; clicking a procedure again zooms into it. When you choice a blue frame, the app replays the run to that part’s longest sleep and shows the stack anywhere it slept:
Under the stack, Show source opens the origin panel at that instant on that thread, and Open gdb here opens gdb in a fork of the run at the sleep:
If you’d fairly use tools you already know, rewind period can emit the data in their formats: folded stacks for flamegraph.pl and speedscope, or a Perfetto trace for ui.perfetto.dev.
The fire chart below is the genuine flamegraph.pl output: click a example to zoom in, or open it on its own.
§Kneeling at the altar
Every idea current predates Rewind. Gregg has been example off-CPU and wakeup fire graphs for complete a decade, and build systems have reported crucial way data possibly equal longer.55Bazel’s crucial way analysis is a awesome example of this, and it has been about for years. I have been inspired by his activity since I archetypal dabbled in eBPF, rear whenever flame graphs were new. 🙇
What Rewind adds is the data. Lots of it.
Rewind has that data since it can’t replay without it. On a sole CPU the lone item that changes from run to run is the scheduler, so all record already logs all environment switch.
This changes the economics of achievement analysis. On a live machine, you have to trace before the run, and tracing has a cost. You can lone trace a few runs, and you have to choice which ones. Rewind traces all run, so you can analyze any of them later, and do so exactly.
It has fair been a manic fever joy to obtain ideas I have admired for years, item them at a deterministic VM, and observe them activity in ways that are difficult or unattainable on a normal machine.
Please obtain rewind period as my offering at the altar of Brendan Gregg.




