thag_demo
Interactive demos for thag_rs and thag_profiler - run Rust profiling examples without installing thag!
Quick Start
One-line demo experience:
|
Or install manually:
What is thag_demo?
thag_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.
Available Demos
π₯ Basic Profiling
Learn the fundamentals of function timing and profiling with the #[profiled] attribute.
β±οΈ Time Profiling
Execution time profiling of nested functions with automatic flamegraph generation and browser visualization.
Demo
Click to watch: The demo shows building and running an instrumented program, then generating an interactive flamegraph
-
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.
-
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.
π§ Memory Profiling
Explore memory allocation tracking, heap analysis, and memory flamegraphs.
π€ΉββοΈ Async Profiling
Discover how to profile async functions, futures, and Tokio runtime integration.
βοΈ Performance Comparison
See before/after performance analysis with differential profiling techniques.
π Interactive Flamegraphs
Generate and understand interactive flamegraphs for visual performance analysis.
π Comprehensive Benchmark
Run a full-featured benchmark showcasing all profiling capabilities.
π§ Interactive Demo Browser
Browse and run demo scripts interactively with filtering and search.
Demo
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.
-
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 artefact 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.
π List All Scripts
See all available demo scripts with descriptions and categories.
βοΈ Demo Directory Management
Download, update, or manage the demo script collection.
π Custom Scripts
Run any script from the thag_rs demo collection.
Features
- 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
What You'll Learn
Time Profiling
- Function-level timing with
#[profiled] - Flamegraph generation and interpretation
- Hotspot identification and analysis
Memory Profiling
- Allocation tracking and visualization
- Memory leak detection
- Heap analysis and optimization
Async Profiling
- Profiling async functions and futures
- Understanding async execution patterns
- Tokio runtime integration
Advanced Features
- Differential profiling for before/after comparisons
- Custom profiling annotations
- Performance optimization techniques
How It Works
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
Demo Directory Discovery
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.
Interactive Commands
Browse Demos Interactively
- Filter demos by typing part of the name
- Navigate with arrow keys
- See descriptions and categories inline
- Run demos directly from the browser
Manage Demo Directory
- Download the demo collection if not present
- Update existing demo collection
- View directory information and statistics
- Browse demos interactively
List All Available Scripts
- Shows both built-in demos and script demos
- Displays descriptions and categories
- Provides usage examples
Requirements
- Rust toolchain (stable)
- Internet connection (for demo directory download)
- Git (for downloading demo collection)
Output Files
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
Integration with thag_profiler
All demos use thag_profiler annotations:
use ;
Next Steps
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
Resources
License
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.
Contributing
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.