-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-5404 - Add docs for profiling execution #2402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from __future__ import annotations | ||
|
||
import argparse | ||
import subprocess | ||
import sys | ||
|
||
|
||
def main(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth having this file at all? We're adding 60 lines of code to change this:
into:
Can we just pass all the args to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I like the conciseness of |
||
parser = argparse.ArgumentParser(description="Generate a flamegraph of a given Python script.") | ||
|
||
parser.add_argument( | ||
"--output", | ||
default="profile", | ||
help="Output filename (default: 'profile')", | ||
) | ||
parser.add_argument( | ||
"--sampling_rate", | ||
default="2000", | ||
help="Sampling rate in samples/sec (default: 2000)", | ||
) | ||
parser.add_argument( | ||
"--native", | ||
default=False, | ||
action=argparse.BooleanOptionalAction, | ||
help="Whether to profile native extensions (default: False)", | ||
) | ||
parser.add_argument( | ||
"--script_path", | ||
required=True, | ||
help="Path to the Python script to be profiled (required)", | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
bash_command = [ | ||
"py-spy", | ||
"record", | ||
"-o", | ||
f"{args.output}.svg", | ||
"-r", | ||
f"{args.sampling_rate}", | ||
"--", | ||
"python", | ||
f"{args.script_path}", | ||
] | ||
|
||
if args.native: | ||
# Insert --native option at the correct position | ||
bash_command.insert(6, "--native") | ||
|
||
try: | ||
subprocess.run(bash_command, check=True) # noqa: S603 | ||
except Exception: | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we even add this to
just
? Since we already need to installpy-spy
manually why not document the py-spy command to run withoutjust
.