@@ -117,6 +117,9 @@ def __call__(self, parser, namespace, values, option_string=None):
117117 "binary" : BinaryCollector ,
118118}
119119
120+ BROWSER_COMPATIBLE_FORMATS = ("flamegraph" , "diff_flamegraph" , "heatmap" )
121+
122+
120123def _setup_child_monitor (args , parent_pid ):
121124 # Build CLI args for child profilers (excluding --subprocesses to avoid recursion)
122125 child_cli_args = _build_child_profiler_args (args )
@@ -528,8 +531,12 @@ def _add_format_options(parser, include_compression=True, include_binary=True):
528531 output_group .add_argument (
529532 "--browser" ,
530533 action = "store_true" ,
531- help = "Automatically open HTML output (flamegraph, heatmap) in browser. "
532- "When using `--subprocesses`, only the main process opens the browser" ,
534+ help = (
535+ "Automatically open HTML output "
536+ f"({ ', ' .join ('--' + f .replace ('_' , '-' ) for f in BROWSER_COMPATIBLE_FORMATS )} ) "
537+ "in browser. "
538+ "When using `--subprocesses`, only the main process opens the browser"
539+ ),
533540 )
534541
535542
@@ -789,13 +796,12 @@ def progress_callback(current, total):
789796 args .outfile
790797 or _generate_output_filename (args .format , os .getpid ())
791798 )
792- collector .export (filename )
799+ export_ok = collector .export (filename )
793800
794801 # Auto-open browser for HTML output if --browser flag is set
795802 if (
796- args .format in (
797- 'flamegraph' , 'diff_flamegraph' , 'heatmap'
798- )
803+ export_ok
804+ and args .format in BROWSER_COMPATIBLE_FORMATS
799805 and getattr (args , 'browser' , False )
800806 ):
801807 _open_in_browser (filename )
@@ -840,10 +846,14 @@ def _handle_output(collector, args, pid, mode):
840846 filename = os .path .join (args .outfile , _generate_output_filename (args .format , pid ))
841847 else :
842848 filename = args .outfile or _generate_output_filename (args .format , pid )
843- collector .export (filename )
849+ export_ok = collector .export (filename )
844850
845851 # Auto-open browser for HTML output if --browser flag is set
846- if args .format in ('flamegraph' , 'diff_flamegraph' , 'heatmap' ) and getattr (args , 'browser' , False ):
852+ if (
853+ export_ok
854+ and args .format in BROWSER_COMPATIBLE_FORMATS
855+ and getattr (args , 'browser' , False )
856+ ):
847857 _open_in_browser (filename )
848858
849859
0 commit comments