Skip to content

Commit e187121

Browse files
committed
fixup! Apply suggestions from code review
1 parent 50b7c89 commit e187121

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

Doc/library/profiling.sampling.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,23 +295,23 @@ The default configuration works well for most use cases:
295295
:widths: 25 75
296296

297297
* - Option
298-
- Default behavior
298+
- Default
299299
* - ``--interval`` / ``-i``
300300
- 100 µs between samples (~10,000 samples/sec)
301301
* - ``--duration`` / ``-d``
302-
- Profile for 10 seconds
302+
- 10 seconds
303303
* - ``--all-threads`` / ``-a``
304-
- Sample main thread only
304+
- Main thread only
305305
* - ``--native``
306306
- No ``<native>`` frames (C code time attributed to caller)
307307
* - ``--no-gc``
308-
- Include ``<GC>`` frames when garbage collection is active
308+
- ``<GC>`` frames included when garbage collection is active
309309
* - ``--mode``
310310
- Wall-clock mode (all samples recorded)
311311
* - ``--realtime-stats``
312-
- No live statistics display during profiling
312+
- Disabled
313313
* - ``--subprocesses``
314-
- Profile only the target process (no subprocess monitoring)
314+
- Disabled
315315

316316

317317
Sampling interval and duration

Lib/profiling/sampling/cli.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def _generate_output_filename(format_type, pid):
499499
# For heatmap, use cleaner directory name without extension
500500
if format_type == "heatmap":
501501
return f"heatmap_{pid}"
502-
return f"{format_type}.{pid}.{extension}"
502+
return f"{format_type}_{pid}.{extension}"
503503

504504

505505
def _handle_output(collector, args, pid, mode):
@@ -513,7 +513,12 @@ def _handle_output(collector, args, pid, mode):
513513
"""
514514
if args.format == "pstats":
515515
if args.outfile:
516-
collector.export(args.outfile)
516+
# If outfile is a directory, generate filename inside it
517+
if os.path.isdir(args.outfile):
518+
filename = os.path.join(args.outfile, _generate_output_filename(args.format, pid))
519+
collector.export(filename)
520+
else:
521+
collector.export(args.outfile)
517522
else:
518523
# Print to stdout with defaults applied
519524
sort_choice = args.sort if args.sort is not None else "nsamples"
@@ -524,7 +529,11 @@ def _handle_output(collector, args, pid, mode):
524529
)
525530
else:
526531
# Export to file
527-
filename = args.outfile or _generate_output_filename(args.format, pid)
532+
if args.outfile and os.path.isdir(args.outfile):
533+
# If outfile is a directory, generate filename inside it
534+
filename = os.path.join(args.outfile, _generate_output_filename(args.format, pid))
535+
else:
536+
filename = args.outfile or _generate_output_filename(args.format, pid)
528537
collector.export(filename)
529538

530539

0 commit comments

Comments
 (0)