Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Lib/profiling/sampling/pstats_collector.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import collections
import marshal
import pstats
lazy from _colorize import ANSIColors
lazy from _colorize import get_colors

from .collector import Collector, extract_lineno
from .constants import MICROSECONDS_PER_SECOND, PROFILING_MODE_CPU


class PstatsCollector(Collector):
aggregating = True

Expand Down Expand Up @@ -178,6 +177,8 @@ def print_stats(self, sort=-1, limit=None, show_summary=True, mode=None):
}

# Print header with colors and proper alignment
ANSIColors = get_colors()

print(f"{ANSIColors.BOLD_BLUE}Profile Stats:{ANSIColors.RESET}")

header_nsamples = f"{ANSIColors.BOLD_BLUE}{'nsamples':>{col_widths['nsamples']}}{ANSIColors.RESET}"
Expand Down Expand Up @@ -269,6 +270,8 @@ def _determine_best_unit(max_value):

def _print_summary(self, stats_list, total_samples):
"""Print summary of interesting functions."""
ANSIColors = get_colors()

print(
f"\n{ANSIColors.BOLD_BLUE}Summary of Interesting Functions:{ANSIColors.RESET}"
)
Expand Down
9 changes: 7 additions & 2 deletions Lib/profiling/sampling/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import sysconfig
import time
from collections import deque
lazy from _colorize import ANSIColors
lazy from _colorize import get_colors

from .binary_collector import BinaryCollector


@contextlib.contextmanager
def _pause_threads(unwinder, blocking):
"""Context manager to pause/resume threads around sampling if blocking is True."""
Expand Down Expand Up @@ -272,6 +271,8 @@ def _print_realtime_stats(self):
) # Max time = Min Hz

# Build cache stats string if stats collection is enabled
ANSIColors = get_colors()

cache_stats_str = ""
if self.collect_stats:
try:
Expand Down Expand Up @@ -305,6 +306,8 @@ def _print_unwinder_stats(self):
except RuntimeError:
return # Stats not enabled

ANSIColors = get_colors()

print(f"\n{ANSIColors.BOLD_BLUE}{'='*50}{ANSIColors.RESET}")
print(f"{ANSIColors.BOLD_BLUE}Unwinder Statistics:{ANSIColors.RESET}")

Expand Down Expand Up @@ -399,6 +402,8 @@ def _print_binary_stats(self, collector):
except (ValueError, RuntimeError):
return # Collector closed or stats unavailable

ANSIColors = get_colors()

print(f" {ANSIColors.CYAN}Binary Encoding:{ANSIColors.RESET}")

repeat_records = stats.get('repeat_records', 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ def test_print_sampled_stats_sort_by_name(self):
and not "calls" in line # Skip summary lines
and not "total time" in line # Skip summary lines
and not "cumulative time" in line
and not "filename:lineno(function)" in line # Skip header line
): # Skip summary lines
data_lines.append(line)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow disabling terminal coloring for Tachyon's pstats collector.
Loading