Interactive demos for thag_rs and thag_profiler - run Rust profiling examples without installing thag!
One-line demo experience:
curl -sL https://raw.githubusercontent.com/durbanlegend/thag_rs/main/thag_demo/install_and_demo.sh | bashOr install manually:
cargo install thag_demo
thag_demo --listthag_demo is a lightweight facade over thag_rs that provides curated profiling examples and demonstrations. It's designed to let you explore the capabilities of thag_profiler without needing to install the full thag_rs toolkit.
thag_demo basic-profilingLearn the fundamentals of function timing and profiling with the #[profiled] attribute.
thag_demo time-profilingExecution time profiling of nested functions with automatic flamegraph generation and browser visualization.
Click to watch: The demo shows building and running an instrumented program, then generating an interactive flamegraph
📋 **Detailed steps**
-
Type thag_demo to show the welcome screen showing options.
-
Type thag_demo time-profiling to invoke the time profiling demo.
-
Builds (if needed) and runs a sample program instrumented with thag_profiler execution time profiling.
-
Offers to show a flamegraph of the results. Respond ‘y’.
-
Displays collected stats while it builds and shows the flamegraph in the browser.
-
The flamegraph is not recorded by the
asciinemarecorder because the latter is terminal-based, but is shown both as PNG and interactive SVG in thag_demo README.md. -
End of demo.
Interactive flamegraph showing execution time across nested function calls. Click image for interactive version with clickable bars and search.
📋 **Try this**
-
Hover to see details and see the following displayed for each one as a tooltip and also in the bottom area:
a. function name, preceded by
asyncif applicableb. elapsed time in microseconds
c. percentage of total elapsed time that this bar accounts for.
-
Search for functions Find functions whose names contain
_a:- Click on the
Searchlink in the top right corner, enter_ain the dialog that pops up, and press Enter. Bars with matching text will display in pink. Notice that matching functions appear in three different places stacks.
- Click on the
-
Expand bars and undo Click on one of the pink bars and see how it expands to the full width of the screen, with its call stack below it.
Click on the
mainorallbar at the bottom to restore the full view.Click on another of the pink bars and see it do the same, showing its slightly different call stack below it.
-
Reset view To remove the pink highlighting, click on the
Resetlink.
thag_demo memory-profilingExplore memory allocation tracking, heap analysis, and memory flamegraphs.
thag_demo async-profilingDiscover how to profile async functions, futures, and Tokio runtime integration.
thag_demo comparisonSee before/after performance analysis with differential profiling techniques.
thag_demo flamegraphGenerate and understand interactive flamegraphs for visual performance analysis.
thag_demo benchmarkRun a full-featured benchmark showcasing all profiling capabilities.
thag_demo browseBrowse and run demo scripts interactively with filtering and search.
Click to watch: The demo shows running thag_demo browse to view all the thag scripts in $THAG_DEMO_DIR, and selecting and running the ratatui showcase demo. It also highlights the use of thag_styling integrations to automatically theme both the inquire selection list and the ratatui showcase screen with the current catppuccin-mocha theme.
📋 **Detailed steps**
-
Invoke thag_demo with the browse option.
-
Inquire crate displays themed scrollable list of thag demo scripts.
-
Type rata to narrow the search on the fly.
-
Arrow down to select ratatui_theming_showcase script.
-
Enter to invoke run options for the script.
-
Final Enter builds script if needed and runs it.
-
Demo shows
ratatuishowcase app, themed bythag_stylingwith the terminal’s currentcatppuccin-mochatheme, as specified by $THAG_THEME. -
Show first panel of app with progress bar responding to keys or mouse. The dashed vertical border effect in some areas is an artifact of the video player.
-
Show pop-up help.
-
Show remaining 3 panels in turn.
-
Enter q to return to thag_demo browse.
-
Esc to end thag_demo browse.
thag_demo list-scriptsSee all available demo scripts with descriptions and categories.
thag_demo manageDownload, update, or manage the demo script collection.
thag_demo script <script_name>Run any script from the thag_rs demo collection.
- Zero installation friction - One command to install and run
- Interactive demo browser - Browse 330+ demo scripts with filtering and search
- Automatic demo directory management - Downloads demo collection as needed
- Interactive examples - Each demo explains what it's doing
- Progressive complexity - Start simple, work up to advanced features
- Visual output - Generates flamegraphs and performance visualizations
- Educational - Learn profiling techniques through practical examples
- Comprehensive - Covers time, memory, async, and differential profiling
- Smart discovery - Finds demo directory in multiple standard locations
- Function-level timing with
#[profiled] - Flamegraph generation and interpretation
- Hotspot identification and analysis
- Allocation tracking and visualization
- Memory leak detection
- Heap analysis and optimization
- Profiling async functions and futures
- Understanding async execution patterns
- Tokio runtime integration
- Differential profiling for before/after comparisons
- Custom profiling annotations
- Performance optimization techniques
thag_demo is a thin wrapper around thag_rs that:
- Bundles curated examples - High-quality profiling demonstrations
- Manages demo collection - Automatically downloads 330+ demo scripts
- Provides interactive browsing - Filter and search through demos by name/category
- Configures thag_rs - Pre-configured for optimal demo experience
- Provides guidance - Explains what each demo teaches
- Generates artifacts - Creates flamegraphs and profile data you can explore
The tool automatically searches for demo scripts in multiple locations:
-
Sibling to thag_demo installation
-
~/.thag/demo(standard user location) -
$THAG_DEMO_DIRenvironment variable -
./demoin current directory
If not found, it offers to download the demo collection using thag_get_demo_dir.
thag_demo browse- Filter demos by typing part of the name
- Navigate with arrow keys
- See descriptions and categories inline
- Run demos directly from the browser
thag_demo manage- Download the demo collection if not present
- Update existing demo collection
- View directory information and statistics
- Browse demos interactively
thag_demo list-scripts- Shows both built-in demos and script demos
- Displays descriptions and categories
- Provides usage examples
- Rust toolchain (stable)
- Internet connection (for demo directory download)
- Git (for downloading demo collection)
Each demo generates several files you can explore:
*.svg- Interactive flamegraphs (open in browser)*.folded- Raw profile data for analysis- Console output with explanations and tips
All demos use thag_profiler annotations:
use thag_profiler::{enable_profiling, profiled};
#[profiled]
fn my_function() {
// Your code here
}
#[enable_profiling(time)]
fn main() {
my_function();
}After running the demos:
- Explore the flamegraphs - Open the
.svgfiles in your browser - Try thag_profiler - Add profiling to your own projects
- Use thag_rs - Install the full toolkit for script development
- Read the docs - Check out the full documentation
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributions will be considered (under MIT/Apache 2 license) if they align with the aims of the project.
Rust code should pass clippy::pedantic checks.
