CPU profiling
Capture a profile
Section titled “Capture a profile”Build the development profiling binary and start your normal local workflow:
just profile-buildjust run-cliThe profiling build samples CPU activity at 99 Hz and writes gzip-compressed
pprof protobuf files below the active session’s profiling/ directory. Polytoken
writes periodic daemon snapshots and prunes older ones. When the daemon shuts
down, Polytoken writes a final daemon snapshot before closing telemetry and log
output.
The development profiling binary also profiles the local conversation TUI when
you attach to or start a local session. TUI snapshots use the tui-profile-
filename prefix and share the session’s profiling/ directory. Polytoken rotates
daemon and TUI snapshots independently, keeping the newest snapshots from each.
The TUI sampler starts before terminal setup and session hydration, after you
leave the session picker. When you quit the TUI, Polytoken writes a final TUI
snapshot after terminal teardown.
The profiling build is development-only. Normal and release builds do not start the sampler, open the console endpoints, or add the profiling libraries to the shipped binary.
Inspect the live task console
Section titled “Inspect the live task console”The profiling build exposes the daemon tokio-console server on
127.0.0.1:6669 and the local conversation TUI server on 127.0.0.1:6670.
Connect a compatible tokio-console client to either loopback address while the
matching daemon or TUI process runs. Each server keeps approximately 60 seconds
of task history. The console layer adds aggregation work to the runtime, so use
the console for diagnosis rather than routine operation.
Inspect a dump
Section titled “Inspect a dump”A .pb.gz file contains the standard pprof protobuf wrapped in gzip. Decompress
the file before passing it to a pprof-compatible viewer. For example:
gzip -dc "$DUMP" > profile.pbgo tool pprof -top profile.pbThe feedback attachment picker labels the newest CPU profile snapshot
CPU profile (pprof) and retrieves that snapshot through the daemon’s versioned
artifact catalog. The serving daemon must use a profiling build for the picker
to list a CPU profile snapshot. If the picker does not list a snapshot, restart
the daemon with the profiling build, then reopen the attachment picker.
Polytoken sends diagnostic attachments, including CPU profiles, raw and unsanitized. A profile captured on your machine can contain symbolized stack frames with build-machine paths and internal symbol names. Review the attachment before you send it. See Crash Reporting and Feedback for the full attachment policy.
To avoid common signal-safety risks, Polytoken excludes libc, libgcc, pthread, and vdso frames from profiles.
Expected overhead
Section titled “Expected overhead”The sampler runs at 99 Hz and normally contributes low single-digit CPU percentage overhead on a quiet development daemon. The task console adds aggregation cost that grows with task and span churn.
Polytoken briefly pauses sample collection while generating each profile report, so a small sampling gap can appear around each snapshot.
Each dump covers only the time since the previous dump, not the whole process history. Polytoken rebuilds the sampler after each periodic dump and discards samples that arrive while Polytoken encodes and writes the current dump. The brief sampling gap keeps the profiler’s own encoding work out of the next dump. At shutdown, Polytoken writes only the tail since the previous dump, which can be a very short interval.
Treat these figures as operational guidance, not a benchmark guarantee. Repeat measurements on the workload and platform that matter to the investigation.