MCPcopy Index your code
hub / github.com/python/cpython / _build_output_pattern

Function _build_output_pattern

Lib/profiling/sampling/cli.py:167–188  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

165
166
167def _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
191def _parse_mode(mode_string):

Calls 2

splitextMethod · 0.80
getMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…