Skip to content

fix(valgrind): use %p in log file path to avoid multi-process overwrite#381

Merged
not-matthias merged 1 commit into
mainfrom
cod-2747-multi-process-valgrind-logs-can-overwrite-log-file
Jun 10, 2026
Merged

fix(valgrind): use %p in log file path to avoid multi-process overwrite#381
not-matthias merged 1 commit into
mainfrom
cod-2747-multi-process-valgrind-logs-can-overwrite-log-file

Conversation

@not-matthias

Copy link
Copy Markdown
Member

What?

With --trace-children=yes, every (forked) process wrote to the same valgrind.log file, so the last writer won and earlier processes' logs were lost.

This uses the %p (PID) placeholder in --log-file so each process gets its own valgrind.<pid>.log, matching the existing %p.out (callgrind) and %p.tgtrace (tracegrind) out-file patterns.

Also drops the failure-path read of the now-nonexistent hardcoded valgrind.log.

Closes COD-2747

@not-matthias not-matthias marked this pull request as ready for review May 29, 2026 16:10
@codspeed-hq

codspeed-hq Bot commented May 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 7 untouched benchmarks


Comparing cod-2747-multi-process-valgrind-logs-can-overwrite-log-file (b1c5547) with main (bd8f33e)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented May 29, 2026

Copy link
Copy Markdown

Greptile Summary

Fixes a multi-process log overwrite bug introduced by --trace-children=yes by replacing the hardcoded valgrind.log path with a %p-keyed pattern, consistent with the existing %p.out and %p.tgtrace out-file conventions. A helper dump_valgrind_logs is added to glob and emit all per-process log files when valgrind exits non-zero.

  • log_path changed from valgrind.log to valgrind.%p.log, so each child process writes to its own file instead of overwriting a shared file.
  • dump_valgrind_logs iterates the profile folder on failure, filters files matching valgrind.*.log, and emits their contents via debug!, guarded by a log_enabled! check to avoid unnecessary I/O when debug logging is off.

Confidence Score: 5/5

Safe to merge — the change is a targeted, low-risk fix that aligns the log-file naming convention with the existing out-file patterns.

The %p substitution is the established valgrind idiom already used for --callgrind-out-file and --tracegrind-out-file in the same function, so the fix is both correct and idiomatic. The dump_valgrind_logs helper is well-guarded (early return when debug logging is off, silent skip on unreadable entries) and introduces no new failure modes. No regressions were found in the changed path.

No files require special attention.

Important Files Changed

Filename Overview
src/executor/valgrind/measure.rs Core fix using %p PID placeholder in --log-file path; adds dump_valgrind_logs helper that safely handles missing/unreadable files and is correctly gated by log_enabled!.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[measure called] --> B[build valgrind cmd\n--log-file=.../valgrind.%p.log]
    B --> C[run_command_with_log_pipe]
    C --> D{valgrind exit\nsuccess?}
    D -- yes --> E{cmd_status == 0?}
    E -- yes --> F[return Ok]
    E -- no --> G[bail: benchmark failed]
    D -- no --> H[dump_valgrind_logs\nprofile_folder]
    H --> I{log::debug\nenabled?}
    I -- no --> J[return early\nno I/O]
    I -- yes --> K[read_dir profile_folder]
    K --> L[for each valgrind.*.log]
    L --> M[debug! file contents]
    M --> N[bail: failed to execute valgrind]
Loading

Reviews (5): Last reviewed commit: "fix(valgrind): use %p in log file path t..." | Re-trigger Greptile

Comment thread src/executor/valgrind/measure.rs

@GuillaumeLagrange GuillaumeLagrange left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

olgtm

Comment thread src/executor/valgrind/measure.rs Outdated
Comment thread src/executor/valgrind/measure.rs Outdated
Comment thread src/executor/valgrind/measure.rs Outdated
@not-matthias not-matthias force-pushed the cod-2747-multi-process-valgrind-logs-can-overwrite-log-file branch from ce58003 to 31e39a0 Compare June 10, 2026 12:18
Each (potentially forked) process now writes to its own valgrind.<pid>.log
instead of clobbering a shared log file. On failure, dump these per-process
logs via a dump_valgrind_logs helper when debug logging is enabled.
@not-matthias not-matthias force-pushed the cod-2747-multi-process-valgrind-logs-can-overwrite-log-file branch from 31e39a0 to b1c5547 Compare June 10, 2026 12:26
@not-matthias not-matthias merged commit b1c5547 into main Jun 10, 2026
21 checks passed
@not-matthias not-matthias deleted the cod-2747-multi-process-valgrind-logs-can-overwrite-log-file branch June 10, 2026 13:09
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