feat(coding-agent): add startup profiling scripts for tui/rpc (#2497)

This commit is contained in:
Duncan Ogilvie
2026-03-21 20:46:00 +01:00
committed by GitHub
parent f90647ea8e
commit 80f527ec22
5 changed files with 594 additions and 9 deletions

View File

@@ -754,6 +754,11 @@ export async function main(args: string[]) {
stdinContent,
);
const isInteractive = !parsed.print && parsed.mode === undefined;
const startupBenchmark = isTruthyEnvFlag(process.env.PI_STARTUP_BENCHMARK);
if (startupBenchmark && !isInteractive) {
console.error(chalk.red("Error: PI_STARTUP_BENCHMARK only supports interactive mode"));
process.exit(1);
}
const mode = parsed.mode || "text";
initTheme(settingsManager.getTheme(), isInteractive);
@@ -848,8 +853,7 @@ export async function main(args: string[]) {
console.log(chalk.dim(`Model scope: ${modelList} ${chalk.gray("(Ctrl+P to cycle)")}`));
}
printTimings();
const mode = new InteractiveMode(session, {
const interactiveMode = new InteractiveMode(session, {
migratedProviders,
modelFallbackMessage,
initialMessage,
@@ -857,7 +861,21 @@ export async function main(args: string[]) {
initialMessages: parsed.messages,
verbose: parsed.verbose,
});
await mode.run();
if (startupBenchmark) {
await interactiveMode.init();
interactiveMode.stop();
stopThemeWatcher();
if (process.stdout.writableLength > 0) {
await new Promise<void>((resolve) => process.stdout.once("drain", resolve));
}
if (process.stderr.writableLength > 0) {
await new Promise<void>((resolve) => process.stderr.once("drain", resolve));
}
return;
}
printTimings();
await interactiveMode.run();
} else {
await runPrintMode(session, {
mode,