Repository navigation
wcprof: report views, clients reporting their own work, and per-exec and per-session CPU - #14866
Merged
Merged
Conversation
sipsma
force-pushed
the
sipsma/wcprof-extension
branch
from
October 27, 2026 13:18
1d53d58 to
4dabb6a
Compare
…windows wcprof-report now reads each exec op's recorded command, and adds: - -label: a regexp over each exec's command whose first submatch labels the op and every ancestor whose labelled descendants all share that label, so a package's request, lazy evaluation and exec carry the package its compile script names; - the ancestors view: ops grouped by their class and the classes of up to -levels ancestors, to see where a class is called from; - the occupancy view: per class, or per label with -by label, how many ops were in progress over time (mean per bucket and peak), rather than how many started; - the window view: for one op over its interval or a -from/-to part of it, three named quantities per class: time on the critical chain, occupied wall time (the union of the class's ops), and self time summed across concurrent ops; - compare -by label, to compare two dumps package by package. Signed-off-by: Erik Sipsma <[email protected]>
…ngine-lab flags The window view's occupied and self totals now walk the op's whole subtree, since a descendant can outlive its parent (publication work started by a call that already returned), and say they cover the subtree while the critical chain also follows waits into shared work. Ops still open at dump time keep their recorded command, so they can be labelled. engine-lab's wcprofReport passes label, by, levels, from and to through to the helper and documents the new views; flag help and the compare heading follow. Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Clients and programs inside execs can report their own work to wcprof with OTel spans: tasks (a unit of their work, e.g. one package of a build) and task groups (a parent whose tasks run concurrently), each task's dependency waits as wait links (reason "dependency", written even when the dependency was already done), their limited resources (a "resource" span with a capacity and an admission policy) and each acquisition of one (an "acquire" span from request to release, with its priority, what the priority came from, when it was granted and its outcome), and a producer's count of the spans it reported. wcprof gains the op kinds task, task_group, resource and acquire and the wait reason dependency; telemetryattrs the wcprof.label, wcprof.producer, wcprof.resource.* and wcprof.producer.* attributes. The new engine/wcprof/contract package decodes a span under this contract, for the recorder and the offline analyzers alike. Signed-off-by: Erik Sipsma <[email protected]>
Spans that clients and programs inside execs report under the wcprof reporting contract reach the engine with the session's telemetry; the session span exporter now decodes them with engine/wcprof/contract and records them when the session is profiled. The recorder gives each reported span an op ID the first time it sees it (a span exported live and again at its end is recorded once, at its end) and keeps parents, wait targets and acquired resources as span references, resolved when the dump is written; one still missing then is dumped as an unresolved_span link. Resources and acquisitions are dumped as their own events, reported ops carry their label and producer, and the dump header lists each producer's received and declared span counts. serveQuery links its session op to the caller's span, so in the dump the engine work a reported task requested resolves to that task (a reported_cause link). Signed-off-by: Erik Sipsma <[email protected]>
A client a dagql call runs, such as a build tool inside the call's exec or the module the call invokes, gets the call's span as its traceparent, so what it reports to wcprof is parented to that span. The native dump had no op for that span, so those parents were dumped as unresolved_span links and the reported work floated free of the call that ran it. Each call op is now mapped to the span it begins under, and a reported op's parent resolves to it. When calls share a span (under a telemetry-suppressed caller), the outermost call keeps it. Signed-off-by: Erik Sipsma <[email protected]>
…p resource names - A live snapshot's unset end can arrive as a time before its start, as the session's span store already handles. It was recorded as ended, and the span's final export, with its real end and the links it gained, was then dropped as a repeat. Such a snapshot is now left for the final export. - A producer may report work with an existing op kind, e.g. its compile as exec work: a non-engine span carrying a producer ID is now recorded whatever its kind, instead of dropped. - A resource's display name is kept in its dump event. - Note that a flushing dump drops caller links it couldn't resolve. Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
When an exec is profiled (by wcprof or by OTel profile emission), the
engine reads two cgroups once the exec's work is done and records what
it used:
- container: the workload's own cgroup, read after its processes exit
and before the container is deleted (cleanups run in reverse, so the
read is registered right after the delete);
- exec_cgroup: the exec's resource cgroup, the workload and the mount
helpers beside it, read after the existing final resource sample.
Each reading is the cgroup's user and system CPU time and peak memory,
read with resources.ReadUsage. The recorder keeps readings apart from its
fixed-size events and dumps each as a usage event on the exec.run op ("e":
"usage", the scope as its class, cu/cs/mp for the values). The exec.run
OTel span carries the same readings as wcprof.usage.<scope>.* attributes.
Signed-off-by: Erik Sipsma <[email protected]>
… exec's cgroup; omit an unknown peak When a mount helper couldn't join the exec's cgroup, the resource cgroup's total leaves it out, so the exec_cgroup reading is skipped, as the resource sampler already skips that cgroup's samples; the container's own reading still counts. A peak memory that couldn't be read is left off the exec.run span instead of reported as zero. The tests read a fixture cgroup tree, so they see an unprofiled exec reading nothing. Signed-off-by: Erik Sipsma <[email protected]>
…r a session A profiled session is now an op in wcprof, "session" (kind session_phase, the session ID as its ident), from its initialization to the end of its removal. Its end carries the CPU the engine used meanwhile, as usage readings: the engine process itself, its child processes the engine reaped meanwhile (runc, and through it the containers it ran), and the engine's whole cgroup, as the engine's cgroup metrics find it. These are activity during the session, not CPU the session owned: sessions that overlap see each other's work. /debug/wcprof/profile?phase=session arms a CPU profile of the engine over the next session's life and returns it, in pprof's format, when that session ends. One profile can be armed at a time; a client that leaves before the session starts disarms it. Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
…under one lock - A session's phase now starts when the session is marked initialized, so a session that fails to initialize starts none, and no failure cleanup has to end one before the rest of the cleanup has run. - Arming, starting and disarming a CPU profile happen under one lock: a client leaving can't disarm a profile a session is starting, and a started profile stays armed until its session ends, so no other profile can arm and then fail to start meanwhile. It is still delivered to its request at the end. - Lint: the phase begins only as the session phase, and the profile write carries gosec's exemption for binary output. Signed-off-by: Erik Sipsma <[email protected]>
A request whose profile failed to start, then disarming, cleared whatever profile was armed, even one armed in its place since. It now clears only its own. Signed-off-by: Erik Sipsma <[email protected]>
…ainer cgroup The container reading existed to tell the workload's usage from the mount helpers' that run beside it in the exec's cgroup. It had to be read between the workload's exit and the container's delete, which a runtime that removes the container itself when its run returns doesn't leave. Read the helpers' own cgroup (the exec cgroup's sshfs child) instead, with the exec cgroup's reading after mount teardown, and only when a helper ran: the workload's usage is the exec cgroup's less the helpers'. Without a helper, the exec cgroup's reading is the workload's alone. When a helper couldn't join the exec's cgroup, neither reading would hold it, so neither is recorded. A separate workload memory peak is no longer read; the exec cgroup's peak bounds it. The usage scope "container" becomes "mount_helpers". Signed-off-by: Erik Sipsma <[email protected]>
A session's removal can take a second after its last query: on a cold build of dagger's CLI, the release of its dagql cache removes thousands of owner leases one by one, and the CLI waits for it through its telemetry streams. Profiles recorded nothing there. A profiled session's removal is now an op, "session.teardown", under the session's own op, with an op for each main step: stopping its services, draining its queries, releasing its cache (the dagql cache release and the wait for its client scopes), and shutting its telemetry down. They are native only, like the session's op: the session's telemetry is itself shut down during the removal. Signed-off-by: Erik Sipsma <[email protected]>
Profiles stopped at the call and lazy-op level, so what happened inside an operation (gathering files into a directory, an exec's cleanups after its process) took a patched engine to see. dagql.BeginStep records a step inside an operation, named <operation>.<step>, when the work under its context is profiled: an internal op in the native profile and, when the engine's telemetry records there too, an internal OTel span nested the same way. Work that isn't profiled records nothing and allocates nothing. The first steps: - gathering files into a directory (copyFiles, behind withFile and withFiles): evaluating the inputs, creating the snapshot, mounting it and copying (with each source's mount and copy), the usage, the commit and the release; - each cleanup an exec runs after its process, by its name, with a mount target left out so the names stay a bounded set. Cleanups now keep the name they were added with, and RunEach runs them through a wrapper that gets it. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
sipsma/wcprof-extension
branch
from
October 28, 2026 02:42
4dabb6a to
bd89642
Compare
grouville
self-requested a review
October 28, 2026 16:06
grouville
approved these changes
Oct 28, 2026
A profiled step was also an internal OTel span, and the UI hides everything under an internal span. withFiles.evalInputs evaluates lazy inputs under its step, so on a profiling engine an input's evaluation, an exec's output included, could disappear from the CLI. Steps are now recorded only as ops in wcprof's native profile; work under a step nests directly under the span the step began under. Signed-off-by: Erik Sipsma <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
wcprof, the engine's wall-clock profiler, could only see the engine's own work. Measuring where a cold Go build's time goes needed one-off scripts, patched engines and instrumented builds. This PR adds what those were standing in for, in four parts.
What changes for users
Almost nothing, apart from one small addition to every exec in normal use. Whenever telemetry is on, each exec now reads its cgroup's CPU time and peak memory once its work is done: two small cgroup files, which the engine's resource sampler already reads for every exec, and two more when the exec ran a mount helper. Its
exec.runspan gets up to sixwcprof.usage.*attributes. I haven't measured the time this adds; it runs on a path that has just started and stopped a container. Each exec also keeps its cleanups' names, a few small allocations.Everything else only runs when the engine is profiling, or when a CPU profile has been armed through the debug endpoint.
Report views (engine-lab wcprof-report)
wcprof-report gains views for questions that so far needed scripts:
-label REGEXP: labels each exec by a submatch of its command, and carries the label up to the ancestors whose labelled descendants all share it. For example, a Go build's request, lazy evaluation and exec ops then carry their package's name.-view ancestors: ops grouped by their class and the classes of up to N ancestors, to see where a class is called from.-view occupancy: per class or per label, how many ops were in progress over time (mean per bucket and peak), rather than how many started.-view window: for one op, over its interval or part of it, three quantities per class: time on the critical chain, occupied wall time, and self time summed across concurrent ops.-view compare -by label: two dumps compared label by label, e.g. package by package.On a real build with 1,412 packages, the per-package numbers match the script they replace within 0.03 ms on average.
Clients reporting their own work
A program inside an exec, or a module, can now report its own units of work with plain OTel spans and links, extending the
wcprof.*attributes engine spans already use:wcprof.label) and tagged with a producer ID (wcprof.producer);dependency;resourcespan with a capacity and an admission policy), and each acquisition of one unit (anacquirespan from request to release, with its priority, the inputs the priority came from, when it was granted and its outcome);engine/wcprof/contractis the one decoder of this contract. When a session is profiled, its span exporter records reported spans in wcprof's native dump. Each span is recorded once; live snapshots wait for the final export. References between spans resolve when the dump is written, and anything still missing is dumped asunresolved_span.Work a client reports from inside a dagql call's exec or module is attached to that call. A query made under a reported task links its engine work to the task.
One limit: a dump that flushes the recorder while a client is mid-task loses that client's links to the queries it made. Dumps taken after the clients finish are complete.
Each exec's CPU and memory, and the engine's CPU per session
exec_cgroup). When a mount helper ran, the helpers' own cgroup inside it is read too (mount_helpers), so the workload's usage is the first less the second; without one, the first is the workload's alone. Nothing is read between the workload's exit and the container's removal, so this works whether or not the runtime removes the container itself. The readings go into wcprof asusageevents on theexec.runop, and onto its span.session, from the end of its initialization to the end of its removal. It carries the CPU the engine used meanwhile: the engine process, its reaped child processes, and its cgroup. These are activity during the session, not CPU the session owned. Its removal is an op too,session.teardown, with an op for each main step: stopping its services, draining its queries, releasing its cache, and shutting its telemetry down. On a cold build, releasing the cache can take a second after the last query while the client waits; these ops show it. Like the session's op, they are only in the engine's native profile, since the session's telemetry is itself shut down during the removal./debug/wcprof/profile?phase=sessionarms a CPU profile of the engine over the next session, and returns it in pprof's format when that session ends.Checked on real builds
Steps inside engine operations
dagql.BeginSteprecords a step inside an engine operation, named<operation>.<step>, when the work under its context is profiled, as an internal op in the native profile only. It's never an OTel span: the UI hides everything under an internal span, and a step can run user-facing work, such as evaluating a lazy input and its exec. Work that isn't profiled records nothing; the helper allocates nothing then. The first steps:copyFiles, behindwithFileandwithFiles): evaluating the inputs, creating the snapshot, mounting it and copying (each source's mount and copy), the usage, the commit and the release;exec.cleanup.<name>, with a mount target left out of the name. Cleanups now keep the names they were added with (a few small allocations per exec), andRunEachruns them through a wrapper that gets it.Tests
engine/wcprof,engine/wcprof/contract,engine/server,engine/engineutil,engine/engineutil/resourcesanddagql. They run in the "Package tests outside core/integration" check, with the race detector.wcprof-report-testcheck.