Add timer
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
|||||||
setupGitHubInstallationToken,
|
setupGitHubInstallationToken,
|
||||||
} from "./utils/github.ts";
|
} from "./utils/github.ts";
|
||||||
import { setupGitAuth, setupGitBranch, setupGitConfig } from "./utils/setup.ts";
|
import { setupGitAuth, setupGitBranch, setupGitConfig } from "./utils/setup.ts";
|
||||||
|
import { Timer } from "./utils/timer.ts";
|
||||||
|
|
||||||
// runtime validation using agents (needed for ArkType)
|
// runtime validation using agents (needed for ArkType)
|
||||||
// Note: The AgentName type is defined in external.ts, this is the runtime validator
|
// Note: The AgentName type is defined in external.ts, this is the runtime validator
|
||||||
@@ -51,23 +52,34 @@ export async function main(inputs: Inputs): Promise<MainResult> {
|
|||||||
let mcpServerClose: (() => Promise<void>) | undefined;
|
let mcpServerClose: (() => Promise<void>) | undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const timer = new Timer();
|
||||||
|
|
||||||
// parse payload early to extract agent
|
// parse payload early to extract agent
|
||||||
const payload = parsePayload(inputs);
|
const payload = parsePayload(inputs);
|
||||||
|
|
||||||
const partialCtx = await initializeContext(inputs, payload);
|
const partialCtx = await initializeContext(inputs, payload);
|
||||||
const ctx = partialCtx as MainContext;
|
const ctx = partialCtx as MainContext;
|
||||||
|
timer.checkpoint("initializeContext");
|
||||||
|
|
||||||
setupGitAuth({
|
setupGitAuth({
|
||||||
githubInstallationToken: ctx.githubInstallationToken,
|
githubInstallationToken: ctx.githubInstallationToken,
|
||||||
repoContext: ctx.repoContext,
|
repoContext: ctx.repoContext,
|
||||||
});
|
});
|
||||||
|
|
||||||
await setupTempDirectory(ctx);
|
await setupTempDirectory(ctx);
|
||||||
|
timer.checkpoint("setupTempDirectory");
|
||||||
|
|
||||||
setupGitBranch(ctx.payload);
|
setupGitBranch(ctx.payload);
|
||||||
|
|
||||||
await startMcpServer(ctx);
|
await startMcpServer(ctx);
|
||||||
mcpServerClose = ctx.mcpServerClose;
|
mcpServerClose = ctx.mcpServerClose;
|
||||||
|
timer.checkpoint("startMcpServer");
|
||||||
|
|
||||||
setupMcpServers(ctx);
|
setupMcpServers(ctx);
|
||||||
|
|
||||||
await installAgentCli(ctx);
|
await installAgentCli(ctx);
|
||||||
|
timer.checkpoint("installAgentCli");
|
||||||
|
|
||||||
validateApiKey(ctx);
|
validateApiKey(ctx);
|
||||||
|
|
||||||
const result = await runAgent(ctx);
|
const result = await runAgent(ctx);
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { log } from "./cli.ts";
|
||||||
|
|
||||||
|
export class Timer {
|
||||||
|
private initialTimestamp: number;
|
||||||
|
private lastCheckpointTimestamp: number | null = null;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.initialTimestamp = Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
checkpoint(name: string): void {
|
||||||
|
const now = Date.now();
|
||||||
|
const duration = this.lastCheckpointTimestamp
|
||||||
|
? now - this.lastCheckpointTimestamp
|
||||||
|
: now - this.initialTimestamp;
|
||||||
|
|
||||||
|
log.info(`${name}: ${duration}ms`);
|
||||||
|
this.lastCheckpointTimestamp = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user