Skip to content

Commit e90e7c8

Browse files
pablogsalStanFromIreland
authored andcommitted
pythongh-141645: Refactor tachyon's live TUI tests to not use private fields (python#141806)
1 parent 3d5d18e commit e90e7c8

File tree

6 files changed

+142
-142
lines changed

6 files changed

+142
-142
lines changed

Lib/data.bin

12 KB
Binary file not shown.

Lib/profiling/sampling/live_collector/collector.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,20 @@ def __init__(
137137
self._saved_stderr = None
138138
self._devnull = None
139139
self._last_display_update = None
140-
self._max_sample_rate = 0 # Track maximum sample rate seen
141-
self._successful_samples = 0 # Track samples that captured frames
142-
self._failed_samples = 0 # Track samples that failed to capture frames
143-
self._display_update_interval = DISPLAY_UPDATE_INTERVAL # Instance variable for display refresh rate
140+
self.max_sample_rate = 0 # Track maximum sample rate seen
141+
self.successful_samples = 0 # Track samples that captured frames
142+
self.failed_samples = 0 # Track samples that failed to capture frames
143+
self.display_update_interval = DISPLAY_UPDATE_INTERVAL # Instance variable for display refresh rate
144144

145145
# Thread status statistics (bit flags)
146-
self._thread_status_counts = {
146+
self.thread_status_counts = {
147147
"has_gil": 0,
148148
"on_cpu": 0,
149149
"gil_requested": 0,
150150
"unknown": 0,
151151
"total": 0, # Total thread count across all samples
152152
}
153-
self._gc_frame_samples = 0 # Track samples with GC frames
153+
self.gc_frame_samples = 0 # Track samples with GC frames
154154

155155
# Interactive controls state
156156
self.paused = False # Pause UI updates (profiling continues)
@@ -174,10 +174,10 @@ def __init__(
174174
self._path_prefixes = self._get_common_path_prefixes()
175175

176176
# Widgets (initialized when display is available)
177-
self._header_widget = None
178-
self._table_widget = None
179-
self._footer_widget = None
180-
self._help_widget = None
177+
self.header_widget = None
178+
self.table_widget = None
179+
self.footer_widget = None
180+
self.help_widget = None
181181

182182
# Color mode
183183
self._can_colorize = _colorize.can_colorize()
@@ -256,7 +256,7 @@ def _get_common_path_prefixes(self):
256256

257257
return prefixes
258258

259-
def _simplify_path(self, filepath):
259+
def simplify_path(self, filepath):
260260
"""Simplify a file path by removing common prefixes."""
261261
# Try to match against known prefixes
262262
for prefix_path in self._path_prefixes:
@@ -268,7 +268,7 @@ def _simplify_path(self, filepath):
268268
# If no match, return the original path
269269
return filepath
270270

271-
def _process_frames(self, frames, thread_id=None):
271+
def process_frames(self, frames, thread_id=None):
272272
"""Process a single thread's frame stack.
273273
274274
Args:
@@ -295,7 +295,7 @@ def _process_frames(self, frames, thread_id=None):
295295
thread_data.result[top_location]["direct_calls"] += 1
296296

297297
def collect_failed_sample(self):
298-
self._failed_samples += 1
298+
self.failed_samples += 1
299299
self.total_samples += 1
300300

301301
def collect(self, stack_frames):
@@ -349,7 +349,7 @@ def collect(self, stack_frames):
349349

350350
frames = getattr(thread_info, "frame_info", None)
351351
if frames:
352-
self._process_frames(frames, thread_id=thread_id)
352+
self.process_frames(frames, thread_id=thread_id)
353353

354354
# Track thread IDs only for threads that actually have samples
355355
if (
@@ -375,12 +375,12 @@ def collect(self, stack_frames):
375375

376376
# Update cumulative thread status counts
377377
for key, count in temp_status_counts.items():
378-
self._thread_status_counts[key] += count
378+
self.thread_status_counts[key] += count
379379

380380
if has_gc_frame:
381-
self._gc_frame_samples += 1
381+
self.gc_frame_samples += 1
382382

383-
self._successful_samples += 1
383+
self.successful_samples += 1
384384
self.total_samples += 1
385385

386386
# Handle input on every sample for instant responsiveness
@@ -393,15 +393,15 @@ def collect(self, stack_frames):
393393
if (
394394
self._last_display_update is None
395395
or (current_time - self._last_display_update)
396-
>= self._display_update_interval
396+
>= self.display_update_interval
397397
):
398398
self._update_display()
399399
self._last_display_update = current_time
400400

401401
def _prepare_display_data(self, height):
402402
"""Prepare data for display rendering."""
403403
elapsed = self.elapsed_time
404-
stats_list = self._build_stats_list()
404+
stats_list = self.build_stats_list()
405405

406406
# Calculate available space for stats
407407
# Add extra lines for finished banner when in finished state
@@ -422,15 +422,15 @@ def _prepare_display_data(self, height):
422422

423423
def _initialize_widgets(self, colors):
424424
"""Initialize widgets with display and colors."""
425-
if self._header_widget is None:
425+
if self.header_widget is None:
426426
# Initialize trend tracker with colors
427427
if self._trend_tracker is None:
428428
self._trend_tracker = TrendTracker(colors, enabled=True)
429429

430-
self._header_widget = HeaderWidget(self.display, colors, self)
431-
self._table_widget = TableWidget(self.display, colors, self)
432-
self._footer_widget = FooterWidget(self.display, colors, self)
433-
self._help_widget = HelpWidget(self.display, colors)
430+
self.header_widget = HeaderWidget(self.display, colors, self)
431+
self.table_widget = TableWidget(self.display, colors, self)
432+
self.footer_widget = FooterWidget(self.display, colors, self)
433+
self.help_widget = HelpWidget(self.display, colors)
434434

435435
def _render_display_sections(
436436
self, height, width, elapsed, stats_list, colors
@@ -442,12 +442,12 @@ def _render_display_sections(
442442
self._initialize_widgets(colors)
443443

444444
# Render header
445-
line = self._header_widget.render(
445+
line = self.header_widget.render(
446446
line, width, elapsed=elapsed, stats_list=stats_list
447447
)
448448

449449
# Render table
450-
line = self._table_widget.render(
450+
line = self.table_widget.render(
451451
line, width, height=height, stats_list=stats_list
452452
)
453453

@@ -473,7 +473,7 @@ def _update_display(self):
473473

474474
# Show help screen if requested
475475
if self.show_help:
476-
self._help_widget.render(0, width, height=height)
476+
self.help_widget.render(0, width, height=height)
477477
self.display.refresh()
478478
return
479479

@@ -486,11 +486,11 @@ def _update_display(self):
486486
)
487487

488488
# Footer
489-
self._footer_widget.render(height - 2, width)
489+
self.footer_widget.render(height - 2, width)
490490

491491
# Show filter input prompt if in filter input mode
492492
if self.filter_input_mode:
493-
self._footer_widget.render_filter_input_prompt(
493+
self.footer_widget.render_filter_input_prompt(
494494
height - 1, width
495495
)
496496

@@ -616,7 +616,7 @@ def _setup_colors(self):
616616
"trend_stable": A_NORMAL,
617617
}
618618

619-
def _build_stats_list(self):
619+
def build_stats_list(self):
620620
"""Build and sort the statistics list."""
621621
stats_list = []
622622
result_source = self._get_current_result_source()
@@ -707,17 +707,17 @@ def reset_stats(self):
707707
self.view_mode = "ALL"
708708
self.current_thread_index = 0
709709
self.total_samples = 0
710-
self._successful_samples = 0
711-
self._failed_samples = 0
712-
self._max_sample_rate = 0
713-
self._thread_status_counts = {
710+
self.successful_samples = 0
711+
self.failed_samples = 0
712+
self.max_sample_rate = 0
713+
self.thread_status_counts = {
714714
"has_gil": 0,
715715
"on_cpu": 0,
716716
"gil_requested": 0,
717717
"unknown": 0,
718718
"total": 0,
719719
}
720-
self._gc_frame_samples = 0
720+
self.gc_frame_samples = 0
721721
# Clear trend tracking
722722
if self._trend_tracker is not None:
723723
self._trend_tracker.clear()
@@ -886,14 +886,14 @@ def _handle_input(self):
886886

887887
elif ch == ord("+") or ch == ord("="):
888888
# Decrease update interval (faster refresh)
889-
self._display_update_interval = max(
890-
0.05, self._display_update_interval - 0.05
889+
self.display_update_interval = max(
890+
0.05, self.display_update_interval - 0.05
891891
) # Min 20Hz
892892

893893
elif ch == ord("-") or ch == ord("_"):
894894
# Increase update interval (slower refresh)
895-
self._display_update_interval = min(
896-
1.0, self._display_update_interval + 0.05
895+
self.display_update_interval = min(
896+
1.0, self.display_update_interval + 0.05
897897
) # Max 1Hz
898898

899899
elif ch == ord("c") or ch == ord("C"):

Lib/profiling/sampling/live_collector/widgets.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def draw_header_info(self, line, width, elapsed):
180180

181181
# Calculate display refresh rate
182182
refresh_hz = (
183-
1.0 / self.collector._display_update_interval if self.collector._display_update_interval > 0 else 0
183+
1.0 / self.collector.display_update_interval if self.collector.display_update_interval > 0 else 0
184184
)
185185

186186
# Get current view mode and thread display
@@ -248,8 +248,8 @@ def draw_sample_stats(self, line, width, elapsed):
248248
)
249249

250250
# Update max sample rate
251-
if sample_rate > self.collector._max_sample_rate:
252-
self.collector._max_sample_rate = sample_rate
251+
if sample_rate > self.collector.max_sample_rate:
252+
self.collector.max_sample_rate = sample_rate
253253

254254
col = 0
255255
self.add_str(line, col, "Samples: ", curses.A_BOLD)
@@ -308,11 +308,11 @@ def draw_sample_stats(self, line, width, elapsed):
308308
def draw_efficiency_bar(self, line, width):
309309
"""Draw sample efficiency bar showing success/failure rates."""
310310
success_pct = (
311-
self.collector._successful_samples
311+
self.collector.successful_samples
312312
/ max(1, self.collector.total_samples)
313313
) * 100
314314
failed_pct = (
315-
self.collector._failed_samples
315+
self.collector.failed_samples
316316
/ max(1, self.collector.total_samples)
317317
) * 100
318318

@@ -327,7 +327,7 @@ def draw_efficiency_bar(self, line, width):
327327
bar_width = min(MAX_EFFICIENCY_BAR_WIDTH, available_width)
328328
success_fill = int(
329329
(
330-
self.collector._successful_samples
330+
self.collector.successful_samples
331331
/ max(1, self.collector.total_samples)
332332
)
333333
* bar_width
@@ -381,7 +381,7 @@ def draw_thread_status(self, line, width):
381381
"""Draw thread status statistics and GC information."""
382382
# Get status counts for current view mode
383383
thread_data = self.collector._get_current_thread_data()
384-
status_counts = thread_data.as_status_dict() if thread_data else self.collector._thread_status_counts
384+
status_counts = thread_data.as_status_dict() if thread_data else self.collector.thread_status_counts
385385

386386
# Calculate percentages
387387
total_threads = max(1, status_counts["total"])
@@ -395,7 +395,7 @@ def draw_thread_status(self, line, width):
395395
pct_gc = (thread_data.gc_frame_samples / total_samples) * 100
396396
else:
397397
total_samples = max(1, self.collector.total_samples)
398-
pct_gc = (self.collector._gc_frame_samples / total_samples) * 100
398+
pct_gc = (self.collector.gc_frame_samples / total_samples) * 100
399399

400400
col = 0
401401
self.add_str(line, col, "Threads: ", curses.A_BOLD)
@@ -809,7 +809,7 @@ def get_trend_color(column_name):
809809

810810
# File:line column
811811
if col < width - 10:
812-
simplified_path = self.collector._simplify_path(filename)
812+
simplified_path = self.collector.simplify_path(filename)
813813
file_line = f"{simplified_path}:{lineno}"
814814
remaining_width = width - col - 1
815815
self.add_str(

0 commit comments

Comments
 (0)