macOS xterm-256color zsh 28 views

Tip: View in full-screen mode for best legibility

Use f to toggle full-screen mode.

Steps

Use thag_instrument to make a copy of demo/document_pipeline.rs called demo/document_pipeline_instr.rs, instrumented for thag_profiler. We specify that the code being profiled is at Rust Edition 2021.

Compare the two files, showing that thag_instrument has added a thag_profiler import and annotated fn main with #[enable_profiling] and every other function with #[profiled].

Build and run the instrumented program to profile it. Since it’s a stand-alone thag script , we do so using thag demo/document_pipeline_instr.rs.

Now we are ready to analyse the profiling output. Since by default we wrote them to the current working directory, we specify that:

thag_profile .

Although we’ve profiled both execution time and memory, for the demo we’ll choose to view an aggregated time flamegraph. We choose Time Profile - Single, select the latest file document_pipeline_instr-20251013-213201.folded, then Show Aggregated Execution Timeline (Flamegraph). We then get to choose a color scheme and display the graph in the browser.

Since the lightweight asciinema tool can’t see the browser, we’ll exit at this point and return to view it in Part 2 with a heavyweight screen recorder.