@@ -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
505505def _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