Skip to content

bootchart, svg: a quieter header that says what sampling cost - #7

Merged
aledbf merged 1 commit into
jsonfrom
header-overhead
Nov 22, 2026
Merged

aledbf merged 1 commit into
jsonfrom
header-overhead

Conversation

@aledbf

@aledbf aledbf commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Why

spin-stack/machine draws its boot with this fork to see how systemd starts inside a ~300-400 ms VM boot on one vCPU, and to catch regressions release to release. On one vCPU the sampler's own CPU time is time the boot did not get. Ubuntu's 235 took ~12 ms at 200 Hz, and the chart never said so. The header was also mostly a command line several hundred characters wide.

What

  • Cost, reported. The header says Sampler: X ms of CPU for N samples, Y us a sample, and the JSON carries sampler_cpu_ns. It is the sampler's CPU time (getrusage) up to the last sample, before drawing.
  • Cost, reduced. Every sample listed every process's task/ directory to add its threads' times. procfs counts a process's threads in that directory's link count (2 + threads), so a single-threaded process is now skipped after one fstatat instead of about six syscalls. Sampling this laptop's ~600 processes, one sample's CPU went from 6.0 and 6.4 ms to 5.3 and 5.4 ms. That is two interleaved runs of three each, a lead and not a VM number. A boot's processes are mostly single-threaded, so the saving there should be larger. The spin-stack/machine lab run measures it.
  • Its name. As PID 1's child, the sampler kept the comm the kernel gave init, and the chart listed it as "init" beside systemd. It now sets its comm to bootchart (PR_SET_NAME). spin-stack/machine finds the sampler by its executable, so that lookup does not change.
  • Header. The tables of top consumers sit 560 px apart, and the chart is at least as wide as they need. The CPU, unit and I/O tables of the earlier PRs overlapped at 400 px. The command line is cut to 150 characters and kept whole in an XML comment, with -- encoded. It is read through --proc, and a missing one leaves the line empty instead of failing the chart. "recorded N total" now counts the samples taken. It used to print the configured maximum.

Checked

tests/header runs over a fixture /proc with a ~300 character command line containing --. It asserts the header line Sampler: ... for 20 samples, a non-zero sampler_cpu_ns, the cut line, and the whole command line in the comment. tests/pressure still counts a two-threaded process's thread, so the link-count skip keeps processes with threads. make check passes under ASan/UBSan with gcc in an Ubuntu 24.04 container. CI covers clang.

Stacked on #6.

🤖 Generated with Claude Code

The sampler runs on the CPUs it charts, and on spin-stack/machine's one
vCPU its time is time the boot did not get: ~12 ms of CPU at 200 Hz.
The header now says what the samples cost, in total and per sample,
and the JSON carries it as sampler_cpu_ns. It is the sampler's own CPU
time up to the last sample, before drawing.

Every process's task directory was listed on every sample to add its
threads' times. procfs counts a process's threads in that directory's
link count, so a process with one thread is now skipped after a stat.
Sampling this laptop's ~600 processes, a sample's CPU went from 6.0 and
6.4 ms to 5.3 and 5.4 ms (two interleaved runs of three); a boot's
processes are mostly single-threaded, where the saving is larger.

As PID 1's child the sampler kept the name the kernel gave init, and
the chart listed it as "init" beside the systemd it forked from. It is
now "bootchart". The header's command line, a few hundred characters on
a VM, is cut to 150, and kept whole in a comment. It is read through
--proc, and a missing one leaves the line empty instead of failing the
chart. "recorded N total" counts the samples taken, not the most that
could have been. The tables of top consumers, which overlapped at
400 px apart once they carried wait and IO amounts, sit 560 px apart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aledbf
aledbf merged commit af58ee3 into json Nov 22, 2026
2 checks passed
@aledbf aledbf mentioned this pull request Nov 22, 2026
aledbf added a commit that referenced this pull request Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant