MCPcopy
hub / github.com/ChromeDevTools/chrome-devtools-mcp / stopTracingAndAppendOutput

Function stopTracingAndAppendOutput

src/tools/performance.ts:184–233  ·  view source on GitHub ↗
(
  page: ContextPage,
  response: Response,
  context: Context,
  filePath?: string,
)

Source from the content-addressed store, hash-verified

182});
183
184async function stopTracingAndAppendOutput(
185 page: ContextPage,
186 response: Response,
187 context: Context,
188 filePath?: string,
189): Promise<void> {
190 try {
191 const traceEventsBuffer = await page.pptrPage.tracing.stop();
192 if (filePath && traceEventsBuffer) {
193 let dataToWrite: Uint8Array = traceEventsBuffer;
194 if (filePath.endsWith('.gz')) {
195 dataToWrite = await new Promise((resolve, reject) => {
196 zlib.gzip(traceEventsBuffer, (error, result) => {
197 if (error) {
198 reject(error);
199 } else {
200 resolve(result);
201 }
202 });
203 });
204 }
205 const file = await context.saveFile(
206 dataToWrite,
207 filePath,
208 filePath.endsWith('.gz') ? '.json.gz' : '.json',
209 );
210 response.appendResponseLine(
211 `The raw trace data was saved to ${file.filename}.`,
212 );
213 }
214 const result = await parseRawTraceBuffer(traceEventsBuffer, {
215 cpuThrottling: page.cpuThrottlingRate,
216 networkThrottling: page.networkConditions ?? undefined,
217 });
218 response.appendResponseLine('The performance trace has been stopped.');
219 if (traceResultIsSuccess(result)) {
220 if (context.isCruxEnabled()) {
221 await populateCruxData(result);
222 }
223 context.storeTraceRecording(result);
224 response.attachTraceSummary(result);
225 } else {
226 throw new Error(
227 `There was an unexpected error parsing the trace: ${result.error}`,
228 );
229 }
230 } finally {
231 context.setIsRunningPerformanceTrace(false);
232 }
233}
234
235/** We tell CrUXManager to fetch data so it's available when DevTools.PerformanceTraceFormatter is invoked */
236async function populateCruxData(result: TraceResult): Promise<void> {

Callers 1

performance.tsFile · 0.85

Calls 12

rejectFunction · 0.85
resolveFunction · 0.85
parseRawTraceBufferFunction · 0.85
traceResultIsSuccessFunction · 0.85
populateCruxDataFunction · 0.85
stopMethod · 0.80
saveFileMethod · 0.80
isCruxEnabledMethod · 0.80
storeTraceRecordingMethod · 0.80
appendResponseLineMethod · 0.65
attachTraceSummaryMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…