Bug report
Bug description:
When profiling a script that does not produce HTML output, the following warning is displayed:
Warning: No functions found in profiling data. Check if sampling captured any data.
However, when the --browser option is specified, the program still attempts to open the output file in a browser.
./python -m profiling.sampling run --flamegraph --browser script.py
# script.py
print("hello world")
Suggested Fix
diff --git a/Lib/profiling/sampling/cli.py b/Lib/profiling/sampling/cli.py
index f4b31aad45b..75a21429705 100644
--- a/Lib/profiling/sampling/cli.py
+++ b/Lib/profiling/sampling/cli.py
@@ -607,6 +607,10 @@ def _open_in_browser(path):
"""
abs_path = os.path.abspath(path)
+ if not os.path.exists(abs_path):
+ print(f"Warning: Could not find {abs_path}", file=sys.stderr)
+ return
+
# For heatmap directories, open the index.html file
if os.path.isdir(abs_path):
index_path = os.path.join(abs_path, 'index.html')
I can open a PR with a proposed fix
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Bug report
Bug description:
When profiling a script that does not produce HTML output, the following warning is displayed:
Warning: No functions found in profiling data. Check if sampling captured any data.However, when the
--browseroption is specified, the program still attempts to open the output file in a browser.Suggested Fix
I can open a PR with a proposed fix
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs