flamegraph-textual
flamegraph-textual is an interactive flamegraph component for
Textual.
It is the rendering library extracted from flameshow. Use it when you want to embed a terminal flamegraph inside your own Textual app instead of launching a standalone viewer.
Install
From PyPI:
pip install flamegraph-textual
From a local checkout:
git clone git@github.com:laixintao/flamegraph-textual.git
cd flamegraph-textual
pip install -e .
For development with Poetry:
git clone git@github.com:laixintao/flamegraph-textual.git
cd flamegraph-textual
poetry install
What It Does
- Renders flamegraphs as a Textual widget
- Parses profile input for you
- Supports keyboard and mouse navigation
- Supports multiple sample types when present in the profile
- Works with bundled demo data or your own files
Quick Start
FlameGraphView is the main entrypoint. Pass it raw profile data and a
filename. The library parses the content internally.
from pathlib import Path
from textual.app import App, ComposeResult
from flamegraph_textual import FlameGraphView
class Demo(App):
def compose(self) -> ComposeResult:
profile_bytes = Path("profile.out").read_bytes()
yield FlameGraphView(profile_bytes, filename="profile.out")
Demo().run()
For stackcollapse text input, passing str also works:
from pathlib import Path
from flamegraph_textual import FlameGraphView
profile_text = Path("stacks.txt").read_text(encoding="utf-8")
widget = FlameGraphView(profile_text, filename="stacks.txt")
# Optional: skip auto-detection when you already know the format
widget = FlameGraphView(
profile_text,
filename="stacks.txt",
profile_type="stackcollapse",
)
For Austin collapsed text, use the same parser explicitly:
from pathlib import Path
from flamegraph_textual import FlameGraphView
austin_text = Path("austin.txt").read_text(encoding="utf-8")
widget = FlameGraphView(
austin_text,
filename="austin.txt",
profile_type="austin",
)
Supported Input Formats
pprof: pprof protobuf profilesstackcollapse: generic collapsed-stack text in FlameGraph formataustin: Austin collapsed text; parsed with the same stackcollapse parser
Format Notes
pprofBinary protobuf profiles such as Gopprofoutput. Use this when your input is raw profile bytes.stackcollapsePlain text in collapsed-stack format, where each line looks likeframe_a;frame_b;frame_c 10.austinAustin's collapsed text output is stackcollapse-compatible, often with metadata comment lines such as# austin: ...,# interval: ..., and# mode: .... Those comment lines are ignored by the parser.
The parser selection is automatic through: parse
Try It Immediately
This repo includes sample profiles under:
Run the bundled examples with no setup:
python examples/pprof_binary.py
python examples/pprof_binary.py --sample goroutine
python examples/pprof_binary.py --sample heap
python examples/stackcollapse_text.py
python examples/stackcollapse_text.py --sample simple
python examples/stackcollapse_text.py --sample perf
You can still pass your own file path:
python examples/pprof_binary.py /path/to/profile.out
python examples/stackcollapse_text.py /path/to/stacks.txt
Main API
The public exports are defined in: init.py
Most users should start with:
- FlameGraphView for embedding a flamegraph widget in a Textual app
- parse if you want to parse profile bytes yourself
parse(...) and FlameGraphView(...) both support an optional
profile_type argument. Supported values are pprof, stackcollapse, and
austin. If omitted, the library auto-detects the parser as before.
Other public exports:
FlameGraphAppconvenience alias around the full demo-style appFlameGraphlower-level rendering widgetFlameGraphScrollscroll container used around the flamegraph widgetFrame,Profile,SampleTypedata model typesFrameMap,add_arraylower-level rendering helpers used by the widget
Controls
Inside the widget:
j/k/h/lor arrow keys move selectionEnterzooms inEsczooms outTabswitches sample typeiopens the detail screen when mounted inside a Textual app- Mouse hover updates frame details
- Mouse click zooms into a frame
Regenerate Protobuf Bindings
The canonical pprof schema lives in: profile.proto
The generated Python module lives in: profile_pb2.py
Regenerate it with:
poetry add --group dev grpcio-tools
poetry run python -m grpc_tools.protoc \
-I proto \
--python_out=flamegraph_textual/parsers \
proto/profile.proto
Development
Run tests with:
pytest -q
Changelog
Unreleased
- Added speedscope format parser (
SpeedscopeParser) supporting botheventedandsampledprofile types. - Added Google Trace Event format parser (
GoogleTraceParser). parse()andFlameGraphViewnow accept an optionalprofile_typekeyword argument ("pprof","stackcollapse","austin","speedscope","google_trace") to skip auto-detection.
Metadata
Release files for flamegraph-textual 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flamegraph_textual-0.1.2.tar.gz | 23.8 kB | Without provenance | Details for flamegraph_textual-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flamegraph_textual-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for flamegraph_textual-0.1.2-py3-none-any.whl |
Total release size: 55.0 kB
Release files / flamegraph_textual-0.1.2.tar.gz
| Download URL | flamegraph_textual-0.1.2.tar.gz |
|---|---|
| Size | 23.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d9e489120e3144be00a7a7eee85908c4256a613a8dd6099552d7c132c3dfe22
|
|
BLAKE2b-256 checksum How to use checksums |
6e1164a977d1b70f55105978f641282926b48c881d2be0ccfb2a9c32e224647f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.13.14 Darwin/24.6.0
|
Release files / flamegraph_textual-0.1.2-py3-none-any.whl
| Download URL | flamegraph_textual-0.1.2-py3-none-any.whl |
|---|---|
| Size | 31.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4b486139b09c9f109707329d7c1a2cced0e7a4a78f2f1d56524f6d8f67e360a0
|
|
BLAKE2b-256 checksum How to use checksums |
b0c6e97e9ce4bc1d6ce266c3a01c295fd24b36c4608f1401b2b2ac04fcb53cc7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.13.14 Darwin/24.6.0
|
Security for flamegraph-textual 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.