Skip to content

Commit 4334b0f

Browse files
committed
fixup! Fix browser open after empty export
1 parent 7124c94 commit 4334b0f

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

Lib/profiling/sampling/cli.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
120123
def _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

@@ -794,9 +801,7 @@ def progress_callback(current, total):
794801
# Auto-open browser for HTML output if --browser flag is set
795802
if (
796803
export_ok
797-
and args.format in (
798-
'flamegraph', 'diff_flamegraph', 'heatmap'
799-
)
804+
and args.format in BROWSER_COMPATIBLE_FORMATS
800805
and getattr(args, 'browser', False)
801806
):
802807
_open_in_browser(filename)
@@ -846,7 +851,7 @@ def _handle_output(collector, args, pid, mode):
846851
# Auto-open browser for HTML output if --browser flag is set
847852
if (
848853
export_ok
849-
and args.format in ('flamegraph', 'diff_flamegraph', 'heatmap')
854+
and args.format in BROWSER_COMPATIBLE_FORMATS
850855
and getattr(args, 'browser', False)
851856
):
852857
_open_in_browser(filename)

0 commit comments

Comments
 (0)