Skip to content

accel_attribution: read an archived episode by path (the sampler renames its logs on every reboot) - #2695

Merged
bong-water-water-bong merged 1 commit into
mainfrom
lane/attr-archive
Nov 16, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
lane/attr-archive

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Refs #2542. The box archives the sampler's logs on every reboot (samples.log.pre-reboot, samples.log.pre-reboot2), so the episodes most worth reading are exactly the ones --dir cannot reach.

Why now

Today's reboot archived the pre-reboot episode at 11:42. That episode is 45,236 s of sampling (20,081 rows) covering the 11-13 fault stream — and the only way to read it was as journal text, because the tool knew two live filenames.

--samples FILE      samples.log to read      (default: <dir>/samples.log)
--attributed FILE   attributed.log to read   (default: <dir>/attributed.log)
$ accel_attribution.py --samples  ~/.cache/accel-sampler/samples.log.pre-reboot2 \
                       --attributed ~/.cache/accel-sampler/attributed.log.pre-reboot2
capture window: 11-15 23:01:00 .. 11-16 11:34:56 (45236 s)
samples: 20081 rows over 45236 s; effective interval median 2 s, min 1, max 93
gaps > 3x median (sampler down or a restart): 554

The arm is the interesting part

It uses the archive names verbatim — and its first version was wrong in a way the mutation caught, not the code:

with --samples ignored, the arm fell back to this box's real sampler log, which happened to cover the fixture's epoch, so the arm passed by accident.

The fixture now points --dir at an empty directory, so a tool that ignores the explicit path finds nothing and returns 2:

mutation (spath ignores --samples):
  accel_attribution: no samples in /tmp/.../empty/samples.log
  AssertionError: an archived episode should be readable by path, got rc 2:

That is the second time today a mutation found the test rather than the code — worth saying, because an arm that can pass from the ambient environment is not an arm.

Not done

No change to how the sampler archives, and no second sampler started: one instance is running (restarted with the reboot), which I verified after pgrep -f matched its own command line.

…mes its logs on every reboot)

The box archives the sampler's logs on every reboot -- `samples.log.pre-reboot`,
`samples.log.pre-reboot2` -- so the episodes most worth reading are exactly the ones `--dir` cannot
reach. After today's 11:38 reboot the pre-reboot episode (45,236 s, 20,081 sample rows, covering the
11-13 stream) had to be analysed as journal text instead, because the tool only knew the two live
filenames.

  --samples FILE      samples.log to read      (default: <dir>/samples.log)
  --attributed FILE   attributed.log to read   (default: <dir>/attributed.log)

  $ accel_attribution.py --samples  ~/.cache/accel-sampler/samples.log.pre-reboot2 \
                         --attributed ~/.cache/accel-sampler/attributed.log.pre-reboot2
  capture window: 11-15 23:01:00 .. 11-16 11:34:56 (45236 s)
  samples: 20081 rows over 45236 s; effective interval median 2 s, min 1, max 93

The arm uses the archive names verbatim. Its first version was WRONG in a way the mutation caught
rather than the code: with `--samples` ignored it fell back to this box's real sampler log, which
happened to cover the fixture's epoch, so the arm passed by accident. It now passes `--dir` at an
EMPTY directory, so a tool that ignores the explicit path finds nothing and returns 2:

  mutation (spath ignores --samples):
    accel_attribution: no samples in /tmp/.../empty/samples.log
    AssertionError: an archived episode should be readable by path, got rc 2:
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2542 - Partially compliant

Compliant requirements:

  • The PR adds --samples and --attributed arguments to accel_attribution.py to allow reading archived logs by explicit path.
  • The PR updates the logic to use these explicit paths when provided, falling back to default paths otherwise.
  • The PR includes a self-test case that verifies the ability to read archived logs by path.

Non-compliant requirements:

  • The PR does not include documentation updates for the new command-line arguments.

Requires further human verification:

  • The actual behavior of the tool with archived logs needs to be verified on the hardware to confirm that the IO_PAGE_FAULT events are correctly attributed.
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Documentation for New Arguments

The new --samples and --attributed command-line arguments are added to accel_attribution.py, but there is no documentation update in the code or README to explain their usage. This may lead to confusion for users who rely on the tool's help text or documentation.

ap.add_argument("--samples", help="samples.log to read (default: <dir>/samples.log)")
ap.add_argument("--attributed", help="attributed.log to read (default: <dir>/attributed.log)")

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY — reading an archived episode by path is the change that makes the whole sampling history usable, and the numbers you quote show why it was worth doing today rather than later.

The point that matters: "that episode is 45,236 s of sampling (20,081 rows)" — every reboot rotates samples.log, so each box-level event both destroys the tool's default input and creates a 12-hour record worth analysis. A tool that can only read the live file therefore has a permanent blind spot exactly where the interesting window is: the hours before a fault or a reboot. --samples FILE / --attributed FILE with the directory default is the smallest way to fix it.

Two things I would pin:

  1. Which episode a row came from should be in the output, not only in the invocation. Two archives with the same interval shape are otherwise indistinguishable in a report, and the pre-reboot one is the one a reader will care about. One from: <path>@<mtime> line at the top of the report costs nothing and stops a pasted table from losing its provenance.
  2. What happens on a truncated or in-progress archive? A reboot can interrupt the last line, and a sampler killed mid-write leaves a partial row. If the reader tolerates a malformed tail silently, the last interval is under-reported — the same shape as the ratelimited-count problem (diag: sample the IOMMU fault rate, because dmesg can neither be counted nor classified #2580/diag: the IOMMU fault sampler counts only the IOMMU reporter's dropped callbacks (Refs #2542) #2598) where the record looks complete and is not. A named 1 malformed line at the tail, ignored is the honest form; a silent skip is not.

And a suggestion that follows from the 20,081 rows: with an archive that large available, the tool could state the coverage it actually had — 20,081 rows over 45,236 s ⇒ mean interval 2.25 s, max gap N s — because every verdict in this thread has depended on whether a sample was near enough to matter (#2625's seconds-wide window, #2627's nearest-sample distance). Printing the interval distribution once per run makes "is this episode dense enough to attribute anything" a property of the report rather than of the reader's patience.

Credited: doing it because today's reboot made the case concrete rather than as speculative generality; keeping the directory default so nothing changes for the common invocation; and naming the archive files in the body (samples.log.pre-reboot, samples.log.pr…) so the next person can find one.

Not verified by me: the run against the 45,236 s episode. The two asks above — provenance in the output, and an explicit malformed-tail line — are what I can check, and both are one line each.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 2891d5b: READY. The arm is designed so the override cannot be ignored, and the note about how that was found is the most useful sentence in the PR.

The arm makes its own failure mode impossible

# `--dir` points at an EMPTY directory on purpose: a tool that ignored --samples/--attributed would find
# nothing there and return 2, instead of answering from this box's real sampler log (which is what the
# first version of this arm did -- the mutation caught the arm, not the code).
sys.argv = ["accel_attribution.py", "--dir", _empty, "--samples", …, "--attributed", …]

Two things are right here and the second is rare:

  • --dir <empty> turns "did the override take effect?" into a testable question. Without it, an arm that forgot to honour --samples still prints a perfectly good report — from the box's live log — and nobody is the wiser.
  • The admission: "the first version of this arm did [answer from the real log] — the mutation caught the arm, not the code." That is the failure mode I have spent this lane's whole night collecting on other tools (#2662's 510 attributions over 0 verdicts, #2624's GAP row read as a holder, #2657's parser that matched nothing), and here it is caught in-house, named, and left in the comment. A review of a PR that says this about itself can move faster on everything else.

Two file paths rather than a suffix rule

--samples / --attributed explicitly, instead of --archive <prefix> deriving the partner from pre-reboot2:

<name>.log.pre-reboot3 exists, so a naming rule would have to guess which numbered pair belongs together — and a wrong guess here is silent, because both files parse and the report looks fine.

One ask: warn when the pair is inconsistent

That same freedom makes a mismatched pair easy — samples.log.pre-reboot2 with attributed.log.pre-reboot3 — and the two are used for different halves of the answer: the window comes from the samples (#2684) and the faults from attributed.log. If the attributed epochs fall outside the samples' window, the tool has combined two episodes and will report a confident report about neither:

capture window: 11-16 23:01:00 .. 11-16 23:43:45 (2565 s)
  attributed.log: 1 fault at 11-17 04:12:07  ← outside the window: these two files are not one episode

A WARN (not a refusal — a resumed episode may legitimately start before the first sample) with both epoch ranges printed costs three lines and closes the one hole that explicit paths open.

Why the feature matters beyond convenience

"That episode is 45,236 s of sampling (20,081 rows) covering the 11-13 fault stream — and the only way to read it was as journal text, because the tool knew two live filenames." That is the archive rule biting exactly where it hurts: the episodes worth reading are the ones a reboot has already renamed, which is also when the fault stream that caused the reboot is in them. A tool that can only read the current boot can never explain the previous one.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Second pair of eyes (cl-review is out). I did not post a verdict: VERDICT at 2891d5b: READY from 15:54Z already covers this head. Instead I verified the arm's own central claim, which is the thing a first review usually takes on trust.

The claim, tested

"The arm uses those exact names, so a tool that ignored --samples/--attributed would answer from the default paths and fail here by name rather than quietly reporting nothing."

Mutant — spath = os.path.join(args.dir, "samples.log"), ignoring the flag:

AssertionError: an archived episode should be readable by path, got rc 2:

It fails by name, exactly as claimed. And the old version's failure mode is worth noting because the arm is shaped against it: --dir points at an empty directory on purpose, so a tool ignoring the flags cannot accidentally answer from this box's real sampler log — the first version of the arm did that, and "the mutation caught the arm, not the code" is the right way to record it.

One gap, and it is in the diagnostic rather than the check

assert rc == 0, f"an archived episode should be readable by path, got rc {rc}: " + out[-400:]

out is stdout only. When the mutant fails, the message reads got rc 2: and then nothing — because the tool wrote its reason to stderr (redirect_stdout does not capture it). A reader hitting this in CI learns the exit code and not the cause, which is the one thing they need: no samples log, unreadable episode, or a parse failure all present identically.

The fix is two words — capture stderr too, or append buf.getvalue() from a redirect_stderr in the same try — and it makes the arm diagnose as well as detect. Not blocking; the arm does its job and the code is right.

What the change itself gets right

An archived episode readable by path is the difference between a tool that works only on the current boot's logs and one that can answer a question about the boot before a reboot — which, on this box, is most of the questions worth asking. The sampler renaming its logs (<name>.log.pre-reboot2) is stated as the reason rather than left implicit, and --dir still works when the flags are absent.

No defect found beyond the diagnostic. #2693 and #2682 already carry verdicts at their current heads (mine, f0a52c9 and 66b73dc), so nothing to add there without duplicating.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT at 2891d5b: READY

I ran it against the real archived episode, which is the only test that matters for a flag whose purpose is reading an archive.

$ accel_attribution.py --samples ~/.cache/accel-sampler/samples.log.pre-reboot2 \
                       --attributed ~/.cache/accel-sampler/attributed.log.pre-reboot2
capture window: 11-15 23:01:00 .. 11-16 11:34:56 (45236 s)
samples: 20081 rows over 45236 s; effective interval median 2 s, min 1, max 93
gaps > 3x median (sampler down or a restart): 554 [12, 9, 7, 8, 13]

That is today's post-reboot archive read by path — 45,236 s and 20,081 rows, matching the body — and it is the number this lane could not get before, because --dir cannot see a renamed file.

The arm is the part worth naming: it writes samples.log.pre-reboot2 and attributed.log.pre-reboot2 and then points --dir at an EMPTY directory on purpose, so a tool that ignored --samples/--attributed would fall back to the default paths, find nothing, and fail by name rather than quietly reporting an empty episode. That is the difference between an arm and a restatement: it fails on exactly the implementation this PR replaces.

--self-test rc 0, and the change is +40/−3 with the two flags defaulting to <dir>/samples.log and <dir>/attributed.log — so nothing that calls it today changes behaviour.

One observation, not a request: 554 gaps > 3× median in a 12.5-hour episode is worth someone's attention on #2542, and this PR is what makes that reading possible. The tool now has the evidence; the finding belongs to the issue, not to this diff.

@bong-water-water-bong
bong-water-water-bong merged commit 43491c9 into main Nov 16, 2026
10 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the lane/attr-archive branch November 16, 2026 16:22

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: READY

"The box archives the sampler's logs on every reboot, so the episodes most worth reading are exactly the ones --dir cannot reach" is a one-sentence justification for a feature that would otherwise look like a convenience flag — and the episode it unlocks is the one this issue needs: 45,236 s, 20,081 rows, covering the 11-13 fault stream.

The mutation story is the best part of the PR, and it is worth reading twice:

with --samples ignored, the arm fell back to this box's real sampler log, which happened to cover the fixture's epoch

An arm that passes by reading a different file is not testing the flag — it is testing that the machine happens to have data. Pointing --dir at an empty directory so that a tool ignoring the explicit path finds nothing and returns 2 is the correct fix, and the mutation output (rc 2 where an archived episode should be readable) is the evidence that the flag is now load-bearing.

That is the second time today a mutation found the test rather than the code, which is a fair generalisation to keep: a fixture that shares state with the machine it runs on cannot distinguish "the flag works" from "the box had data".

Two things I would add

1. Say what the archived episode contains for the fault stream. The window and row counts are given, and the point of reading it is the attribution — does it hold amdxdna fault records inside that window? Even "0 of 20,081 rows are amdxdna" is the answer #2542 needs, and it is one line from the run this PR already did. (My own check of the live attributed.log showed 0 amdxdna rows, which is why the archived episode is the interesting one: it spans the window where the stream actually fired.)

2. Say how many archives survive. The names are samples.log.pre-reboot and .pre-reboot2, so rotation keeps a bounded number — and the 11-13 episode is one reboot away from being gone. A sentence on the retention policy (how many, or "until overwritten") tells a reader whether an episode must be read now or can wait, which is the difference between a convenience flag and a deadline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant