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

pip install flamegraph-textual

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")

Supported Input Formats

  • pprof protobuf profiles
  • stackcollapse text

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

Most users only need:

Other exports are available if you want lower-level control:

  • FlameGraph
  • FlameGraphScroll
  • Frame
  • Profile
  • SampleType

See: init.py

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

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.0.tar.gz (19.4 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.0-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for flamegraph_textual-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c996c614a7433e8ed4f52ce8efd7377bd31c70650acb3a0bc61810e24cbc6c98
MD5 070dfc55c716a306201a346d4aa6313e
BLAKE2b-256 b120570fb74d512cadbe21d2d4dfaad7df8503294c815fa788fbcd830fffeefa

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for flamegraph_textual-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 febfefb6c56e06ec3b907ec52a1f9bc884c6140643a95fa75657026e55ff9b79
MD5 a58889101b2716ee13d6e61f664b7fda
BLAKE2b-256 b71f71c7ea782e0dd837ba23490b54df26186ecdbb1b39a65eb9dd8ae0537b08

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