From af23eeda63797b3762cd6529bdc7825178fda14c Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 15 Nov 2026 20:23:52 -0400 Subject: [PATCH] diag: accel_attribution's holder renderer crashed on the first real log The merged reader indexed e['ticket'] in the "holders seen" block, but holder_table() builds `spans`, not `ticket` -- the key was dropped when the table grew span tracking, and nothing rendered the block in the self-test, so it only ever ran on fixtures that did not reach it. On 2 h of live samples (3 578 rows) it raised KeyError on the first holder and printed no holders at all, which is the one section a reader of this tool opens first. - the renderer is now render_holders(), so the self-test can drive it; - it prints the LAST span's ticket, which is what the process was relabelled with; - the self-test renders a leaky holder and asserts the last ticket appears and the first does not. Reverting the line to e['ticket'] makes the self-test raise KeyError, so the arm bites. --- tools/diag/accel_attribution.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tools/diag/accel_attribution.py b/tools/diag/accel_attribution.py index e975c3d9f..3685ed940 100755 --- a/tools/diag/accel_attribution.py +++ b/tools/diag/accel_attribution.py @@ -190,6 +190,14 @@ def self_test(): assert [p for p, _ in spans_ticket_boundaries(lt)] == ["111"], spans_ticket_boundaries(lt) assert spans_ticket_boundaries(holder_table(samples)) == [], "the plain fixture must not trip the arm" + # THE RENDERER, not only the analysis (engine#2542): the "holders seen" line read a `ticket` key that + # holder_table() stopped building when it grew `spans`, so the merged tool raised KeyError on the first real log + # (3,500+ samples) and had only ever run on fixtures where that line was not reached. Rendering is asserted here + # because a reader that crashes on real data is not a reader. + rendered = render_holders(holder_table(leaky)) + assert "gpu-hold cl-b 2" in rendered, rendered # the LAST span: what the process was relabelled with + assert "cl-a" not in rendered, rendered + # A partially written row must not kill the reader. import tempfile with tempfile.NamedTemporaryFile("w", suffix=".log", delete=False) as f: @@ -203,6 +211,17 @@ def self_test(): print("accel_attribution self-test: ok") +def render_holders(t): + """The "holders seen" block. A separate function so the self-test can drive it: this line read a `ticket` key + that holder_table() stopped building when it grew `spans`, and the crash only appeared on the first real log.""" + out = [] + for pid, e in sorted(t.items(), key=lambda kv: -kv[1]["n"]): + last = e["spans"][-1][0] if e["spans"] else "-" # the LAST span: what the process was relabelled with + out.append(f" {pid:<9} {e['first']}..{e['last']} ({e['last'] - e['first']:>5}s) n={e['n']:<4} " + f"{e['cmd'][:46]} {last[:30]}") + return "\n".join(out) + + def main(): ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) ap.add_argument("--dir", default=os.path.expanduser("~/.cache/accel-sampler")) @@ -244,9 +263,7 @@ def main(): print(f" {a}..{b} ({b - a:>4}s) {tk[:46]}") if t: print("\nholders seen (pid, first..last, samples, ticket):") - for pid, e in sorted(t.items(), key=lambda kv: -kv[1]["n"]): - print(f" {pid:<9} {e['first']}..{e['last']} ({e['last'] - e['first']:>5}s) n={e['n']:<4} " - f"{e['cmd'][:46]} {e['ticket'].rstrip()[:30]}") + print(render_holders(t)) print(f"\nattributions: {len(attrs)}") for line in explain(samples, attrs, args.window):