mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-30 15:04:16 -07:00
refactor: rename formatMemoryUsage to formatBytes (#14997)
Co-authored-by: Adib234 <30782825+Adib234@users.noreply.github.com>
This commit is contained in:
@@ -11,7 +11,7 @@ import { bugCommand } from './bugCommand.js';
|
|||||||
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
|
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
|
||||||
import { getVersion } from '@google/gemini-cli-core';
|
import { getVersion } from '@google/gemini-cli-core';
|
||||||
import { GIT_COMMIT_INFO } from '../../generated/git-commit.js';
|
import { GIT_COMMIT_INFO } from '../../generated/git-commit.js';
|
||||||
import { formatMemoryUsage } from '../utils/formatters.js';
|
import { formatBytes } from '../utils/formatters.js';
|
||||||
|
|
||||||
// Mock dependencies
|
// Mock dependencies
|
||||||
vi.mock('open');
|
vi.mock('open');
|
||||||
@@ -68,7 +68,7 @@ vi.mock('../utils/terminalCapabilityManager.js', () => ({
|
|||||||
describe('bugCommand', () => {
|
describe('bugCommand', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.mocked(getVersion).mockResolvedValue('0.1.0');
|
vi.mocked(getVersion).mockResolvedValue('0.1.0');
|
||||||
vi.mocked(formatMemoryUsage).mockReturnValue('100 MB');
|
vi.mocked(formatBytes).mockReturnValue('100 MB');
|
||||||
vi.stubEnv('SANDBOX', 'gemini-test');
|
vi.stubEnv('SANDBOX', 'gemini-test');
|
||||||
vi.useFakeTimers();
|
vi.useFakeTimers();
|
||||||
vi.setSystemTime(new Date('2024-01-01T00:00:00Z'));
|
vi.setSystemTime(new Date('2024-01-01T00:00:00Z'));
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
} from './types.js';
|
} from './types.js';
|
||||||
import { MessageType } from '../types.js';
|
import { MessageType } from '../types.js';
|
||||||
import { GIT_COMMIT_INFO } from '../../generated/git-commit.js';
|
import { GIT_COMMIT_INFO } from '../../generated/git-commit.js';
|
||||||
import { formatMemoryUsage } from '../utils/formatters.js';
|
import { formatBytes } from '../utils/formatters.js';
|
||||||
import {
|
import {
|
||||||
IdeClient,
|
IdeClient,
|
||||||
sessionId,
|
sessionId,
|
||||||
@@ -45,7 +45,7 @@ export const bugCommand: SlashCommand = {
|
|||||||
}
|
}
|
||||||
const modelVersion = config?.getModel() || 'Unknown';
|
const modelVersion = config?.getModel() || 'Unknown';
|
||||||
const cliVersion = await getVersion();
|
const cliVersion = await getVersion();
|
||||||
const memoryUsage = formatMemoryUsage(process.memoryUsage().rss);
|
const memoryUsage = formatBytes(process.memoryUsage().rss);
|
||||||
const ideClient = await getIdeClientName(context);
|
const ideClient = await getIdeClientName(context);
|
||||||
const terminalName =
|
const terminalName =
|
||||||
terminalCapabilityManager.getTerminalName() || 'Unknown';
|
terminalCapabilityManager.getTerminalName() || 'Unknown';
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { useEffect, useState } from 'react';
|
|||||||
import { Box, Text } from 'ink';
|
import { Box, Text } from 'ink';
|
||||||
import { theme } from '../semantic-colors.js';
|
import { theme } from '../semantic-colors.js';
|
||||||
import process from 'node:process';
|
import process from 'node:process';
|
||||||
import { formatMemoryUsage } from '../utils/formatters.js';
|
import { formatBytes } from '../utils/formatters.js';
|
||||||
|
|
||||||
export const MemoryUsageDisplay: React.FC = () => {
|
export const MemoryUsageDisplay: React.FC = () => {
|
||||||
const [memoryUsage, setMemoryUsage] = useState<string>('');
|
const [memoryUsage, setMemoryUsage] = useState<string>('');
|
||||||
@@ -20,7 +20,7 @@ export const MemoryUsageDisplay: React.FC = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const updateMemory = () => {
|
const updateMemory = () => {
|
||||||
const usage = process.memoryUsage().rss;
|
const usage = process.memoryUsage().rss;
|
||||||
setMemoryUsage(formatMemoryUsage(usage));
|
setMemoryUsage(formatBytes(usage));
|
||||||
setMemoryUsageColor(
|
setMemoryUsageColor(
|
||||||
usage >= 2 * 1024 * 1024 * 1024
|
usage >= 2 * 1024 * 1024 * 1024
|
||||||
? theme.status.error
|
? theme.status.error
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import { isBinary, ShellExecutionService } from '@google/gemini-cli-core';
|
|||||||
import { type PartListUnion } from '@google/genai';
|
import { type PartListUnion } from '@google/genai';
|
||||||
import type { UseHistoryManagerReturn } from './useHistoryManager.js';
|
import type { UseHistoryManagerReturn } from './useHistoryManager.js';
|
||||||
import { SHELL_COMMAND_NAME } from '../constants.js';
|
import { SHELL_COMMAND_NAME } from '../constants.js';
|
||||||
import { formatMemoryUsage } from '../utils/formatters.js';
|
import { formatBytes } from '../utils/formatters.js';
|
||||||
import crypto from 'node:crypto';
|
import crypto from 'node:crypto';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
@@ -192,7 +192,7 @@ export const useShellCommandProcessor = (
|
|||||||
let currentDisplayOutput: string | AnsiOutput;
|
let currentDisplayOutput: string | AnsiOutput;
|
||||||
if (isBinaryStream) {
|
if (isBinaryStream) {
|
||||||
if (binaryBytesReceived > 0) {
|
if (binaryBytesReceived > 0) {
|
||||||
currentDisplayOutput = `[Receiving binary output... ${formatMemoryUsage(
|
currentDisplayOutput = `[Receiving binary output... ${formatBytes(
|
||||||
binaryBytesReceived,
|
binaryBytesReceived,
|
||||||
)} received]`;
|
)} received]`;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -7,23 +7,23 @@
|
|||||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||||
import {
|
import {
|
||||||
formatDuration,
|
formatDuration,
|
||||||
formatMemoryUsage,
|
formatBytes,
|
||||||
formatTimeAgo,
|
formatTimeAgo,
|
||||||
stripReferenceContent,
|
stripReferenceContent,
|
||||||
} from './formatters.js';
|
} from './formatters.js';
|
||||||
|
|
||||||
describe('formatters', () => {
|
describe('formatters', () => {
|
||||||
describe('formatMemoryUsage', () => {
|
describe('formatBytes', () => {
|
||||||
it('should format bytes into KB', () => {
|
it('should format bytes into KB', () => {
|
||||||
expect(formatMemoryUsage(12345)).toBe('12.1 KB');
|
expect(formatBytes(12345)).toBe('12.1 KB');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format bytes into MB', () => {
|
it('should format bytes into MB', () => {
|
||||||
expect(formatMemoryUsage(12345678)).toBe('11.8 MB');
|
expect(formatBytes(12345678)).toBe('11.8 MB');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format bytes into GB', () => {
|
it('should format bytes into GB', () => {
|
||||||
expect(formatMemoryUsage(12345678901)).toBe('11.50 GB');
|
expect(formatBytes(12345678901)).toBe('11.50 GB');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
REFERENCE_CONTENT_END,
|
REFERENCE_CONTENT_END,
|
||||||
} from '@google/gemini-cli-core';
|
} from '@google/gemini-cli-core';
|
||||||
|
|
||||||
export const formatMemoryUsage = (bytes: number): string => {
|
export const formatBytes = (bytes: number): string => {
|
||||||
const gb = bytes / (1024 * 1024 * 1024);
|
const gb = bytes / (1024 * 1024 * 1024);
|
||||||
if (bytes < 1024 * 1024) {
|
if (bytes < 1024 * 1024) {
|
||||||
return `${(bytes / 1024).toFixed(1)} KB`;
|
return `${(bytes / 1024).toFixed(1)} KB`;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import type {
|
|||||||
ShellOutputEvent,
|
ShellOutputEvent,
|
||||||
} from '../services/shellExecutionService.js';
|
} from '../services/shellExecutionService.js';
|
||||||
import { ShellExecutionService } from '../services/shellExecutionService.js';
|
import { ShellExecutionService } from '../services/shellExecutionService.js';
|
||||||
import { formatMemoryUsage } from '../utils/formatters.js';
|
import { formatBytes } from '../utils/formatters.js';
|
||||||
import type { AnsiOutput } from '../utils/terminalSerializer.js';
|
import type { AnsiOutput } from '../utils/terminalSerializer.js';
|
||||||
import {
|
import {
|
||||||
getCommandRoots,
|
getCommandRoots,
|
||||||
@@ -231,7 +231,7 @@ export class ShellToolInvocation extends BaseToolInvocation<
|
|||||||
break;
|
break;
|
||||||
case 'binary_progress':
|
case 'binary_progress':
|
||||||
isBinaryStream = true;
|
isBinaryStream = true;
|
||||||
cumulativeOutput = `[Receiving binary output... ${formatMemoryUsage(
|
cumulativeOutput = `[Receiving binary output... ${formatBytes(
|
||||||
event.bytesReceived,
|
event.bytesReceived,
|
||||||
)} received]`;
|
)} received]`;
|
||||||
if (Date.now() - lastUpdateTime > OUTPUT_UPDATE_INTERVAL_MS) {
|
if (Date.now() - lastUpdateTime > OUTPUT_UPDATE_INTERVAL_MS) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
|
|
||||||
import { bytesToMB, formatMemoryUsage } from './formatters.js';
|
import { bytesToMB, formatBytes } from './formatters.js';
|
||||||
|
|
||||||
describe('bytesToMB', () => {
|
describe('bytesToMB', () => {
|
||||||
it('converts bytes to megabytes', () => {
|
it('converts bytes to megabytes', () => {
|
||||||
@@ -16,16 +16,16 @@ describe('bytesToMB', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('formatMemoryUsage', () => {
|
describe('formatBytes', () => {
|
||||||
it('formats values below one megabyte in KB', () => {
|
it('formats values below one megabyte in KB', () => {
|
||||||
expect(formatMemoryUsage(512 * 1024)).toBe('512.0 KB');
|
expect(formatBytes(512 * 1024)).toBe('512.0 KB');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('formats values below one gigabyte in MB', () => {
|
it('formats values below one gigabyte in MB', () => {
|
||||||
expect(formatMemoryUsage(5 * 1024 * 1024)).toBe('5.0 MB');
|
expect(formatBytes(5 * 1024 * 1024)).toBe('5.0 MB');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('formats values of one gigabyte or larger in GB', () => {
|
it('formats values of one gigabyte or larger in GB', () => {
|
||||||
expect(formatMemoryUsage(2 * 1024 * 1024 * 1024)).toBe('2.00 GB');
|
expect(formatBytes(2 * 1024 * 1024 * 1024)).toBe('2.00 GB');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
export const bytesToMB = (bytes: number): number => bytes / (1024 * 1024);
|
export const bytesToMB = (bytes: number): number => bytes / (1024 * 1024);
|
||||||
|
|
||||||
export const formatMemoryUsage = (bytes: number): string => {
|
export const formatBytes = (bytes: number): string => {
|
||||||
const gb = bytes / (1024 * 1024 * 1024);
|
const gb = bytes / (1024 * 1024 * 1024);
|
||||||
if (bytes < 1024 * 1024) {
|
if (bytes < 1024 * 1024) {
|
||||||
return `${(bytes / 1024).toFixed(1)} KB`;
|
return `${(bytes / 1024).toFixed(1)} KB`;
|
||||||
|
|||||||
Reference in New Issue
Block a user