MCPcopy Create free account
hub / github.com/NomicFoundation/hardhat / runCommandPhase

Function runCommandPhase

scripts/benchmark/regression.ts:574–636  ·  view source on GitHub ↗

* Run a single-command benchmark: `cfg.runs` measured runs, each preceded by * the optional unmeasured `cfg.prepare` hook. A non-selected command runs * once, unmeasured. Its dependents only observe that it ran before them.

(
  scenarioId: string,
  scenarioTmpDir: string,
  workingDir: string,
  env: Record<string, string> | undefined,
  name: string,
  cfg: CommandVariant,
  emit: boolean,
  peakRssMethod: PeakRssMethod,
)

Source from the content-addressed store, hash-verified

572 * once, unmeasured. Its dependents only observe that it ran before them.
573 */
574async function runCommandPhase(
575 scenarioId: string,
576 scenarioTmpDir: string,
577 workingDir: string,
578 env: Record<string, string> | undefined,
579 name: string,
580 cfg: CommandVariant,
581 emit: boolean,
582 peakRssMethod: PeakRssMethod,
583): Promise<BenchmarkEntry[]> {
584 const runs = emit ? cfg.runs : 1;
585
586 logStep(
587 `${fmt.pkg(name)} (${runs} run${runs === 1 ? "" : "s"}${
588 emit ? "" : ", prerequisite"
589 })`,
590 );
591
592 try {
593 if (!emit) {
594 if (cfg.prepare !== undefined) {
595 await runPrepare(cfg.prepare, { cwd: workingDir, env });
596 }
597
598 await runPlain(cfg.command, { cwd: workingDir, env });
599
600 return [];
601 }
602
603 const measured = await runSeries(
604 cfg.command,
605 reportPaths(scenarioTmpDir, name),
606 {
607 cwd: workingDir,
608 env,
609 runs,
610 warmup: cfg.warmup,
611 prepare: cfg.prepare,
612 peakRssMethod,
613 onWarmupCompleted: (i, total) =>
614 log(fmt.deemphasize(` warm-up ${runCounter(i, total)}`)),
615 onRunCompleted: (run, i, total) =>
616 log(` run ${runCounter(i, total)}: ${formatRun(run)}`),
617 },
618 );
619
620 return measuredRunsToEntries(
621 scenarioId,
622 name,
623 measured,
624 peakRssMethod,
625 cfg.statistic,
626 );
627 } catch (error) {
628 throw benchmarkError(
629 `${scenarioId} / ${name} failed`,
630 cfg.command,
631 workingDir,

Callers 1

runPhasesFunction · 0.85

Calls 11

logStepFunction · 0.90
runPrepareFunction · 0.90
runPlainFunction · 0.90
runSeriesFunction · 0.90
logFunction · 0.90
runCounterFunction · 0.90
formatRunFunction · 0.90
measuredRunsToEntriesFunction · 0.90
reportPathsFunction · 0.85
benchmarkErrorFunction · 0.85
pkgMethod · 0.80

Tested by

no test coverage detected