Skip to content

Add shutdown performance profiling summary#20911

Closed
dchen024 wants to merge 1 commit intogoogle-gemini:mainfrom
dchen024:codex/shutdown-perf-summary
Closed

Add shutdown performance profiling summary#20911
dchen024 wants to merge 1 commit intogoogle-gemini:mainfrom
dchen024:codex/shutdown-perf-summary

Conversation

@dchen024
Copy link
Copy Markdown

@dchen024 dchen024 commented Mar 3, 2026

Summary

  • add shutdown performance sections to session summary: Throughput, Startup, Tool Profiling, and Model API Performance
  • plumb startup phase and wall-time telemetry into quit history so shutdown rendering can compute performance metrics
  • refactor tool profiling into a compact table with category grouping by MCP server and per-tool avg/total/calls/success columns
  • update README with a feature bullet for shutdown performance insights

Example

Screenshot 2026-03-02 at 8 49 36 PM

Testing

  • npm run test --workspace @google/gemini-cli -- src/ui/commands/quitCommand.test.ts src/ui/components/SessionSummaryDisplay.test.tsx src/ui/components/HistoryItemDisplay.test.tsx src/ui/components/StatsDisplay.test.tsx

@dchen024 dchen024 requested review from a team as code owners March 3, 2026 01:51
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the user experience by introducing detailed performance metrics upon session shutdown. Users can now gain valuable insights into the throughput, startup times, tool usage, and model API performance of their sessions, facilitating better understanding and optimization of their interactions with the CLI. The changes involve plumbing telemetry data through the application and rendering it in a user-friendly, structured format.

Highlights

  • Enhanced Session Summary: Added new sections to the session summary display, including Throughput, Startup, Tool Profiling, and Model API Performance, providing comprehensive insights into session shutdown performance.
  • Telemetry Integration: Integrated startup phase and wall-time telemetry into the quit history, enabling the computation and display of detailed performance metrics during session shutdown.
  • Refactored Tool Profiling: Improved the tool profiling display by presenting it in a compact table format, with category grouping by MCP server and columns for average/total duration, calls, and success rates per tool.
  • Documentation Update: Updated the README.md file to highlight the new session shutdown performance insights feature.
Changelog
  • README.md
    • Updated README with a new feature bullet point for session shutdown performance insights.
  • packages/cli/src/ui/commands/quitCommand.test.ts
    • Imported startupProfiler from @google/gemini-cli-core.
    • Spied on startupProfiler.getLastStartupStats to mock its return value in tests.
    • Updated the expected QuitActionReturn object to include wallTimeMs and startupPhases.
  • packages/cli/src/ui/commands/quitCommand.ts
    • Imported startupProfiler from @google/gemini-cli-core.
    • Retrieved startup phase metrics using startupProfiler.getLastStartupStats().
    • Added wallTimeMs and startupPhases to the QuitActionReturn object returned by the quit command.
  • packages/cli/src/ui/components/HistoryItemDisplay.tsx
    • Modified SessionSummaryDisplay component to accept wallTimeMs and startupPhases as props when rendering a 'quit' history item.
  • packages/cli/src/ui/components/SessionSummaryDisplay.tsx
    • Added wallTimeMs and startupPhases to SessionSummaryDisplayProps interface.
    • Passed wallTimeMs, startupPhases, and a new showPerformanceProfile prop to the StatsDisplay component.
  • packages/cli/src/ui/components/StatsDisplay.tsx
    • Imported DiscoveredMCPTool and StartupPhaseMetric types.
    • Defined new interfaces for ToolProfileSummary.
    • Added helper functions getPerMinuteRate, formatPhaseName, splitToolName, and getToolCategorization for performance calculations and formatting.
    • Updated StatsDisplayProps to include optional wallTimeMs, startupPhases, and showPerformanceProfile.
    • Implemented logic to calculate and display 'Throughput', 'Startup', 'Tool Profiling', and 'Model API Performance' sections based on provided performance data.
    • Refactored tool profiling into a categorized and sortable table display.
  • packages/cli/src/ui/hooks/slashCommandProcessor.ts
    • Updated the historyItemContent for MessageType.QUIT to include wallTimeMs and startupPhases from the incoming message.
  • packages/cli/src/ui/types.ts
    • Defined a new interface StartupPhaseMetric to represent startup phase name and duration.
    • Added optional wallTimeMs and startupPhases properties to the HistoryItemQuit type.
    • Added optional wallTimeMs and startupPhases properties to the MessageType.QUIT in the Message union type.
  • packages/core/src/telemetry/startupProfiler.ts
    • Added a private member lastFlushedPhases to store the last set of startup phases.
    • Updated the flush method to store the startupPhases in lastFlushedPhases before logging.
    • Implemented a new public method getLastStartupStats() to retrieve the stored lastFlushedPhases.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a performance summary on session shutdown, which is a great addition for providing developers with valuable insights. The implementation is solid, plumbing startup and wall-time metrics through to the UI and refactoring the tool profiling into a more compact and informative table. I've identified a couple of areas for improvement in the new StatsDisplay component to enhance the clarity and usefulness of the presented data. Specifically, I'm suggesting a change to how MCP tool names are displayed to avoid redundancy and to sort the model performance data to make it easier to interpret.

): { category: string; toolCall: string } => {
const tool = config.getToolRegistry()?.getTool(toolName);
if (tool instanceof DiscoveredMCPTool) {
return { category: tool.serverName, toolCall: toolName };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

For better clarity in the tool profiling summary, it's better to display the original tool name from the MCP server (serverToolName) instead of the potentially qualified toolName from the registry. This avoids redundancy where the category (server name) might be repeated in the tool call column.

Suggested change
return { category: tool.serverName, toolCall: toolName };
return { category: tool.serverName, toolCall: tool.serverToolName };

Comment on lines +546 to +563
const modelPerformanceRows = Object.entries(models)
.filter(([, modelMetrics]) => modelMetrics.api.totalRequests > 0)
.map(([modelName, modelMetrics]) => {
const requests = modelMetrics.api.totalRequests;
const errors = modelMetrics.api.totalErrors;
const errorRate = requests > 0 ? (errors / requests) * 100 : 0;
const avgLatencyMs =
requests > 0 ? modelMetrics.api.totalLatencyMs / requests : 0;

return {
modelKey: modelName,
modelName: getDisplayString(modelName.replace('-001', '')),
requests,
errors,
errorRate,
avgLatencyMs,
};
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The modelPerformanceRows array is not sorted. To improve the readability and usefulness of the "Model API Performance" summary, it would be beneficial to sort this data. Sorting by the number of requests in descending order would be a good approach, as it highlights the most frequently used models first.

Suggested change
const modelPerformanceRows = Object.entries(models)
.filter(([, modelMetrics]) => modelMetrics.api.totalRequests > 0)
.map(([modelName, modelMetrics]) => {
const requests = modelMetrics.api.totalRequests;
const errors = modelMetrics.api.totalErrors;
const errorRate = requests > 0 ? (errors / requests) * 100 : 0;
const avgLatencyMs =
requests > 0 ? modelMetrics.api.totalLatencyMs / requests : 0;
return {
modelKey: modelName,
modelName: getDisplayString(modelName.replace('-001', '')),
requests,
errors,
errorRate,
avgLatencyMs,
};
});
const modelPerformanceRows = Object.entries(models)
.filter(([, modelMetrics]) => modelMetrics.api.totalRequests > 0)
.map(([modelName, modelMetrics]) => {
const requests = modelMetrics.api.totalRequests;
const errors = modelMetrics.api.totalErrors;
const errorRate = requests > 0 ? (errors / requests) * 100 : 0;
const avgLatencyMs =
requests > 0 ? modelMetrics.api.totalLatencyMs / requests : 0;
return {
modelKey: modelName,
modelName: getDisplayString(modelName.replace('-001', '')),
requests,
errors,
errorRate,
avgLatencyMs,
};
})
.sort((a, b) => b.requests - a.requests);

@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Mar 3, 2026
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli Bot commented Mar 3, 2026

Hi there! Thank you for your contribution to Gemini CLI.

To improve our contribution process and better track changes, we now require all pull requests to be associated with an existing issue, as announced in our recent discussion and as detailed in our CONTRIBUTING.md.

This pull request is being closed because it is not currently linked to an issue. Once you have updated the description of this PR to link an issue (e.g., by adding Fixes #123 or Related to #123), it will be automatically reopened.

How to link an issue:
Add a keyword followed by the issue number (e.g., Fixes #123) in the description of your pull request. For more details on supported keywords and how linking works, please refer to the GitHub Documentation on linking pull requests to issues.

Thank you for your understanding and for being a part of our community!

@gemini-cli gemini-cli Bot closed this Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant