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)
| 91 | |
| 92 | |
| 93 | def 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…