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

Function inject_trace

Doc/tools/extensions/profiling_trace.py:123–154  ·  view source on GitHub ↗
(app, exception)

Source from the content-addressed store, hash-verified

121
122
123def inject_trace(app, exception):
124 if exception:
125 return
126
127 js_path = (
128 Path(app.outdir) / '_static' / 'profiling-sampling-visualization.js'
129 )
130
131 if not js_path.exists():
132 return
133
134 trace = generate_trace(DEMO_SOURCE)
135
136 demo_data = {'source': DEMO_SOURCE.rstrip(), 'trace': trace, 'samples': []}
137
138 demo_json = json.dumps(demo_data, indent=2)
139 content = js_path.read_text(encoding='utf-8')
140
141 pattern = r"(const DEMO_SIMPLE\s*=\s*/\* PROFILING_TRACE_DATA \*/)[^;]+;"
142
143 if re.search(pattern, content):
144 content = re.sub(
145 pattern, lambda m: f"{m.group(1)} {demo_json};", content
146 )
147 js_path.write_text(content, encoding='utf-8')
148 print(
149 f"profiling_trace: Injected {len(trace)} trace events into {js_path.name}"
150 )
151 else:
152 raise ExtensionError(
153 f"profiling_trace: Placeholder pattern not found in {js_path.name}"
154 )
155
156
157def setup(app):

Callers

nothing calls this directly

Calls 10

PathClass · 0.90
generate_traceFunction · 0.85
existsMethod · 0.45
rstripMethod · 0.45
dumpsMethod · 0.45
read_textMethod · 0.45
searchMethod · 0.45
subMethod · 0.45
groupMethod · 0.45
write_textMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…