· AI dev tools
Rewind adds rewind time command to analyze critical path, inspired by Brendan Gregg's work
The Rewind application now features a new rewind time command designed to pinpoint where execution time was spent during a recording, offering insights into how to achieve a quicker completion.
The Rewind application now features a new `rewind time` command designed to pinpoint where execution time was spent during a recording, offering insights into how to achieve a quicker completion. This tool allows users to delve into specific areas of the analysis to identify the source code lines responsible for the observed timings, creating something akin to Brendan Gregg’s flame graphs, but enhanced for critical path examination and equipped with debugger capabilities.
This new command's concepts draw inspiration from, or are directly influenced by, the pioneering work of Brendan Gregg. Beyond this, a quick note for newcomers: to understand the utility of a deterministic virtual machine, examine a flaky build that only appears once.
To illustrate this, let's observe a libuv build and test run within Rewind. The entire build and test suite consumes 78 seconds when executed on the VM's solitary CPU, yet even utilizing 64 cores, the critical path remains at 47 seconds. Why this substantial difference? The typical suggestion is to review a CPU profile, but in this instance, such a profile would yield nearly no useful information because the build spends two-thirds of those 47 seconds in a waiting state, not actively computing.
Each `rewind time` output begins with two figures: the total duration on the VM's single virtual CPU, and the critical path, which represents the absolute minimum time required across any number of processors. The critical path is defined as the longest sequence of interdependent tasks within a program, signifying the lowest possible completion time irrespective of available resources. The only path to accelerating a program is to reduce its critical path length.
If one respects the contributions of Brendan Gregg, one recognizes his dedication to transforming performance analysis from an intuitive art into a rigorous science; this new feature serves as a small tribute to that legacy.
The initial output for libuv shows: `$ rewind time 7a29e716 libuv-1.51.0 78.0 s elapsed on the VM's one CPU 47.4 s critical path: the least it can take on any number of CPUs 67% asleep (epoll_pwait 23.1 s, clock_nanosleep 8.53 s, futex 100 ms), 33% computing`. The first number details the total time taken on one virtual CPU, while the second is the critical path—the longest chain of work where each step was necessarily delayed by the preceding one. Since no quantity of CPUs can shorten a run beyond its critical path, the difference between these two numbers quantifies the benefit parallelism can provide. The line beneath these figures applies Gregg’s thread state evaluation, revealing that the most significant state observed is "asleep," specifically 23 seconds in `epoll_pwait` and 8.5 seconds in `clock_nanosleep`.
A sleeping thread remains invisible to standard CPU profilers. Gregg’s recommended solution is off-CPU analysis: investigating where threads pause, rather than solely where they perform calculations. On a live machine, conducting off-CPU analysis presents considerable difficulty. While Linux permits tracking which thread awakened another, Gregg developed wakeup and off-wake profiling built upon this capability; however, this tracing must commence before the slow execution, incurs an overhead, and most captured idle periods are mere noise. Rewind, by design, already logs every context switch because it requires them for faithful replay, and now it also records every instance of a wakeup event and the entity that triggered it. All this valuable information resides within every recording.
The detailed output for libuv includes: `$ rewind time 7a29e716 libuv-1.51.0 78.0 s elapsed on the VM's one CPU 47.4 s critical path: the least it can take on any number of CPUs 67% asleep (epoll_pwait 23.1 s, clock_nanosleep 8.53 s, futex 100 ms), 33% computing`. Furthermore, the critical path can be broken down by phase: 3.54 s in `configurePhase`, 1.67 s in `buildPhase`, and 42.0 s in `checkPhase`, alongside 99 ms from five other phases. It can also be viewed by process along the path, showing what each process initiated and its duration on the critical path: 47.4 s for `init` running `bash -e source-stdenv.sh default-builder.sh`, which includes 41.9 s from `make -j8 SHELL=bash-5.3p3/bin/bash VERBOSE=y check`, and 36.4 s from `make` within that, which subsequently invokes `lt-run-tests` for 3.38 s. The test runner itself triggers 287 individual tests, each consuming between one and three seconds. All these tests reside on the path, forming a single chain, meaning the runner executed them sequentially. Compounding the issue, a majority of each test duration is spent waiting, suspended by timers.
The concept of "drag"—how much sooner a run could conclude if a specific segment took no time—is addressed by the last table. For the truly remarkable functionality, users possess the ability to jump to any point along the path and observe the system's state, even invoking `gdb` and forking the execution at that precise instant. A standard profiler provides a stack trace captured at a single moment, a snapshot from which one cannot return; conversely, every frame within `rewind time` represents a captured moment in the recording, allowing Rewind to replay the execution to that specific point. The `--in` flag permits inspection inside a single process, while `--folded` prepares the path for tools like `flamegraph.pl` or `speedscope.app`, and `--perfetto` generates a trace for `ui.perfetto.dev`.
For instance, examining the `hrtime` test, which consumed 3.38 seconds asleep in `clock_nanosleep`, reveals: `$ rewind time 7a29e716 --in hrtime lt-run-tests hrtime hrtime (pid 5412) 3.38 s on the critical path with what it started, 7% of the 47.4 s path 100% asleep (clock_nanosleep 3.38 s), <1% computing`. The "drag" calculation for this segment is 3.38 seconds, with 75 instances of `clock_nanosleep` observed.
A closer look using `rewind time 7a29e716 115894 --pid 5412` reveals the source line where the activity began. Since this test was entirely dormant, the line provided marks its initiation point. Using `rewind where 7a29e716 115894 --pid 5412` replays the execution to that step and presents the stack trace, showing: `#2 uv_sleep (src/unix/core.c:1869) 1867 1868 do > 1869 rc = nanosleep(&timeout, &timeout); 1870 while (rc == -1 && errno == EINTR); 1871 arguments: msec = 45 locals: timeout = {tv_sec = 0, tv_nsec = 45000000} rc = <optimized out> __PRETTY_FUNCTION__ = <error: Cannot access memory at address 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)`. This clearly demonstrates that the test calls `uv_sleep(45)` from line 39 of `test/test-hrtime.c`, resulting in a 45-millisecond pause, repeated 75 times for a total of 3.38 seconds.
It turns out this waiting is intentional; the test is designed to measure how far `uv_hrtime` progresses across a sleep period, meaning there is no optimization possible here. As a final enhancement, the run is deterministic, guaranteeing that step 115,894 will execute the identical instruction every time it is replayed. Users can launch `rewind gdb` at this juncture to investigate thoroughly. The Rewind application’s Time tab presents equivalent data, rendering the path as a flame graph colored according to Gregg's convention: warm tones for computation, cool tones for waiting, with a process shading between the two based on its proportion of time spent sleeping. Selecting a frame advances the playhead to that moment, displaying the build log, process tree, and relevant files for that instant; clicking a process again zooms into its details. When a blue frame is selected, the app replays the run to that segment's longest sleep and displays the stack trace from which it slept. Beneath the stack, "Show source" displays the code panel for that thread at that moment, and "Open gdb here" launches `gdb` in a fork of the running process at the point of suspension.
For those preferring established tools, `rewind time` can export its data in formats compatible with `flamegraph.pl` and `speedscope`, or as a Perfetto trace for `ui.perfetto.dev`. The flame




