]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-153293: Clear opcode statistics in the live profiler's reset_stats() (#153295)
authorŁukasz <lukaszlapinski7@gmail.com>
Sat, 11 Jul 2026 17:44:31 +0000 (19:44 +0200)
committerGitHub <noreply@github.com>
Sat, 11 Jul 2026 17:44:31 +0000 (18:44 +0100)
Lib/profiling/sampling/live_collector/collector.py
Lib/test/test_profiling/test_sampling_profiler/test_live_collector_interaction.py
Misc/NEWS.d/next/Library/2026-07-07-22-06-52.gh-issue-153293.0DvYdc.rst [new file with mode: 0644]

index 2805134f239eb38eb57cfeeec0e9620761c77f9e..553c856c6f8c56288a0db0962a8d4473f494ba5d 100644 (file)
@@ -702,6 +702,7 @@ class LiveStatsCollector(Collector):
     def reset_stats(self):
         """Reset all collected statistics."""
         self.result.clear()
+        self.opcode_stats.clear()
         self.per_thread_data.clear()
         self.thread_ids.clear()
         self.view_mode = "ALL"
index baf478133fc66591813b479a50c7eda9bc80f140..6dfdb9a192e03a1a322c11fb48d40e48101d9b13 100644 (file)
@@ -99,6 +99,7 @@ class TestLiveCollectorInteractiveControls(unittest.TestCase):
             "cumulative_calls": 75,
             "total_rec_calls": 0,
         }
+        self.collector.opcode_stats[("test.py", 1, "func")][100] = 5
 
         # Reset
         self.collector.reset_stats()
@@ -107,6 +108,7 @@ class TestLiveCollectorInteractiveControls(unittest.TestCase):
         self.assertEqual(self.collector.successful_samples, 0)
         self.assertEqual(self.collector.failed_samples, 0)
         self.assertEqual(len(self.collector.result), 0)
+        self.assertEqual(len(self.collector.opcode_stats), 0)
 
     def test_increase_refresh_rate(self):
         """Test increasing refresh rate (faster updates)."""
diff --git a/Misc/NEWS.d/next/Library/2026-07-07-22-06-52.gh-issue-153293.0DvYdc.rst b/Misc/NEWS.d/next/Library/2026-07-07-22-06-52.gh-issue-153293.0DvYdc.rst
new file mode 100644 (file)
index 0000000..ac358bb
--- /dev/null
@@ -0,0 +1,2 @@
+Fix the live sampling profiler TUI keeping stale aggregated opcode
+statistics after a stats reset.