#Look inside a running program
⚠️ Experimental: Haskell Inspector is under active development. Many features already work with existing GHC releases, while others depend on runtime support we are working to bring to future GHC versions. Expect rough edges and interface changes; feedback and bug reports are very welcome.
Haskell's type system is famously powerful: if it compiles, it works! But what if it works poorly? Perhaps after some upgrades your program keeps eating more memory, and latency spikes are ruining its responsiveness. How do you fix it? What is the root cause? Did GHC miss a specialization? Did you forget a strictness bang? Maybe one of the dependencies is at fault?
These are the kinds of questions that Haskell Inspector aims to answer. Haskell Inspector attaches to the running program and shows you what is happening right now: what each thread is doing, what is on the heap, and what is keeping it alive.
You can use Haskell Inspector through its web interface, which integrates seamlessly into Visual Studio Code and works just as well standalone in any browser. For scripts and automated testing there is an extensive command-line interface.
#Features
Haskell Inspector is built around live monitoring. You connect to your program and see what the threads are doing, how much stack space they use, how much time is spent in the garbage collector. All without disturbing or slowing down your program. If you notice something amiss, you can dig deeper for more detail: Record a profile to see where time is spent, or pause the program to see exactly what data is in memory and on the stack of each thread.
#Live Inspection
After connecting you see what every thread is doing and what it is waiting on. Runtime statistics update live alongside: heap size, allocation rate, GC pressure, and per-capability activity.
The latency monitor watches for sections where a thread cannot be interrupted, such as a long GC or an unsafe foreign call that never yields, and flags them as they occur. Exceptions are collected and shown with a stack trace.
You can also inspect the eventlog directly, in a streaming view that handles millions of rows, with filtering and grouping by event kind.
⚙️ How it works: Most of the timeline and heap data comes directly from the eventlog of your Haskell program. Stack depths and exceptions are tracked by intercepting calls to RTS functions.
#Profile While It Runs
Where is your program spending its time and memory? Start recording a profile and find out as it happens: the report builds up while the program runs.
All of GHC's built-in profiling modes are supported: ticky counters,
cost-centre profiling, and heap census grouped by cost centre or info
table. The data is the same the static profilers produce, but you read
it interactively against the live process instead of waiting for a
.prof file after the program exits.
And if the overhead of the profiling runtime is too much for your program, there are lightweight sampling modes that work on any binary: an STG-stack sampler that records Haskell call stacks, and a runtime-stack sampler that captures both the C and Haskell call stacks. Neither slows your program down significantly.
⚙️ How it works: Haskell Inspector uses the Haskell RTS to capture cost centre stacks and ticky counters. Runtime stacks are sampled using operating system specific methods, such as an eBPF program or signal handlers on Linux, Mach thread APIs on macOS,
SuspendThreadon Windows. Names come from IPE (info-table provenance) information, DWARF debugging information or dynamic library symbols.
You can export your recorded profiles to various common formats:
speedscope, pprof, Chrome trace, and flamegraph.pl-style folded
stacks (--format folded).
#HEQL Your Heap
Pause your program and you get access to detailed heap inspection tools. The heap exploration query language HEQL (pronounced "heckle") lets you quickly answer the most important questions about the state of your running program. "Which data is kept alive by my thread's stack?", "Does my data structure contain long chains of thunks?", "Does the heap contain many duplicated data structures?". It's all just one HEQL away!
HEQL queries have a syntax similar to list comprehensions. Each query returns results in the form of cards or tables. This is a thunk-chain detector: it follows chains of thunks and reports each long one as a finding card, with the worst offenders attached as evidence.
view thunk-chain "Long thunk chains" =
[ card (first p)
{ title = "Long THUNK chain ({count (nodes p)} deep)"
, count = count (nodes p), evidence = take 3 (nodes p) }
| p <- chains /dom[thunkLike]/ thunkLike
, count (nodes p) >= 4, (first p).retained >= 4KiB ]for p : Path <-
((chains : RPQ -> (Node -> Bool) -> Bag Path)
(/…/ : RPQ)
\c : Node ->
((c : Node).type : CType)
in ({(THUNK : CType), (AP : CType)} : Bag CType) : Bool
: Node -> Bool)
: Bag Path
in
filter
((count : (Seq Node) -> Q 1)
((nodes : Path -> Seq Node) (p : Path) : Seq Node))
: Q 1
>= (4 : Q 1) : Bool
&& ((first : Path -> Node) (p : Path) : Node).retained
: Q B
>= (4KiB : Q B) : Bool : Bool
{((card : Node -> { title : Text, count : Q 1, evidence : Seq Node } -> Finding)
((first : Path -> Node) (p : Path) : Node)
{ title = "Long THUNK chain ({(count (nodes p))} deep)"
: Text
, count = ((count : (Seq Node) -> Q 1)
((nodes : Path -> Seq Node)
(p : Path))
: Seq Node)
: Q 1
, evidence = ((take : (Q 1) -> (Seq Node) -> Seq Node)
(3 : Q 1)
((nodes : Path -> Seq Node)
(p : Path))
: Seq Node)
: Seq Node
}
: { title : Text, count : Q 1, evidence : Seq Node })
: Finding}
: Bag Finding
: Bag Finding
: Bag Findingcaps dominators paths
budget arena=0 nodes=0 wall=0
kinds Con=0 Thunk=1 Fun=2 Pap=3 Ap=4 Ind=5 BlackHole=6 MVar=7 MutVar=8 TVar=9 Array=10 ByteArray=11 Weak=12 TSO=13 Stack=14 Blocking=15 Other=16
strand Sspine par=serial -> Result {
spine step=/dom/ follow=\c -> (c.type in [THUNK, AP]) pred=\c -> (c.type in [THUNK, AP])
filter ((count(nodes(%)) >= 4) && (first(%).retained >= 4KiB))
project [card(first(%), {title = "Long THUNK chain ({count(nodes(%))} deep)", count = count(nodes(%)), evidence = take(3, nodes(%))}) cols=["card":text]]
pull cards
}; FLAX bytecode: the per-row programs the engine compiles via flax_bc_prep
; <strand>:<line> names the FLAX Plan operator; a trivial or dynamic expression runs on eval_re
Sspine:1 filter:
0 sp=1 EVAL count(nodes(%))
1 sp=2 CONST 4
2 sp=1 CMP >=
3 sp=0 AND_JF -> 8
4 sp=1 EVAL first(%).retained
5 sp=2 CONST 4096
6 sp=1 CMP >=
7 sp=1 TRUTHY
Haskell Inspector comes with a catalog of HEQL queries to quickly analyze your program and to get you started writing your own; the standard library and prelude references document everything available to your queries. The web interface offers live type checking while you work on your query. Each query can return values that feed into new queries, letting you build interactive views of the heap. You can drill down to get the details you need, even down to a hex view of individual bytes! You can also run HEQL queries using the CLI to integrate into scripts or your testing workflow.
⚙️ How it works: HEQL queries get compiled to a query plan with stream fusion on one or more strands of execution. The strands source their information from pre-built indices of the heap or from the results of other strands. Large strands are split into chunks for parallel processing. The query evaluation engine FLAX (Fused Live Analysis eXecutor)1 runs the plan inside the inspector, or directly inside the inspected process.
Prefer writing your heap analysis in Haskell instead? You can also export a
heap snapshot that is compatible with the
ghc-debug library.
#Installation
#1. Install haskell-inspector
Install the inspector from Hackage:
cabal install inspector
This puts the haskell-inspector binary on your
PATH (cabal installs to ~/.cabal/bin by default), along with hins,
the same program under a shorter name for interactive use. The web
interface and the CLI are both included.
Optional: the VS Code extension embeds the web interface in the editor and lists the inspectable processes of the current workspace. Install it from the Visual Studio Marketplace or Open VSX, or build it yourself from
haskell-inspector/extras/vscode-extensionin the repository; its README covers building and installing. It expects thehaskell-inspectorbinary onPATH.
#2. Add the connector to your program
Making your program inspectable is easy, just add
haskell-inspector-connector package to your component's
build-depends:
build-depends:
...
, haskell-inspector-connector
or use the sublibrary of the haskell-inspector package:
build-depends:
...
, haskell-inspector:connector
When your program is linked against the connector library, it will create a descriptor file on startup, in a location where the inspector can find it, and listen on a socket for an inspector to attach.
The inspector works with any build, but it can tell you much more
when the program carries debugging metadata: IPE information maps heap
objects back to source locations (with a separate table per constructor,
so each constructor gets its own allocation site), and DWARF symbols let
the runtime-stack sampler resolve names for stack frames. To enable both
for your application and all its dependencies, add this to your
cabal.project:
package *
ghc-options: -finfo-table-map -fdistinct-constructor-tables
debug-info: 2
The package * stanza also covers dependencies, so the first build
after adding it recompiles everything.
The connector's startup behaviour can be tuned with environment variables. You can for example start the program paused, or change the socket/descriptor location. See the command line reference for usage information and the full list.
#3. Attach an inspector
If you have installed the VS Code extension, inspectable programs show up in the Haskell Inspector view, filtered to the open workspace, and a badge counts the ones currently running. Click a program to open the inspector next to your code.
Otherwise, just start the web interface from a terminal:
haskell-inspector --web
and open http://localhost:3000. The first view lists every inspectable process discovered on the machine; pick the right one and press Connect:
💡 Tip: use
haskell-inspector --web --port 0to automatically select a free port for the web interface.

#Usage
The web UI aims to be self-documenting. Click around to see the available options. Look for the (i) button in the toolbar to toggle additional information.
Most of the functionality is also available through the CLI. Find the available processes with:
haskell-inspector list
Then connect using a target flag (--pid / --descriptor / --snapshot / --eventlog / --run), pick a control policy (--every / --repeat / --duration / --until-exit),
and an output format (--output / --format).
The general format is
haskell-inspector [GLOBAL-OPTS] [TARGET] [COMMAND [COMMAND-OPTS]] [-- PROG-ARGS]
Refer to the CLI reference for more details.
#Examples
For the full, always-current set of worked examples, run
haskell-inspector help-examples. The recipes below show the shape: a target, an optional control
policy, a command, and an output format:
# Heap consistency check, written to a file, exits non-zero on violations
haskell-inspector -p 12345 consistency --output report.txt
# Heap census by closure type (a built-in HEQL view), as JSON
haskell-inspector -p 12345 heql --tag type-profile --format json
# Live thread status, every 10s, until the program exits
haskell-inspector -p 12345 --every 10s --until-exit threads
# Spawn a program, sample its stacks for 30s, write a speedscope profile
haskell-inspector --run ./myprog --duration 30s \
record samples profile.json --format speedscope -- --my-flag
# Capture everything (snapshot + eventlog + samples + metrics) into a dir
haskell-inspector -p 12345 --duration 2m record all ./report/
#Roadmap
This roadmap is tentative. Haskell Inspector is an experimental project, and what gets built next depends on what users actually run into: if one of these items would help you, or something important is missing, please open a ticket.
- In-process monitoring: Heap invariants checked inside the running program, automatically logging or taking a snapshot when a condition is met.
- Expand conditional breakpoints, more scriptable tracing.
- Extend FLAX engine to support planning/running more queries.
- Fill the query catalog with new queries based on real-world feedback.
- Make CAFs accessible to the query engine.
- Off-CPU profiling: see where threads spend time blocked (on MVars, STM, foreign calls, or the OS scheduler), not just where they burn CPU
- Snapshot comparison: run HEQL queries across two heap snapshots to find what grew, appeared, or leaked between them
- Shareable HEQL query catalogs: query packs that ship with a project or library and are discovered automatically, so a library can provide its own leak detectors and diagnostics
- Extend GHC to improve debugging information
- field-level DWARF information, allowing precise (typed) decoding of heap data structures
- eras profiling without the profiling runtime
- A GHC plugin to add stack annotations based on rules to make backtraces more informative
- The code is currently prototype quality. We are aiming to improve maintainability by making changes to GHC make the layout-dependent code more stable and rely less on live patching.
#Frequently Asked Questions
#I have a performance issue with my Haskell program. Can I solve it with Haskell Inspector?
Haskell Inspector is intended to be the first stop for looking into performance issues, memory leaks and latency spikes. If you're not sure how to approach your problem, or Haskell Inspector doesn't give you the insight you need, please open a ticket describing your situation. Real-world cases like yours help us decide which diagnostics to build next.
#Are editors/IDEs other than Visual Studio Code supported?
Haskell Inspector has a VSCode plugin to automatically discover your inspectable Haskell programs. The plugin also allows the Haskell Inspector web interface to link back to your source files.
You can also launch Haskell Inspector directly with haskell-inspector --web.
See the command line reference for more information about command line options
and environment variables.
If you think Haskell Inspector integration with other development environments could be improved, please open a ticket, or a pull request.
#Which Haskell compilers are supported?
Currently we support GHC 9.6+. We are actively working on improving GHC debugging information and RTS debugging instrumentation to make new versions provide more functionality.
If your favourite Haskell compiler is not supported, please open a ticket!
#Is this whole project just an excuse to write a query language and make some silly puns?
Maybe
#Acknowledgements
Haskell Inspector grew out of Haskell performance work at IOG, and wishing for better tools to do it with. It builds on ideas from many projects and people. Here are some:
- Many ideas were introduced by
ghc-debug2: the out-of-process attach model with a small linked connector, the RTS pause API, and the heap-traversal machinery. Theghc-debug-client3 library is still used for decoding heap objects. - The timeline view is based on ThreadScope,4 whose
development also gave rise to GHC's eventlog and the
ghc-eventslibrary that the live views are built on. - The live stats views are inspired by
eventlog2html.5 - The profile views follow Brendan Gregg's flame graphs6 and Jamie Wong's speedscope7.
- HEQL combines ideas from query-language research: Comprehensions as query syntax,89 a nested relational calculus with monoid aggregation as the core,1011 and path patterns from modern graph query languages.1213
#License & links
Haskell Inspector is licensed under BSD-3-Clause OR Apache-2.0, at your option, written by Luite Stegeman, IOG/ICAN.
Footnotes
-
No relation to Flax, Google's neural network library for JAX. ↩
-
ghc-debug, by Ben Gamari, Matthew Pickering, David Eichmann, Hannes Siebenhandl and others. ↩ -
ghc-debug-clienton Hackage. ↩ -
ThreadScope, by Satnam Singh, Simon Marlow, Donnie Jones, Duncan Coutts et al., described in Parallel Performance Tuning for Haskell (Haskell Symposium 2009). ↩
-
eventlog2html, by Matthew Pickering, David Binder, and Claude Heiland-Allen. ↩ -
Brendan Gregg, flame graphs; The Flame Graph, ACM Queue, 2016. ↩
-
Jamie Wong, speedscope. ↩
-
Philip Wadler, Comprehending Monads, LFP 1990. ↩
-
Simon Peyton Jones and Philip Wadler, Comprehensive Comprehensions, Haskell Symposium 2007. ↩
-
Leonidas Fegaras and David Maier, Optimizing Object Queries Using an Effective Calculus, ACM TODS 2000. ↩
-
James Cheney, Sam Lindley and Philip Wadler, A Practical Theory of Language-Integrated Query, ICFP 2013. ↩
-
The GQL standard (ISO/IEC 39075:2024), described by Alin Deutsch et al., Graph Pattern Matching in GQL and SQL/PGQ, SIGMOD 2022. ↩
-
Renzo Angles et al., G-CORE: A Core for Future Graph Query Languages, SIGMOD 2018. ↩


