11import process from "node:process" ;
22import { spawn } from "node:child_process" ;
3+ import { createResourceMonitor } from "./resource-monitor.ts" ;
34import type { StageCommand , StageDefinition } from "./stage-graph.ts" ;
5+ import type { ProcessResourceUsage } from "./resource-monitor.ts" ;
46
57export interface StageExecutionContext {
68 cwd : string ;
@@ -10,6 +12,7 @@ export interface StageExecutionContext {
1012export interface StageExecutionResult < TStage extends StageDefinition = StageDefinition > {
1113 stage : TStage ;
1214 durationMs : number ;
15+ resourceUsage ?: ProcessResourceUsage ;
1316}
1417
1518export interface StageProgressDetails {
@@ -117,6 +120,8 @@ export async function runStagesSequentially<TStage extends StageDefinition>(
117120 logger ?. start ?.( stage , { stepNumber, total, message } ) ;
118121
119122 const startedAt = Date . now ( ) ;
123+ const stageMonitor = createResourceMonitor ( ) ;
124+ stageMonitor . start ( ) ;
120125
121126 try {
122127 await executeStage ( stage , { cwd, env, stageRunner } ) ;
@@ -126,6 +131,7 @@ export async function runStagesSequentially<TStage extends StageDefinition>(
126131 }
127132 }
128133 catch ( error ) {
134+ stageMonitor . stop ( ) ;
129135 logger ?. fail ?.( stage , { stepNumber, total, message, error } ) ;
130136
131137 if ( error instanceof Error ) {
@@ -141,10 +147,11 @@ export async function runStagesSequentially<TStage extends StageDefinition>(
141147 }
142148
143149 const durationMs = Date . now ( ) - startedAt ;
150+ const resourceUsage = stageMonitor . stop ( ) ?? undefined ;
144151 const formattedDuration = formatDuration ( durationMs ) ;
145152 logger ?. succeed ?.( stage , { stepNumber, total, message, durationMs, formattedDuration } ) ;
146153
147- results . push ( { stage, durationMs } ) ;
154+ results . push ( { stage, durationMs, resourceUsage } ) ;
148155 }
149156 }
150157 finally {
0 commit comments