b6e6a8976c
* Replace Date.now() with performance.now() for duration measurements - Import performance from node:perf_hooks in all affected files - Update Timer and ThinkingTimer classes to use performance.now() - Update activity tracking (markActivity, getIdleMs) to use performance.now() - Update cache duration measurements to use performance.now() - Update agent execution timing (cursor, opencode) to use performance.now() - Update subprocess execution timing to use performance.now() - Update API performance monitoring to use performance.now() - Update prep phase timing to use performance.now() - Update timer.test.ts to mock performance.now() instead of Date.now() Benefits: - Monotonic clock immune to system clock adjustments - Higher precision (microsecond vs millisecond resolution) - Purpose-built for performance measurement Fixes #245 * fix lint. * Round float durations to integers in logging Preserve original behavior by rounding performance.now() float values to integers when displaying/logging millisecond durations. * fix lint. --------- Co-authored-by: pullfrog[bot] <226033991+pullfrog[bot]@users.noreply.github.com> Co-authored-by: Robin Tail <robin_tail@me.com>
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { performance } from "node:perf_hooks";
|
|
import { log } from "../utils/cli.ts";
|
|
import { installNodeDependencies } from "./installNodeDependencies.ts";
|
|
import { installPythonDependencies } from "./installPythonDependencies.ts";
|
|
import type { PrepDefinition, PrepOptions, PrepResult } from "./types.ts";
|
|
|
|
export type { PrepOptions, PrepResult } from "./types.ts";
|
|
|
|
// register all prep steps here
|
|
const prepSteps: PrepDefinition[] = [installNodeDependencies, installPythonDependencies];
|
|
|
|
/**
|
|
* run all prep steps sequentially.
|
|
* failures are logged as warnings but don't stop the run.
|
|
*/
|
|
export async function runPrepPhase(options: PrepOptions): Promise<PrepResult[]> {
|
|
log.debug("» starting prep phase...");
|
|
const startTime = performance.now();
|
|
const results: PrepResult[] = [];
|
|
|
|
for (const step of prepSteps) {
|
|
const shouldRun = await step.shouldRun();
|
|
if (!shouldRun) {
|
|
log.debug(`» skipping ${step.name} (not applicable)`);
|
|
continue;
|
|
}
|
|
|
|
log.debug(`» running ${step.name}...`);
|
|
const result = await step.run(options);
|
|
results.push(result);
|
|
|
|
if (result.dependenciesInstalled) {
|
|
log.debug(`» ${step.name}: dependencies installed`);
|
|
} else if (result.issues.length > 0) {
|
|
log.warning(`» ${step.name}: ${result.issues[0]}`);
|
|
}
|
|
}
|
|
|
|
const totalDurationMs = performance.now() - startTime;
|
|
log.debug(`» prep phase completed (${Math.round(totalDurationMs)}ms)`);
|
|
|
|
return results;
|
|
}
|