ggml-viz
A tracer and desktop viewer for programs built on ggml, the tensor library under llama.cpp and whisper.cpp. Preload a hook into the binary you already have and it records every compute graph, every op and how long it took, and what memory ggml allocated, without rebuilding anything or changing the program’s output.

The Graph
Each forward pass is a ggml compute graph. The hook records every node with its op and inputs when the graph starts, so the viewer redraws the real data flow: one graph at a time, top to bottom in execution order, every node placed just above the first op that uses it. Zoomed out, a transformer block reads off the screen: the norm, the Q, K and V projections fanning out, their writes into the KV cache, attention, then the feed-forward chain.

Where the Time Goes
Per-op timing comes from ggml’s own scheduler callback, so the times are the scheduler’s real node boundaries rather than estimates. The timeline shows them in order; the Op Timings tab ranks them. On this run the answer is plain: the feed-forward matmuls of each layer dominate the prompt.


How It Works
- Capture
- LD_PRELOAD on Linux, DYLD_INTERPOSE on macOS; the hook wraps ggml’s graph compute, scheduler and tensor allocation calls.
- Ops
- The scheduler’s eval callback, chained with any callback the program already set.
- Memory
- Every tensor ggml places in a buffer, including weights llama.cpp maps from the model file. Recorded in the trace; the viewer’s memory panel is not built yet.
- Format
- Events pass through a lock-free ring buffer into GGMLVIZ, a small binary format the viewer reads after the run or live as it grows.
- Cost
- Timing every op makes the scheduler run one node at a time: this run took 1.8 s traced against 1.3 s untraced, with identical output.
- Tested
- llama.cpp on CPU, Linux and macOS. Metal, CUDA and Windows are untried.
Run It
# build git clone --recursive https://github.com/brodheadw/ggml-viz.git cd ggml-viz && cmake -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build -j # trace any llama.cpp binary, unmodified GGML_VIZ_OUTPUT=trace.ggmlviz GGML_VIZ_MEMORY_TRACKING=1 \ LD_PRELOAD=build/src/libggml_viz_hook.so \ ./llama-simple -m model.gguf -n 32 "The capital of France is" # macOS: DYLD_INSERT_LIBRARIES=build/src/libggml_viz_hook.dylib # view it (or --live trace.ggmlviz to follow a run as it writes) ./build/bin/ggml-viz trace.ggmlviz