High-performance binary reader using C implementation. This reader uses memory-mapped I/O (on Unix) for fast replay of profiling data from binary files. Use as a context manager: with BinaryReader('profile.bin') as reader: info = reader.get_info() reader
| 8 | |
| 9 | |
| 10 | class BinaryReader: |
| 11 | """High-performance binary reader using C implementation. |
| 12 | |
| 13 | This reader uses memory-mapped I/O (on Unix) for fast replay of |
| 14 | profiling data from binary files. |
| 15 | |
| 16 | Use as a context manager: |
| 17 | with BinaryReader('profile.bin') as reader: |
| 18 | info = reader.get_info() |
| 19 | reader.replay_samples(collector, progress_callback) |
| 20 | """ |
| 21 | |
| 22 | def __init__(self, filename): |
| 23 | """Create a new binary reader. |
| 24 | |
| 25 | Args: |
| 26 | filename: Path to input binary file |
| 27 | """ |
| 28 | self.filename = filename |
| 29 | self._reader = None |
| 30 | |
| 31 | def __enter__(self): |
| 32 | self._reader = _remote_debugging.BinaryReader(self.filename) |
| 33 | return self |
| 34 | |
| 35 | def __exit__(self, exc_type, exc_val, exc_tb): |
| 36 | if self._reader is not None: |
| 37 | self._reader.close() |
| 38 | self._reader = None |
| 39 | return False |
| 40 | |
| 41 | def get_info(self): |
| 42 | """Get metadata about the binary file. |
| 43 | |
| 44 | Returns: |
| 45 | dict: File metadata including: |
| 46 | - sample_count: Number of samples in the file |
| 47 | - sample_interval_us: Sampling interval in microseconds |
| 48 | - start_time_us: Start timestamp in microseconds |
| 49 | - string_count: Number of unique strings |
| 50 | - frame_count: Number of unique frames |
| 51 | - compression: Compression type used |
| 52 | """ |
| 53 | if self._reader is None: |
| 54 | raise RuntimeError("Reader not open. Use as context manager.") |
| 55 | return self._reader.get_info() |
| 56 | |
| 57 | def replay_samples(self, collector, progress_callback=None): |
| 58 | """Replay samples from binary file through a collector. |
| 59 | |
| 60 | This allows converting binary profiling data to other formats |
| 61 | (e.g., flamegraph, pstats) by replaying through the appropriate |
| 62 | collector. |
| 63 | |
| 64 | Args: |
| 65 | collector: A Collector instance with a collect() method |
| 66 | progress_callback: Optional callable(current, total) for progress |
| 67 |
no outgoing calls
searching dependent graphs…