(app, exception)
| 121 | |
| 122 | |
| 123 | def 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 | |
| 157 | def setup(app): |
nothing calls this directly
no test coverage detected
searching dependent graphs…