MCPcopy Index your code
hub / github.com/python/cpython / convert_binary_to_format

Function convert_binary_to_format

Lib/profiling/sampling/binary_reader.py:93–129  ·  view source on GitHub ↗

Convert a binary profiling file to another format. Args: input_file: Path to input binary file output_file: Path to output file output_format: Target format ('flamegraph', 'collapsed', 'pstats', etc.) sample_interval_usec: Override sample interval (uses file's if

(input_file, output_file, output_format,
                             sample_interval_usec=None, progress_callback=None)

Source from the content-addressed store, hash-verified

91
92
93def convert_binary_to_format(input_file, output_file, output_format,
94 sample_interval_usec=None, progress_callback=None):
95 """Convert a binary profiling file to another format.
96
97 Args:
98 input_file: Path to input binary file
99 output_file: Path to output file
100 output_format: Target format ('flamegraph', 'collapsed', 'pstats', etc.)
101 sample_interval_usec: Override sample interval (uses file's if None)
102 progress_callback: Optional callable(current, total) for progress
103
104 Returns:
105 int: Number of samples converted
106 """
107 with BinaryReader(input_file) as reader:
108 info = reader.get_info()
109 interval = sample_interval_usec or info['sample_interval_us']
110
111 # Create appropriate collector based on format
112 if output_format == 'flamegraph':
113 collector = FlamegraphCollector(interval)
114 elif output_format == 'collapsed':
115 collector = CollapsedStackCollector(interval)
116 elif output_format == 'pstats':
117 collector = PstatsCollector(interval)
118 elif output_format == 'gecko':
119 collector = GeckoCollector(interval)
120 else:
121 raise ValueError(f"Unknown output format: {output_format}")
122
123 # Replay samples through collector
124 count = reader.replay_samples(collector, progress_callback)
125
126 # Export to target format
127 collector.export(output_file)
128
129 return count

Callers

nothing calls this directly

Calls 8

exportMethod · 0.95
BinaryReaderClass · 0.85
FlamegraphCollectorClass · 0.85
PstatsCollectorClass · 0.85
GeckoCollectorClass · 0.85
replay_samplesMethod · 0.80
get_infoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…