Skip to content

Commit 85bada1

Browse files
committed
Fix failed samples calculation
1 parent 757ce0a commit 85bada1

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

Lib/profiling/sampling/collector.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class Collector(ABC):
1515
def collect(self, stack_frames):
1616
"""Collect profiling data from stack frames."""
1717

18+
def collect_failed_sample(self, exeption):
19+
"""Collect data about a failed sample attempt."""
20+
pass
21+
1822
@abstractmethod
1923
def export(self, filename):
2024
"""Export collected data to a file."""

Lib/profiling/sampling/live_collector.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def draw_efficiency_bar(self, line, width):
433433
self.add_str(line, col, "Efficiency:", curses.A_BOLD)
434434
col += 11
435435

436-
label = f" {success_pct:>5.1f}% good, {failed_pct:>4.1f}% failed"
436+
label = f" {success_pct:>5.2f}% good, {failed_pct:>4.2f}% failed"
437437
available_width = width - col - len(label) - 3
438438

439439
if available_width >= MIN_BAR_WIDTH:
@@ -1324,6 +1324,9 @@ def _process_frames(self, frames):
13241324
)
13251325
self.result[top_location]["direct_calls"] += 1
13261326

1327+
def collect_failed_sample(self, exeption):
1328+
self._failed_samples += 1
1329+
13271330
def collect(self, stack_frames):
13281331
"""Collect and display profiling data."""
13291332
if self.start_time is None:
@@ -1340,11 +1343,7 @@ def collect(self, stack_frames):
13401343
if frames:
13411344
got_frames = True
13421345

1343-
if got_frames:
1344-
self._successful_samples += 1
1345-
else:
1346-
self._failed_samples += 1
1347-
1346+
self._successful_samples += 1
13481347
self.total_samples += 1
13491348

13501349
# Handle input on every sample for instant responsiveness

Lib/profiling/sampling/sample.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ def sample(self, collector, duration_sec=10):
202202
except ProcessLookupError:
203203
duration_sec = current_time - start_time
204204
break
205-
except (RuntimeError, UnicodeDecodeError, MemoryError, OSError):
205+
except (RuntimeError, UnicodeDecodeError, MemoryError, OSError) as e:
206+
collector.collect_failed_sample(e)
206207
errors += 1
207208
except Exception as e:
208209
if not self._is_process_running():

0 commit comments

Comments
 (0)