feat: add --show_memory_usage flag to display memory usage in status bar (#606)

This commit is contained in:
Jacob Richman
2025-05-30 22:18:01 +00:00
committed by GitHub
parent 3291ffbe09
commit 01768d7759
10 changed files with 205 additions and 12 deletions

View File

@@ -9,6 +9,8 @@ import { Box, Text } from 'ink';
import { Colors } from '../colors.js';
import { shortenPath, tildeifyPath } from '@gemini-code/server';
import { ConsoleSummaryDisplay } from './ConsoleSummaryDisplay.js';
import process from 'node:process';
import { MemoryUsageDisplay } from './MemoryUsageDisplay.js';
interface FooterProps {
model: string;
@@ -20,6 +22,7 @@ interface FooterProps {
corgiMode: boolean;
errorCount: number;
showErrorDetails: boolean;
showMemoryUsage?: boolean;
}
export const Footer: React.FC<FooterProps> = ({
@@ -31,6 +34,7 @@ export const Footer: React.FC<FooterProps> = ({
corgiMode,
errorCount,
showErrorDetails,
showMemoryUsage,
}) => (
<Box marginTop={1} justifyContent="space-between" width="100%">
<Box>
@@ -86,6 +90,7 @@ export const Footer: React.FC<FooterProps> = ({
<ConsoleSummaryDisplay errorCount={errorCount} />
</Box>
)}
{showMemoryUsage && <MemoryUsageDisplay />}
</Box>
</Box>
);

View File

@@ -0,0 +1,40 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import React, { useEffect, useState } from 'react';
import { Box, Text } from 'ink';
import { Colors } from '../colors.js';
import process from 'node:process';
import { formatMemoryUsage } from '../utils/formatters.js';
export const MemoryUsageDisplay: React.FC = () => {
const [memoryUsage, setMemoryUsage] = useState<string>('');
const [memoryUsageColor, setMemoryUsageColor] = useState<string>(
Colors.SubtleComment,
);
useEffect(() => {
const updateMemory = () => {
const usage = process.memoryUsage().rss;
setMemoryUsage(formatMemoryUsage(usage));
setMemoryUsageColor(
usage >= 2 * 1024 * 1024 * 1024
? Colors.AccentRed
: Colors.SubtleComment,
);
};
const intervalId = setInterval(updateMemory, 2000);
updateMemory(); // Initial update
return () => clearInterval(intervalId);
}, []);
return (
<Box>
<Text color={Colors.SubtleComment}>| </Text>
<Text color={memoryUsageColor}>{memoryUsage}</Text>
</Box>
);
};