Summary
Add a /perf slash command that surfaces Gemini CLI's existing telemetry data as a real-time, in-terminal performance dashboard. This gives developers immediate visibility into startup timing, memory consumption, tool execution profiling, model API latency, and session statistics, without leaving the CLI.
Motivation
Gemini CLI ships a rich but hidden telemetry layer - OpenTelemetry-based metrics, a startup profiler, a memory monitor, activity tracking, and regression detection are all instrumented but never surfaced to the user. The existing /stats command covers token/quota info, but there is no way for users to:
- See how long startup took and which phases are slow
- Monitor memory consumption during a session
- Profile which tools are slowest or called most frequently
- Track API latency per model across requests
- Detect performance regressions between versions
- Export reports for CI integration or bug reports
Existing Infrastructure
| Component |
Location |
What It Does |
StartupProfiler |
packages/core/src/telemetry/startupProfiler.ts |
Phase-based startup timing with performance.mark/measure |
MemoryMonitor |
packages/core/src/telemetry/memory-monitor.ts |
Continuous heap/RSS monitoring, high-water marks, thresholds |
ActivityMonitor |
packages/core/src/telemetry/activity-monitor.ts |
Event buffering with listener pattern |
metrics.ts |
packages/core/src/telemetry/metrics.ts |
50+ OpenTelemetry counters/histograms |
/stats command |
packages/cli/src/ui/commands/statsCommand.ts |
Existing pattern for session stats via SlashCommand |
SessionContext |
packages/cli/src/ui/contexts/SessionContext.tsx |
Real-time metrics state with event subscription |
Proposed Design
/perf Slash Command with Sub-Commands
/perf → Overview dashboard (all sections)
/perf startup → Startup time breakdown by phase
/perf memory → Current memory usage + high-water marks
/perf tools → Tool execution timing & frequency table
/perf api → API latency per model + error rates
/perf session → Session lifetime statistics
/perf export [format] → Export report as JSON/Markdown
Core Data Aggregation Service (PerformanceDataService)
- Aggregates data from
StartupProfiler, MemoryMonitor, ActivityMonitor, and session metrics
- Exposes a unified
getPerformanceSnapshot() API
- Computes derived metrics: avg latencies, success rates, memory usage percentages
Ink-Based Dashboard Rendering
- Color-coded startup phase breakdown (green/yellow/red thresholds)
- Memory usage bar with heap percentage and RSS tracking
- Tool profiler table sorted by total execution time
- Per-model API metrics with error rate indicators
Implementation Phases
- Data Layer -
PerformanceDataService aggregating existing telemetry sources
/perf Command & UI - Slash command + Ink components following statsCommand.ts pattern
- Export & CI - JSON/Markdown exporters, regression detection with configurable thresholds
- DevTools Integration (stretch) - Stream metrics to DevTools via existing WebSocket infrastructure
Expected Outcomes
Related
- Telemetry sources:
packages/core/src/telemetry/
- DevTools:
packages/devtools/
Summary
Add a
/perfslash command that surfaces Gemini CLI's existing telemetry data as a real-time, in-terminal performance dashboard. This gives developers immediate visibility into startup timing, memory consumption, tool execution profiling, model API latency, and session statistics, without leaving the CLI.Motivation
Gemini CLI ships a rich but hidden telemetry layer - OpenTelemetry-based metrics, a startup profiler, a memory monitor, activity tracking, and regression detection are all instrumented but never surfaced to the user. The existing
/statscommand covers token/quota info, but there is no way for users to:Existing Infrastructure
StartupProfilerpackages/core/src/telemetry/startupProfiler.tsperformance.mark/measureMemoryMonitorpackages/core/src/telemetry/memory-monitor.tsActivityMonitorpackages/core/src/telemetry/activity-monitor.tsmetrics.tspackages/core/src/telemetry/metrics.ts/statscommandpackages/cli/src/ui/commands/statsCommand.tsSlashCommandSessionContextpackages/cli/src/ui/contexts/SessionContext.tsxProposed Design
/perfSlash Command with Sub-CommandsCore Data Aggregation Service (
PerformanceDataService)StartupProfiler,MemoryMonitor,ActivityMonitor, and session metricsgetPerformanceSnapshot()APIInk-Based Dashboard Rendering
Implementation Phases
PerformanceDataServiceaggregating existing telemetry sources/perfCommand & UI - Slash command + Ink components followingstatsCommand.tspatternExpected Outcomes
/perfcommand accessible in-CLI with sub-commandsRelated
packages/core/src/telemetry/packages/devtools/