Watch a running app
ztk top shows what a ztk app does while it runs: its interpreters and threads, the compute units and memory of each one, and the time of each frame of its window. It reads the app through the observe service of ztcl, and only the user who started the app can read it.
A model of the window panel that ztk observe is to open runs live on the page The observe panel, live, with made-up data.
Start the app with the service
Start the app with --observe:
ztk --observe app.tcl
The program prints the address of the service on stderr:
ztk: observe at /tmp/ztcl-501/observe-4242.sock
The number in the name is the process id of the app. With no --observe, the app has no service.
Open the panel
In another terminal, give ztk top the process id:
ztk top 4242
The panel opens in a window and reads the app five times a second.

The summary at the top has the count of interpreters and threads, the compute units each second of the whole app with a trend, the memory, the 99th percentile of the frame time, and the count of widgets.
The overview lists each interpreter, child interpreter, and thread, with:
- its state: busy or idle,
- its compute units each second, and a trend of the last 12 seconds,
- its memory, against its limit when it has one,
- the proc that runs in it, when one runs.
Click a row to see its capabilities, the procs on its stack, and its WebAssembly instances in the pane on the right.
The frames of the window
Press 2, or click Frames, for the time of each frame of the window.

A frame has five stages: events, style, layout, paint, and render. The chart has the median time of each stage for each sample. The table has the 50th and 99th percentile of each stage over the last 256 frames. A late frame needed more than 16.7 ms of work in its stages, the time of one frame at 60 Hz, and a slow frame more than 100 ms. A Debug build of ztk has many late frames: Skate Pond on Windows gave 99 late frames of 469 in a Debug build, and none in a ReleaseFast build. Slow frames explains how to find the cause of one.
Keys
| Key | Action |
|---|---|
| 1 | The overview |
| 2 | The frames |
| P | Pause the view; the app runs on |
Another address
--observe=PATH puts the socket at PATH, and ztk top PATH reads it. Use a folder that only you can open.
ztcl top reads the same service in a terminal, and ztcl top --json PID prints one snapshot as JSON, with the frames of the window in its field ztk. Debugging lists the fields.
Safety
- The service is off unless the app starts with
--observe. A library build of ztk has no service. - The socket and the token file belong to the user who started the app, with mode 0600, in a folder of that user. They go away when the app ends.
- The service only answers reads. No request reaches the scripts of the app.
Limits
- The panel shows the data that the service has today: interpreters, threads, compute units, memory, the stack, WebAssembly instances, and frames. The views of the design for the event loop, the network, and the memory by kind come later.
- The panel of the web build of ztk follows.
- The tests of the panel run on Linux in CI, and on macOS by hand. Windows has the service of ztcl on a named pipe, and the panel has no test there yet.