Skip to main content

Terminal flamegraph renderer built for Textual

Project description

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 profiles
  • stackcollapse: generic collapsed-stack text in FlameGraph format
  • austin: Austin collapsed text; parsed with the same stackcollapse parser

Format Notes

  • pprof Binary protobuf profiles such as Go pprof output. Use this when your input is raw profile bytes.
  • stackcollapse Plain text in collapsed-stack format, where each line looks like frame_a;frame_b;frame_c 10.
  • austin Austin'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:

  • FlameGraphApp convenience alias around the full demo-style app
  • FlameGraph lower-level rendering widget
  • FlameGraphScroll scroll container used around the flamegraph widget
  • Frame, Profile, SampleType data model types
  • FrameMap, add_array lower-level rendering helpers used by the widget

Controls

Inside the widget:

  • j / k / h / l or arrow keys move selection
  • Enter zooms in
  • Esc zooms out
  • Tab switches sample type
  • i opens 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 both evented and sampled profile types.
  • Added Google Trace Event format parser (GoogleTraceParser).
  • parse() and FlameGraphView now accept an optional profile_type keyword argument ("pprof", "stackcollapse", "austin", "speedscope", "google_trace") to skip auto-detection.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flamegraph_textual-0.1.1.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flamegraph_textual-0.1.1-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file flamegraph_textual-0.1.1.tar.gz.

File metadata

  • Download URL: flamegraph_textual-0.1.1.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.13 Darwin/24.6.0

File hashes

Hashes for flamegraph_textual-0.1.1.tar.gz
Algorithm Hash digest
SHA256 81ce0b47c25d80aa2d0847460589a90d4ac44cc6513586e9c082496518e6910e
MD5 33b15c17baffa22c10ddbaa04806cdbd
BLAKE2b-256 7d48029da6818f65a0f78a48f71aecb2cfc733af75c481b45c4d97d437c386d8

See more details on using hashes here.

File details

Details for the file flamegraph_textual-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: flamegraph_textual-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 31.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.13 Darwin/24.6.0

File hashes

Hashes for flamegraph_textual-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c65d8e70ac8b06476393566434d7315a46a5e95bef8c5539601d9dc6173e2c4a
MD5 edb2439c129f02c3d070dbe7d9090574
BLAKE2b-256 e0281e5aa7cfbf68013704d6e575ad2735e4d9d42df6c395b1b77d615cefa3f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page