2020from .stack_collector import CollapsedStackCollector , FlamegraphCollector , DiffFlamegraphCollector
2121from .heatmap_collector import HeatmapCollector
2222from .gecko_collector import GeckoCollector
23+ from .jsonl_collector import JsonlCollector
2324from .binary_collector import BinaryCollector
2425from .binary_reader import BinaryReader
2526from .constants import (
@@ -101,6 +102,7 @@ def __call__(self, parser, namespace, values, option_string=None):
101102 "diff_flamegraph" : "html" ,
102103 "gecko" : "json" ,
103104 "heatmap" : "html" ,
105+ "jsonl" : "jsonl" ,
104106 "binary" : "bin" ,
105107}
106108
@@ -111,6 +113,7 @@ def __call__(self, parser, namespace, values, option_string=None):
111113 "diff_flamegraph" : DiffFlamegraphCollector ,
112114 "gecko" : GeckoCollector ,
113115 "heatmap" : HeatmapCollector ,
116+ "jsonl" : JsonlCollector ,
114117 "binary" : BinaryCollector ,
115118}
116119
@@ -488,6 +491,13 @@ def _add_format_options(parser, include_compression=True, include_binary=True):
488491 action = DiffFlamegraphAction ,
489492 help = "Generate differential flamegraph comparing current profile to `BASELINE` binary file" ,
490493 )
494+ format_group .add_argument (
495+ "--jsonl" ,
496+ action = "store_const" ,
497+ const = "jsonl" ,
498+ dest = "format" ,
499+ help = "Generate newline-delimited JSON (JSONL) for programmatic consumers" ,
500+ )
491501 if include_binary :
492502 format_group .add_argument (
493503 "--binary" ,
@@ -611,15 +621,18 @@ def _sort_to_mode(sort_choice):
611621 return sort_map .get (sort_choice , SORT_MODE_NSAMPLES )
612622
613623def _create_collector (format_type , sample_interval_usec , skip_idle , opcodes = False ,
614- output_file = None , compression = 'auto' , diff_baseline = None ):
624+ mode = None , output_file = None , compression = 'auto' ,
625+ diff_baseline = None ):
615626 """Create the appropriate collector based on format type.
616627
617628 Args:
618- format_type: The output format ('pstats', 'collapsed', 'flamegraph', 'gecko', 'heatmap', 'binary', 'diff_flamegraph')
629+ format_type: The output format ('pstats', 'collapsed', 'flamegraph',
630+ 'gecko', 'heatmap', 'jsonl', 'binary', 'diff_flamegraph')
619631 sample_interval_usec: Sampling interval in microseconds
620632 skip_idle: Whether to skip idle samples
621633 opcodes: Whether to collect opcode information (only used by gecko format
622634 for creating interval markers in Firefox Profiler)
635+ mode: Profiling mode for collectors that expose it in metadata
623636 output_file: Output file path (required for binary format)
624637 compression: Compression type for binary format ('auto', 'zstd', 'none')
625638 diff_baseline: Path to baseline binary file for differential flamegraph
@@ -655,6 +668,11 @@ def _create_collector(format_type, sample_interval_usec, skip_idle, opcodes=Fals
655668 skip_idle = False
656669 return collector_class (sample_interval_usec , skip_idle = skip_idle , opcodes = opcodes )
657670
671+ if format_type == "jsonl" :
672+ return collector_class (
673+ sample_interval_usec , skip_idle = skip_idle , mode = mode
674+ )
675+
658676 return collector_class (sample_interval_usec , skip_idle = skip_idle )
659677
660678
@@ -1142,7 +1160,7 @@ def _handle_attach(args):
11421160
11431161 # Create the appropriate collector
11441162 collector = _create_collector (
1145- args .format , args .sample_interval_usec , skip_idle , args .opcodes ,
1163+ args .format , args .sample_interval_usec , skip_idle , args .opcodes , mode ,
11461164 output_file = output_file ,
11471165 compression = getattr (args , 'compression' , 'auto' ),
11481166 diff_baseline = args .diff_baseline
@@ -1249,7 +1267,7 @@ def _handle_run(args):
12491267
12501268 # Create the appropriate collector
12511269 collector = _create_collector (
1252- args .format , args .sample_interval_usec , skip_idle , args .opcodes ,
1270+ args .format , args .sample_interval_usec , skip_idle , args .opcodes , mode ,
12531271 output_file = output_file ,
12541272 compression = getattr (args , 'compression' , 'auto' ),
12551273 diff_baseline = args .diff_baseline
0 commit comments