@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
35 lines • 1.49 kB
JavaScript
import { envValue } from "./brand.js";
import { AsyncLocalStorage } from "node:async_hooks";
/**
* Per-phase timing of a session open (senpi#5707), for naming the await that holds a slow open.
* Enable with SENPI_OPEN_TIMING=1. Off, every call returns before reading a clock or touching
* stderr. On, each mark is one stderr line, written the moment its phase ends:
*
* senpi open-timing <epoch ms> <scope> <phase> +<ms since the scope's previous mark>
*
* Lines carry the wall clock so a host's lines and its session worker's lines (another isolate,
* the same stderr) can be merged in order, and a scope so concurrent opens stay apart.
*/
const ENABLED = envValue("OPEN_TIMING") === "1";
const DISABLED = { mark: () => { } };
const speculative = new AsyncLocalStorage();
/** Speculative builds have no caller to charge; drop their timing rather than report a misleading open. */
export function withoutOpenTiming(build) {
return speculative.run(true, build);
}
export function openTimingEnabled() {
return ENABLED;
}
export function startOpenTimer(scope) {
if (!ENABLED || speculative.getStore())
return DISABLED;
let last = performance.now();
return {
mark(phase) {
const now = performance.now();
process.stderr.write(`senpi open-timing ${Math.round(performance.timeOrigin + now)} ${scope} ${phase} +${Math.round(now - last)}ms\n`);
last = now;
},
};
}
//# sourceMappingURL=open-timing.js.map