Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d9c4e18
feat: enhanced performance monitoring and telemetry infrastructure
eLyiN Jun 27, 2025
45abf5c
fix(telemetry): address security and data integrity issues from code …
eLyiN Jun 29, 2025
3621155
fix(telemetry): resolve additional performance monitoring issues
eLyiN Jun 29, 2025
1a62ef5
fix(telemetry): resolve silent failure issues in monitoring
eLyiN Jun 29, 2025
c1f2713
Update packages/core/src/telemetry/memory-monitor.ts
eLyiN Jun 29, 2025
7673113
feat(telemetry): add granular memory metrics for external and RSS
eLyiN Jun 29, 2025
bd4a137
Update packages/core/src/telemetry/index.ts
eLyiN Jun 29, 2025
0949869
fix(telemetry): refactor MemoryMonitor singleton to avoid config storage
eLyiN Jun 29, 2025
3f48eee
feat(telemetry): add comprehensive documentation and test coverage
eLyiN Jun 29, 2025
0321720
fix(telemetry): export UI telemetry types and services
eLyiN Jul 8, 2025
39b84b8
fix(telemetry): change startup performance metric to accept floating-…
eLyiN Jul 11, 2025
a6312c4
feat(config): initialize config before authentication and UI operations
eLyiN Jul 11, 2025
185a84f
feat(telemetry): add core activity detection system
eLyiN Jul 12, 2025
7df8210
feat(telemetry): implement rate limiting for telemetry recording
eLyiN Jul 12, 2025
5603374
feat(telemetry): add high water mark tracking for memory monitoring
eLyiN Jul 12, 2025
555c783
feat(telemetry): implement activity monitor with event-driven archite…
eLyiN Jul 12, 2025
e9dcb8b
feat(telemetry): enhance memory monitor with activity-driven logic
eLyiN Jul 12, 2025
4386634
feat(cli): integrate activity monitoring into CLI application
eLyiN Jul 12, 2025
a5d0fed
docs(telemetry): document enhanced activity-driven memory monitoring
eLyiN Jul 12, 2025
c89a1d3
fix(activity): resolve activity monitoring functionality issues
eLyiN Jul 15, 2025
87877b6
feat(perf): add trackStartupPerformance utility for cleaner timing code
eLyiN Jul 15, 2025
d768318
refactor(telemetry): simplify high-water mark tracking logic
eLyiN Jul 15, 2025
071cd5d
style(telemetry): clean up memory monitor configuration
eLyiN Jul 15, 2025
fd60e02
test: fix activity monitoring and high-water mark tracker tests
eLyiN Jul 15, 2025
ca91fc7
fix: resolve final code quality issues after successful rebase
eLyiN Aug 21, 2025
5e6f6bd
refactor(memory-monitor): remove measureGarbageCollection method
eLyiN Aug 22, 2025
cfba161
fix: remove extra blank lines in memory monitor files
eLyiN Aug 22, 2025
9e4a476
fix(rebase): resolve conflicts and import type issues after rebase
eLyiN Aug 27, 2025
f72de88
fix(gemini): enhance authentication and theme loading performance met…
eLyiN Sep 6, 2025
06875c6
test: enhance IDE detection and telemetry tests
eLyiN Sep 6, 2025
ea8d831
Merge branch 'main' into feature/enhanced-performance-monitoring
galz10 Sep 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 217 additions & 0 deletions docs/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,104 @@ Use the `npm run telemetry -- --target=gcp` command to automate setting up a loc
1. **Stop the service**:
Press `Ctrl+C` in the terminal where the script is running to stop the OTEL Collector.

## Performance Monitoring

Gemini CLI includes comprehensive performance monitoring capabilities that provide insights into startup performance, memory usage, and operational efficiency. These features help identify performance bottlenecks and track system health over time.

### Memory Monitoring

The integrated MemoryMonitor system provides intelligent, activity-driven memory tracking with automatic snapshots at key lifecycle points. The monitoring system has been enhanced to minimize overhead while maintaining data quality through smart triggering and rate limiting.

#### Activity-Driven Monitoring

Memory monitoring is now **activity-aware**, recording data only when the user is actively using the CLI:

- **Idle Detection**: Monitoring pauses when the user has been inactive for 30 seconds
- **Activity Triggers**: Memory snapshots are triggered by specific user activities:
- User input start/end events
- Stream operations (start/end)
- Tool call scheduling and completion
- Message additions to history
- **Smart Frequency**: Base monitoring occurs every 10 seconds (reduced from 5 seconds), but actual recording depends on activity and growth patterns

#### High Water Mark Tracking

The system uses intelligent high water mark detection to reduce noise and focus on significant memory growth:

- **Growth Threshold**: Only records memory snapshots when usage increases by 5% or more compared to the previous maximum
- **Smoothing Algorithm**: Uses a 3-sample weighted average to filter out garbage collection noise
- **Separate Tracking**: Maintains independent high water marks for different memory types (RSS, heap used, heap total)
- **Growth Analysis**: Identifies genuine memory leaks while ignoring temporary spikes

#### Rate Limiting

To respect system resources and user experience, the monitoring system includes comprehensive rate limiting:

- **Standard Interval**: Maximum one memory recording per minute for normal monitoring
- **High-Priority Events**: Critical events (potential memory leaks) are limited to once every 30 seconds
- **Per-Metric Limiting**: Each memory metric type has independent rate limiting
- **Context-Aware**: Different monitoring contexts (startup, periodic, activity-triggered) have separate rate limits

#### Memory Metrics Tracked

The memory monitor automatically tracks:

- **Heap Usage**: V8 JavaScript heap memory (used and total allocated)
- **External Memory**: Memory used by C++ objects bound to JavaScript
- **RSS (Resident Set Size)**: Physical memory currently used by the process
- **Array Buffers**: Memory used by ArrayBuffer objects
- **Heap Size Limit**: Maximum heap size allowed by V8

#### Configuration Options

The enhanced memory monitoring system supports configuration through the activity monitoring system:

```json
{
"activityMonitoring": {
"enabled": true,
"snapshotThrottleMs": 1000,
"maxEventBuffer": 100,
"triggerActivities": [
"user_input_start",
"message_added",
"tool_call_scheduled",
"stream_start"
]
}
}
```

#### Performance Impact

The enhanced monitoring system significantly reduces telemetry overhead:

- **Frequency Reduction**: ~80-90% reduction in memory recordings compared to continuous monitoring
- **Activity Gating**: Zero recordings during inactive periods
- **Smart Triggering**: Only records when meaningful changes occur
- **Resource Efficiency**: Minimal CPU and memory overhead for tracking logic

### Performance Scoring and Regression Detection

The performance monitoring system includes automated scoring and regression detection:

- **Baseline comparison**: Compares current performance against established baselines
- **Regression detection**: Automatically identifies performance degradations with configurable severity levels
- **Efficiency metrics**: Tracks token usage efficiency and API request optimization
- **Performance scoring**: Provides composite performance scores (0-100 scale) across different system components

### Startup Performance Analysis

Detailed startup timing analysis breaks down CLI initialization into measurable phases:

- **Settings loading**: Time to load and validate configuration files
- **Extension loading**: Time to discover and initialize CLI extensions
- **Service initialization**: Time to set up file, git, and authentication services
- **Authentication**: Time to validate and refresh authentication credentials
- **Sandbox setup**: Time to configure and enter sandbox environments (when enabled)

This granular timing data helps identify startup bottlenecks and track performance improvements over time.

## Logs and metric reference

The following section describes the structure of logs and metrics generated for Gemini CLI.
Expand Down Expand Up @@ -250,6 +348,46 @@ Logs are timestamped records of specific events. The following events are logged
- `command` (string)
- `subcommand` (string, if applicable)

- `gemini_cli.startup.performance`: This event occurs during CLI startup with detailed performance metrics.
- **Attributes**:
- `phase` (string): Specific startup phase (settings_loading, config_loading, authentication, etc.)
- `startup_duration_ms` (number): Duration of the startup phase
- `auth_type` (string): Authentication method used (if applicable)
- `telemetry_enabled` (boolean): Whether telemetry was enabled during startup
- `settings_sources` (number): Number of settings sources processed (if applicable)
- `errors_count` (number): Number of errors encountered during phase (if applicable)
- `extensions_count` (number): Number of extensions loaded (if applicable)
- `theme_name` (string): Theme name loaded (if applicable)
- `sandbox_command` (string): Sandbox command executed (if applicable)
- `is_tty` (boolean): Whether running in TTY mode (if applicable)
- `has_question` (boolean): Whether input question was provided (if applicable)

- `gemini_cli.memory.usage`: This event occurs during memory monitoring snapshots.
- **Attributes**:
- `context` (string): Context that triggered the memory snapshot
- `heap_used_mb` (number): V8 heap memory in use (megabytes)
- `heap_total_mb` (number): Total V8 heap allocated (megabytes)
- `rss_mb` (number): Resident Set Size (megabytes)
- `external_mb` (number): External memory usage (megabytes)
- `array_buffers_mb` (number): Array buffer memory usage (megabytes)
- `heap_size_limit_mb` (number): V8 heap size limit (megabytes)

- `gemini_cli.performance.baseline`: This event occurs when establishing performance baselines.
- **Attributes**:
- `metric_type` (string): Type of performance metric being baselined
- `baseline_value` (number): Established baseline value
- `confidence_level` (number): Statistical confidence in baseline
- `component` (string): Component being monitored

- `gemini_cli.performance.regression`: This event occurs when performance regression is detected.
- **Attributes**:
- `metric_type` (string): Type of performance metric that regressed
- `current_value` (number): Current performance value
- `baseline_value` (number): Expected baseline value
- `regression_percentage` (number): Percentage of performance degradation
- `severity` (string): Regression severity level (low, medium, high)
- `component` (string): Component experiencing regression

### Metrics

Metrics are numerical measurements of behavior over time. The following metrics are collected for Gemini CLI:
Expand Down Expand Up @@ -299,3 +437,82 @@ Metrics are numerical measurements of behavior over time. The following metrics
- **Attributes**:
- `tokens_before`: (Int): Number of tokens in context prior to compression
- `tokens_after`: (Int): Number of tokens in context after compression

- `gemini_cli.startup.duration` (Histogram, ms): Measures CLI startup time with phase breakdown.
- **Attributes**:
- `phase` (string): Specific startup phase (settings_loading, config_loading, authentication, etc.)
- `auth_type` (string): Authentication method used (if applicable)
- `telemetry_enabled` (boolean): Whether telemetry was enabled during startup
- `settings_sources` (number): Number of settings sources processed (if applicable)
- `errors_count` (number): Number of errors encountered during phase (if applicable)
- `extensions_count` (number): Number of extensions loaded (if applicable)
- `theme_name` (string): Theme name loaded (if applicable)
- `sandbox_command` (string): Sandbox command executed (if applicable)
- `is_tty` (boolean): Whether running in TTY mode (if applicable)
- `has_question` (boolean): Whether input question was provided (if applicable)

- `gemini_cli.memory.usage` (Histogram, bytes): General memory usage measurement.
- **Attributes**:
- `component` (string): CLI component being monitored
- `memory_type` (string): Type of memory metric (general usage)

- `gemini_cli.memory.heap.used` (Histogram, bytes): V8 heap memory currently in use.
- **Attributes**:
- `component` (string): CLI component being monitored
- `memory_type` (string): "heap_used"

- `gemini_cli.memory.heap.total` (Histogram, bytes): Total V8 heap memory allocated.
- **Attributes**:
- `component` (string): CLI component being monitored
- `memory_type` (string): "heap_total"

- `gemini_cli.memory.external` (Histogram, bytes): Memory usage of C++ objects bound to JavaScript.
- **Attributes**:
- `component` (string): CLI component being monitored
- `memory_type` (string): "external"

- `gemini_cli.memory.rss` (Histogram, bytes): Resident Set Size - physical memory currently used.
- **Attributes**:
- `component` (string): CLI component being monitored
- `memory_type` (string): "rss"

- `gemini_cli.cpu.usage` (Histogram, percent): CPU usage percentage by component.
- **Attributes**:
- `component` (string): CLI component being monitored

- `gemini_cli.tool.queue.depth` (Histogram, Int): Number of tool calls waiting in execution queue.

- `gemini_cli.tool.execution.breakdown` (Histogram, ms): Detailed timing of tool execution phases.
- **Attributes**:
- `function_name` (string): Name of the tool being executed
- `phase` (string): Execution phase (validation, preparation, execution, result_processing)

- `gemini_cli.token.efficiency` (Histogram, double): Token efficiency metrics including ratios and cache hit rates.
- **Attributes**:
- `model` (string): Gemini model used
- `metric` (string): Type of efficiency metric being measured
- `context` (string): Context for the efficiency measurement

- `gemini_cli.api.request.breakdown` (Histogram, ms): Detailed API request timing by processing phase.
- **Attributes**:
- `model` (string): Gemini model used
- `phase` (string): Request phase (request_preparation, network_latency, response_processing, token_processing)

- `gemini_cli.performance.score` (Histogram, double): Overall performance score (0-100 scale).
- **Attributes**:
- `category` (string): Performance category being scored
- `baseline` (number): Baseline value for comparison (if applicable)

- `gemini_cli.performance.regression` (Counter, Int): Count of detected performance regressions.
- **Attributes**:
- `metric` (string): Performance metric that regressed
- `severity` (string): Regression severity level (low, medium, high)
- `current_value` (number): Current performance value
- `baseline_value` (number): Expected baseline value

- `gemini_cli.performance.baseline.comparison` (Histogram, percent): Performance comparison to established baseline (percentage change).
- **Attributes**:
- `metric` (string): Type of performance metric being compared
- `category` (string): Performance category
- `current_value` (number): Current performance value
- `baseline_value` (number): Baseline performance value
42 changes: 22 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
"yargs": "^17.7.2"
},
"dependencies": {
"@lvce-editor/ripgrep": "^1.6.0",
"mime": "^4.0.7",
"simple-git": "^3.28.0"
},
"optionalDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/gemini.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ describe('gemini.tsx main function kitty protocol', () => {
getExperimentalZedIntegration: () => false,
getScreenReader: () => false,
getGeminiMdFileCount: () => 0,
getFileService: vi.fn(() => ({})),
getCheckpointingEnabled: vi.fn(() => false),
} as unknown as Config);
vi.mocked(loadSettings).mockReturnValue({
errors: [],
Expand Down
Loading
Loading