Skip to content

feat(callgrind): add CALLGRIND_REGISTER_DESC client request - #43

Open
lvaroqui wants to merge 1 commit into
masterfrom
cod-3722-ignore-process-spawning-overhead-in-exec-harness-simulation
Open

lvaroqui wants to merge 1 commit into
masterfrom
cod-3722-ignore-process-spawning-overhead-in-exec-harness-simulation

Conversation

@lvaroqui

@lvaroqui lvaroqui commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Add a CALLGRIND_REGISTER_DESC(desc) client request that attaches a desc: <desc> line to the header of the next dumped part, without dumping.

A client can currently only label a part through the trigger string of CALLGRIND_DUMP_STATS_AT, and every such call creates a part of its own. Here, lines are queued, written in every section of the next part (per thread under --separate-threads=yes), then cleared. This is the same lifecycle as the existing desc: Spawned pid: lines.

The first user is instrument-hooks. It declares the pid a benchmark ran in when that is not the dumping process, so a launcher's own cost can be told apart from the benchmark's:

part: 2
desc: Spawned pid: 289126
desc: Benchmark pid: 289126
desc: Trigger: Client Request: exec_harness::true_twice

Notes for review:

  • Line breaks in desc are written as spaces, so a client string cannot corrupt the header.
  • A fork child drops the lines its parent queued, like the spawned pids.
  • Lines queued after the last dump are lost on exit or exec.
  • Older valgrind builds don't know the request: they log Warning: unknown callgrind client request code and carry on.

Ships as 0codspeed8. instrument-hooks syncs callgrind.h from this repo's master, so this has to merge first.

Stacked on #44, which fixes the inline-crossfile failure on ubuntu-22.04 this change exposed: it was caused by the tool binary's layout, not by this change.

Closes COD-3722

@codspeed

codspeed Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 84 untouched benchmarks
⏩ 60 skipped benchmarks1


Comparing cod-3722-ignore-process-spawning-overhead-in-exec-harness-simulation (fa48853) with master (57010df)

Open in CodSpeed

Footnotes

  1. 60 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@lvaroqui
lvaroqui requested a review from not-matthias October 1, 2026 15:21
@lvaroqui
lvaroqui marked this pull request as ready for review October 1, 2026 15:21
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Adds a new client request to the profiler's public API.

The PR appears safe to merge; no outstanding finding or new actionable issue was identified.

Summary

The PR adds a client request that queues description lines for the next Callgrind dump, prints them in each emitted section, and clears them after the dump or in a fork child. It also adds single-thread and separate-thread regression tests.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[REGISTER_DESC] --> B[Queue sanitized line]
  B --> C[Next dump]
  C --> D[Write line in each emitted section]
  D --> E[Clear queue]
  B --> F[Fork child]
  F --> G[Child clears inherited queue]
Loading

Reviews (4) · Last reviewed commit: "test(callgrind): keep register_desc_thre..."

Comment thread callgrind/tests/register_desc.vgtest
@lvaroqui
lvaroqui force-pushed the cod-3722-ignore-process-spawning-overhead-in-exec-harness-simulation branch from 9e1c11d to 225e92a Compare October 1, 2026 15:55
@lvaroqui
lvaroqui changed the base branch from master to cod-3536-callgrind-inline-markers-cfni-depend-on-the-tool-binary October 1, 2026 15:55
@lvaroqui
lvaroqui added this pull request to stack #45 October 1, 2026 15:56
@lvaroqui
lvaroqui force-pushed the cod-3722-ignore-process-spawning-overhead-in-exec-harness-simulation branch from 225e92a to 8e61271 Compare October 2, 2026 08:34
Base automatically changed from cod-3536-callgrind-inline-markers-cfni-depend-on-the-tool-binary to master October 2, 2026 09:03
@lvaroqui
lvaroqui force-pushed the cod-3722-ignore-process-spawning-overhead-in-exec-harness-simulation branch from 7c0205b to bdc715e Compare October 2, 2026 09:03
Comment thread callgrind/tests/register_desc_threads.c
@lvaroqui
lvaroqui force-pushed the cod-3722-ignore-process-spawning-overhead-in-exec-harness-simulation branch from bdc715e to 83410fc Compare October 2, 2026 10:55
Comment thread callgrind/tests/register_desc_threads.c Outdated
Comment thread callgrind/tests/register_desc_threads.c Outdated

@not-matthias not-matthias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just very minor comments.

Comment thread callgrind/global.h Outdated
/* from dump.c */
void CLG_(init_dumps)(void);
/* Queue a "desc:" line for the header of the next dumped part. */
void CLG_(register_part_desc)(const HChar* desc);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe queue_desc might fit better. i associate "register" more with registering a callback. wdyt? 🤔

other options: dump_desc, emit_desc, add_desc, etc.

@lvaroqui lvaroqui Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, add_desc is probably the clearest name, I'll update

Comment thread callgrind/tests/register_desc_threads.c
A client had no way to attach information to a dump part other than the
trigger string of CALLGRIND_DUMP_STATS_AT, and every such dump creates
a part of its own.

CALLGRIND_REGISTER_DESC(desc) queues a "desc: <desc>" line for the
header of the next dumped part without dumping. Like the spawned pids,
the lines are written in every section of that part, then dropped. Line
breaks in desc are written as spaces so they cannot corrupt the header,
and a fork child drops the lines its parent queued for its own part.

Closes COD-3722
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lvaroqui
lvaroqui force-pushed the cod-3722-ignore-process-spawning-overhead-in-exec-harness-simulation branch from 2d88534 to fa48853 Compare October 2, 2026 15:05
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.

2 participants