Skip to content

Commit ef10073

Browse files
committed
Drop the size cap, keep the is_file() guard only
1 parent c6cbdb5 commit ef10073

3 files changed

Lines changed: 3 additions & 28 deletions

File tree

Lib/profiling/sampling/heatmap_collector.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,12 +783,10 @@ def _generate_file_html(self, output_path: Path, filename: str,
783783
line_counts: Dict[int, int], self_counts: Dict[int, int],
784784
file_stat: FileStats):
785785
"""Generate HTML for a single source file with heatmap coloring."""
786-
_MAX_SOURCE_SIZE = 10 * 1024 * 1024
787786
source_lines = [f"# Source file not available: {filename}"]
788787
try:
789788
resolved = Path(filename).resolve()
790-
if (resolved.is_file()
791-
and resolved.stat().st_size <= _MAX_SOURCE_SIZE):
789+
if resolved.is_file():
792790
source_lines = resolved.read_text(
793791
encoding='utf-8', errors='replace').splitlines()
794792
except (IOError, OSError):

Lib/test/test_profiling/test_heatmap.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -642,29 +642,6 @@ def test_export_skips_nonexistent_source(self):
642642
content = f.read()
643643
self.assertIn('Source file not available', content)
644644

645-
def test_export_caps_oversized_source(self):
646-
"""Source files larger than the cap produce a placeholder."""
647-
collector = HeatmapCollector(sample_interval_usec=100)
648-
649-
big_file = os.path.join(self.test_dir, 'big.py')
650-
with open(big_file, 'w') as f:
651-
f.write('x = 1\n' * 2_000_000)
652-
653-
frames = [(big_file, (1, 1, -1, -1), 'f', None)]
654-
collector.process_frames(frames, thread_id=1)
655-
656-
output_path = os.path.join(self.test_dir, 'big_src')
657-
658-
with captured_stdout(), captured_stderr():
659-
collector.export(output_path)
660-
661-
html_files = [f for f in os.listdir(output_path)
662-
if f.startswith('file_') and f.endswith('.html')]
663-
if html_files:
664-
with open(os.path.join(output_path, html_files[0]),
665-
'r', encoding='utf-8') as f:
666-
content = f.read()
667-
self.assertIn('Source file not available', content)
668645

669646

670647
class MockFrameInfo:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Skip non-regular and oversized files in the ``profiling.sampling`` heatmap
2-
exporter instead of reading them unconditionally. Patch by tonghuaroot.
1+
Skip non-regular files in the ``profiling.sampling`` heatmap exporter
2+
instead of reading them unconditionally. Patch by tonghuaroot.

0 commit comments

Comments
 (0)