Skip to content

Commit 1e2400b

Browse files
committed
Regen and simplify
1 parent 596af7f commit 1e2400b

File tree

12 files changed

+92
-174
lines changed

12 files changed

+92
-174
lines changed

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,11 @@ struct _Py_global_strings {
376376
STRUCT_FOR_ID(co_varnames)
377377
STRUCT_FOR_ID(code)
378378
STRUCT_FOR_ID(col_offset)
379+
STRUCT_FOR_ID(collector)
379380
STRUCT_FOR_ID(command)
380381
STRUCT_FOR_ID(comment_factory)
381382
STRUCT_FOR_ID(compile_mode)
383+
STRUCT_FOR_ID(compression)
382384
STRUCT_FOR_ID(config)
383385
STRUCT_FOR_ID(consts)
384386
STRUCT_FOR_ID(context)
@@ -441,7 +443,9 @@ struct _Py_global_strings {
441443
STRUCT_FOR_ID(event)
442444
STRUCT_FOR_ID(eventmask)
443445
STRUCT_FOR_ID(exc)
446+
STRUCT_FOR_ID(exc_tb)
444447
STRUCT_FOR_ID(exc_type)
448+
STRUCT_FOR_ID(exc_val)
445449
STRUCT_FOR_ID(exc_value)
446450
STRUCT_FOR_ID(excepthook)
447451
STRUCT_FOR_ID(exception)
@@ -697,6 +701,7 @@ struct _Py_global_strings {
697701
STRUCT_FOR_ID(print_file_and_line)
698702
STRUCT_FOR_ID(priority)
699703
STRUCT_FOR_ID(progress)
704+
STRUCT_FOR_ID(progress_callback)
700705
STRUCT_FOR_ID(progress_routine)
701706
STRUCT_FOR_ID(proto)
702707
STRUCT_FOR_ID(protocol)
@@ -736,6 +741,7 @@ struct _Py_global_strings {
736741
STRUCT_FOR_ID(reversed)
737742
STRUCT_FOR_ID(rounding)
738743
STRUCT_FOR_ID(salt)
744+
STRUCT_FOR_ID(sample_interval_us)
739745
STRUCT_FOR_ID(sched_priority)
740746
STRUCT_FOR_ID(scheduler)
741747
STRUCT_FOR_ID(script)
@@ -775,8 +781,10 @@ struct _Py_global_strings {
775781
STRUCT_FOR_ID(spam)
776782
STRUCT_FOR_ID(src)
777783
STRUCT_FOR_ID(src_dir_fd)
784+
STRUCT_FOR_ID(stack_frames)
778785
STRUCT_FOR_ID(stacklevel)
779786
STRUCT_FOR_ID(start)
787+
STRUCT_FOR_ID(start_time_us)
780788
STRUCT_FOR_ID(statement)
781789
STRUCT_FOR_ID(stats)
782790
STRUCT_FOR_ID(status)
@@ -817,6 +825,7 @@ struct _Py_global_strings {
817825
STRUCT_FOR_ID(times)
818826
STRUCT_FOR_ID(timespec)
819827
STRUCT_FOR_ID(timestamp)
828+
STRUCT_FOR_ID(timestamp_us)
820829
STRUCT_FOR_ID(timetuple)
821830
STRUCT_FOR_ID(timeunit)
822831
STRUCT_FOR_ID(top)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

InternalDocs/profiling_binary_format.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,6 @@ frames from the previous stack are kept, and new frames are prepended.
174174
Used when the code path changed: some frames were popped (function returns)
175175
and new frames were pushed (different function calls).
176176

177-
### Compression Benefits
178-
179-
This delta encoding provides massive savings for typical profiling workloads:
180-
181-
- **CPU-bound code**: Hot loops produce many identical samples. RLE encoding
182-
compresses 100 identical samples to just 2-3 bytes of overhead plus the
183-
timestamp/status data.
184-
185-
- **I/O-bound code**: Alternating between wait and work produces similar
186-
stacks with small variations. SUFFIX encoding captures this efficiently.
187-
188-
- **Call-heavy code**: Functions calling other functions share common stack
189-
prefixes. POP_PUSH encoding only stores the changed frames.
190-
191177
### Thread and Interpreter Identification
192178

193179
Thread IDs are 64-bit values that can be large (memory addresses on some

Lib/profiling/sampling/binary_collector.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ def export(self, filename=None):
9898

9999
@property
100100
def total_samples(self):
101-
"""Total number of samples written."""
102101
return self._writer.total_samples
103102

104103
def get_stats(self):
@@ -111,7 +110,6 @@ def get_stats(self):
111110
return self._writer.get_stats()
112111

113112
def __enter__(self):
114-
"""Context manager entry."""
115113
return self
116114

117115
def __exit__(self, exc_type, exc_val, exc_tb):

Lib/profiling/sampling/binary_reader.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ def __init__(self, filename):
2323
self._reader = None
2424

2525
def __enter__(self):
26-
"""Open the binary file for reading."""
2726
import _remote_debugging
2827
self._reader = _remote_debugging.BinaryReader(self.filename)
2928
return self
3029

3130
def __exit__(self, exc_type, exc_val, exc_tb):
32-
"""Close the binary file."""
3331
if self._reader is not None:
3432
self._reader.close()
3533
self._reader = None
@@ -71,7 +69,6 @@ def replay_samples(self, collector, progress_callback=None):
7169

7270
@property
7371
def sample_count(self):
74-
"""Number of samples in the file."""
7572
if self._reader is None:
7673
raise RuntimeError("Reader not open. Use as context manager.")
7774
return self._reader.get_info()['sample_count']

Lib/profiling/sampling/cli.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _parse_mode(mode_string):
102102
def _check_process_died(process):
103103
"""Check if process died and raise an error with stderr if available."""
104104
if process.poll() is None:
105-
return # Process still running
105+
return
106106

107107
# Process died - try to get stderr for error message
108108
stderr_msg = ""
@@ -471,7 +471,6 @@ def _handle_output(collector, args, pid, mode):
471471
sort_mode, limit, not args.no_summary, mode
472472
)
473473
else:
474-
# Export to file
475474
filename = args.outfile or _generate_output_filename(args.format, pid)
476475
collector.export(filename)
477476

@@ -726,7 +725,6 @@ def _handle_attach(args):
726725
mode != PROFILING_MODE_WALL if mode != PROFILING_MODE_ALL else False
727726
)
728727

729-
# For binary format, determine output file before creating collector
730728
output_file = None
731729
if args.format == "binary":
732730
output_file = args.outfile or _generate_output_filename(args.format, args.pid)
@@ -806,7 +804,6 @@ def _handle_run(args):
806804
mode != PROFILING_MODE_WALL if mode != PROFILING_MODE_ALL else False
807805
)
808806

809-
# For binary format, determine output file before creating collector
810807
output_file = None
811808
if args.format == "binary":
812809
output_file = args.outfile or _generate_output_filename(args.format, process.pid)
@@ -940,7 +937,6 @@ def _handle_replay(args):
940937
"""Handle the 'replay' command - convert binary profile to another format."""
941938
import os
942939

943-
# Check input file exists
944940
if not os.path.exists(args.input_file):
945941
sys.exit(f"Error: Input file not found: {args.input_file}")
946942

@@ -956,10 +952,8 @@ def _handle_replay(args):
956952
print(f" Sample interval: {interval} us")
957953
print(f" Compression: {'zstd' if info.get('compression_type', 0) == 1 else 'none'}")
958954

959-
# Create appropriate collector
960955
collector = _create_collector(args.format, interval, skip_idle=False)
961956

962-
# Replay with progress bar
963957
def progress_callback(current, total):
964958
if total > 0:
965959
pct = current / total
@@ -969,20 +963,17 @@ def progress_callback(current, total):
969963
print(f"\r [{bar}] {pct*100:5.1f}% ({current:,}/{total:,})", end="", flush=True)
970964

971965
count = reader.replay_samples(collector, progress_callback)
972-
print() # Newline after progress bar
966+
print()
973967

974-
# Handle output similar to other formats
975968
if args.format == "pstats":
976969
if args.outfile:
977970
collector.export(args.outfile)
978971
else:
979-
# Print to stdout with defaults applied
980972
sort_choice = args.sort if args.sort is not None else "nsamples"
981973
limit = args.limit if args.limit is not None else 15
982974
sort_mode = _sort_to_mode(sort_choice)
983975
collector.print_stats(sort_mode, limit, not args.no_summary, PROFILING_MODE_WALL)
984976
else:
985-
# Export to file
986977
filename = args.outfile or _generate_output_filename(args.format, os.getpid())
987978
collector.export(filename)
988979

0 commit comments

Comments
 (0)