Skip to content

feat: In-CLI Performance Monitoring Dashboard (/perf command) #20313

@Shivangisharma4

Description

@Shivangisharma4

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

  1. Data Layer - PerformanceDataService aggregating existing telemetry sources
  2. /perf Command & UI - Slash command + Ink components following statsCommand.ts pattern
  3. Export & CI - JSON/Markdown exporters, regression detection with configurable thresholds
  4. DevTools Integration (stretch) - Stream metrics to DevTools via existing WebSocket infrastructure

Expected Outcomes

  • /perf command accessible in-CLI with sub-commands
  • Startup time breakdown with optimization suggestions
  • Memory usage monitoring with high-consumption warnings
  • Tool execution timing and frequency statistics
  • Model API latency tracking per request
  • Performance regression detection for CI integration
  • Export capability for performance reports

Related

  • Telemetry sources: packages/core/src/telemetry/
  • DevTools: packages/devtools/

Metadata

Metadata

Assignees

No one assigned

    Labels

    status/need-triageIssues that need to be triaged by the triage automation.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions