Skip to content

LiveStatsCollector (Tachyon): reset_stats() does not clear aggregated opcode statistics #153293

Description

@lkk7

Bug report

Bug description:

In Tachyon profiler TUI, pressing r (reset) clears all collected stats except the aggregated opcode data.

That's because LiveStatsCollector.reset_stats() clears all results, per-thread data and all counters, but not self.opcode_stats.

It can be seen that with --opcodes, the opcode panel keeps running and incrementing the values while every other panel starts from zero.

Short repro with no TUI:

from types import SimpleNamespace
from profiling.sampling.live_collector import LiveStatsCollector

collector = LiveStatsCollector(1000, opcodes=True)
frame = SimpleNamespace(filename="t.py", location=5, funcname="f", opcode=83)
collector.process_frames([frame])
collector.reset_stats()

print(dict(collector.result)) # empty as expected
print(dict(collector.opcode_stats)) # should be empty but isn't: {('t.py', 5, 'f'): defaultdict(<class 'int'>, {83: 1})}

I think that reset_stats() (b338308) predates the opcode tracking (5b19c75) and it was accidentally skipped.

This should be a simple fix plus a test adjustment, I have it ready.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-profilingtype-bugAn unexpected behavior, bug, or error

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions