feat: Add OTEL log event gemini_cli.startup_stats for startup stats. (#14734)

This commit is contained in:
Kevin Ramdass
2025-12-08 12:29:50 -08:00
committed by GitHub
parent f8c4ff635c
commit 159be887df
4 changed files with 130 additions and 0 deletions
@@ -10,6 +10,8 @@ import * as fs from 'node:fs';
import type { Config } from '../config/config.js';
import { recordStartupPerformance } from './metrics.js';
import { debugLogger } from '../utils/debugLogger.js';
import { StartupStatsEvent, type StartupPhaseStats } from './types.js';
import { logStartupStats } from './loggers.js';
interface StartupPhase {
name: string;
@@ -197,6 +199,37 @@ export class StartupProfiler {
}
}
// Emit StartupStats event
const startupPhases: StartupPhaseStats[] = [];
for (const phase of this.phases.values()) {
if (!phase.ended) continue;
const measure = measures.find((m) => m.name === phase.name);
if (measure && phase.cpuUsage) {
startupPhases.push({
name: phase.name,
duration_ms: measure.duration,
cpu_usage_user_usec: phase.cpuUsage.user,
cpu_usage_system_usec: phase.cpuUsage.system,
start_time_usec: (performance.timeOrigin + measure.startTime) * 1000,
end_time_usec:
(performance.timeOrigin + measure.startTime + measure.duration) *
1000,
});
}
}
if (startupPhases.length > 0) {
logStartupStats(
config,
new StartupStatsEvent(
startupPhases,
os.platform(),
os.release(),
fs.existsSync('/.dockerenv'),
),
);
}
// Clear performance marks and measures for all tracked phases.
for (const phaseName of this.phases.keys()) {
const startMarkName = this.getStartMarkName(phaseName);