Skip to content

Commit bce13f7

Browse files
committed
Fix failed samples calculation
1 parent a96122e commit bce13f7

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

Lib/profiling/sampling/collector.py

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

21+
def collect_failed_sample(self, exeption):
22+
"""Collect data about a failed sample attempt."""
23+
pass
24+
2125
@abstractmethod
2226
def export(self, filename):
2327
"""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
@@ -199,7 +199,8 @@ def sample(self, collector, duration_sec=10):
199199
except ProcessLookupError:
200200
duration_sec = current_time - start_time
201201
break
202-
except (RuntimeError, UnicodeDecodeError, MemoryError, OSError):
202+
except (RuntimeError, UnicodeDecodeError, MemoryError, OSError) as e:
203+
collector.collect_failed_sample(e)
203204
errors += 1
204205
except Exception as e:
205206
if not self._is_process_running():

0 commit comments

Comments
 (0)