Create the appropriate collector based on format type. Args: format_type: The output format ('pstats', 'collapsed', 'flamegraph', 'gecko', 'heatmap', 'binary', 'diff_flamegraph') sample_interval_usec: Sampling interval in microseconds skip_idle: Whether to skip idle samp
(format_type, sample_interval_usec, skip_idle, opcodes=False,
output_file=None, compression='auto', diff_baseline=None)
| 560 | return sort_map.get(sort_choice, SORT_MODE_NSAMPLES) |
| 561 | |
| 562 | def _create_collector(format_type, sample_interval_usec, skip_idle, opcodes=False, |
| 563 | output_file=None, compression='auto', diff_baseline=None): |
| 564 | """Create the appropriate collector based on format type. |
| 565 | |
| 566 | Args: |
| 567 | format_type: The output format ('pstats', 'collapsed', 'flamegraph', 'gecko', 'heatmap', 'binary', 'diff_flamegraph') |
| 568 | sample_interval_usec: Sampling interval in microseconds |
| 569 | skip_idle: Whether to skip idle samples |
| 570 | opcodes: Whether to collect opcode information (only used by gecko format |
| 571 | for creating interval markers in Firefox Profiler) |
| 572 | output_file: Output file path (required for binary format) |
| 573 | compression: Compression type for binary format ('auto', 'zstd', 'none') |
| 574 | diff_baseline: Path to baseline binary file for differential flamegraph |
| 575 | |
| 576 | Returns: |
| 577 | A collector instance of the appropriate type |
| 578 | """ |
| 579 | collector_class = COLLECTOR_MAP.get(format_type) |
| 580 | if collector_class is None: |
| 581 | raise ValueError(f"Unknown format: {format_type}") |
| 582 | |
| 583 | if format_type == "diff_flamegraph": |
| 584 | if diff_baseline is None: |
| 585 | raise ValueError("Differential flamegraph requires a baseline file") |
| 586 | if not os.path.exists(diff_baseline): |
| 587 | raise ValueError(f"Baseline file not found: {diff_baseline}") |
| 588 | return collector_class( |
| 589 | sample_interval_usec, |
| 590 | baseline_binary_path=diff_baseline, |
| 591 | skip_idle=skip_idle |
| 592 | ) |
| 593 | |
| 594 | # Binary format requires output file and compression |
| 595 | if format_type == "binary": |
| 596 | if output_file is None: |
| 597 | raise ValueError("Binary format requires an output file") |
| 598 | return collector_class(output_file, sample_interval_usec, skip_idle=skip_idle, |
| 599 | compression=compression) |
| 600 | |
| 601 | # Gecko format never skips idle (it needs both GIL and CPU data) |
| 602 | # and is the only format that uses opcodes for interval markers |
| 603 | if format_type == "gecko": |
| 604 | skip_idle = False |
| 605 | return collector_class(sample_interval_usec, skip_idle=skip_idle, opcodes=opcodes) |
| 606 | |
| 607 | return collector_class(sample_interval_usec, skip_idle=skip_idle) |
| 608 | |
| 609 | |
| 610 | def _generate_output_filename(format_type, pid): |
no test coverage detected
searching dependent graphs…