Build output filename pattern for child profilers. The pattern uses {pid} as a placeholder which will be replaced with the actual child PID using str.replace(), so user filenames with braces are safe.
(args)
| 165 | |
| 166 | |
| 167 | def _build_output_pattern(args): |
| 168 | """Build output filename pattern for child profilers. |
| 169 | |
| 170 | The pattern uses {pid} as a placeholder which will be replaced with the |
| 171 | actual child PID using str.replace(), so user filenames with braces are safe. |
| 172 | """ |
| 173 | if args.outfile: |
| 174 | # User specified output - add PID to filename |
| 175 | base, ext = os.path.splitext(args.outfile) |
| 176 | if ext: |
| 177 | return f"{base}_{{pid}}{ext}" |
| 178 | else: |
| 179 | return f"{args.outfile}_{{pid}}" |
| 180 | else: |
| 181 | # Use default pattern based on format (consistent _ separator) |
| 182 | extension = FORMAT_EXTENSIONS.get(args.format, "txt") |
| 183 | if args.format == "heatmap": |
| 184 | return "heatmap_{pid}" |
| 185 | if args.format == "pstats": |
| 186 | # pstats defaults to stdout, but for subprocesses we need files |
| 187 | return "profile_{pid}.pstats" |
| 188 | return f"{args.format}_{{pid}}.{extension}" |
| 189 | |
| 190 | |
| 191 | def _parse_mode(mode_string): |
searching dependent graphs…