( scenario: Scenario, resolved: ResolvedCommand, runDir: string, baseEnv: NodeJS.ProcessEnv, args: ProfileArgs, )
| 382 | } |
| 383 | |
| 384 | function profileSystem( |
| 385 | scenario: Scenario, |
| 386 | resolved: ResolvedCommand, |
| 387 | runDir: string, |
| 388 | baseEnv: NodeJS.ProcessEnv, |
| 389 | args: ProfileArgs, |
| 390 | ): RunRecord { |
| 391 | const perfData = path.join(runDir, "perf.data"); |
| 392 | const wrapped = wrapWithPerfCpu( |
| 393 | resolved.command, |
| 394 | perfData, |
| 395 | args.sampleRateHz, |
| 396 | ); |
| 397 | |
| 398 | const env: NodeJS.ProcessEnv = { |
| 399 | ...baseEnv, |
| 400 | NODE_OPTIONS: mergeNodeOptions(baseEnv.NODE_OPTIONS, PERF_JS_NODE_OPTIONS), |
| 401 | }; |
| 402 | |
| 403 | logStep(`[${scenario.id}] system profile: ${resolved.command}`); |
| 404 | const record = runInScenario( |
| 405 | wrapped, |
| 406 | scenario, |
| 407 | env, |
| 408 | commandLogPath(runDir, Mode.System), |
| 409 | args.showOutput, |
| 410 | ); |
| 411 | |
| 412 | // Resolving JS frame names depends on the /tmp/perf-<pid>.map files the |
| 413 | // profiled processes just wrote. Symbolize to ensure output is |
| 414 | // self-contained. |
| 415 | const samples = path.join(runDir, PERF_SCRIPT_OUTPUT_FILENAME); |
| 416 | |
| 417 | // Remove artifacts from a previous run in the same --out-dir, so that a |
| 418 | // crash between symbolizing and compressing does not leave stale samples |
| 419 | // behind. |
| 420 | rmSync(`${samples}.gz`, { force: true }); |
| 421 | |
| 422 | const symbolized = runPostProcess( |
| 423 | `perf script -i ${shellQuote(perfData)} > ${shellQuote(samples)}`, |
| 424 | ); |
| 425 | |
| 426 | runPostProcess( |
| 427 | `perf report -i ${shellQuote(perfData)} --stdio --no-children --no-call-graph --sort dso > ${shellQuote(path.join(runDir, "dso.txt"))}`, |
| 428 | ); |
| 429 | runPostProcess( |
| 430 | `perf report -i ${shellQuote(perfData)} --stdio --no-children --no-call-graph --sort dso,sym --percent-limit 0.05 > ${shellQuote(path.join(runDir, "report.txt"))}`, |
| 431 | ); |
| 432 | |
| 433 | if (symbolized) { |
| 434 | runPostProcess(`gzip -f ${shellQuote(samples)}`); |
| 435 | } else { |
| 436 | // A truncated samples file would masquerade as a complete profile. |
| 437 | rmSync(samples, { force: true }); |
| 438 | } |
| 439 | |
| 440 | // perf.data is machine-bound and large, so only keep it if the user |
| 441 | // explicitly requested it or if symbolization failed |
no test coverage detected