mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-07 03:40:36 -07:00
[Part 4/6] feat(telemetry): add memory monitor with activity-aware recording and tests (#8122)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
31
packages/core/src/utils/formatters.test.ts
Normal file
31
packages/core/src/utils/formatters.test.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
import { bytesToMB, formatMemoryUsage } from './formatters.js';
|
||||
|
||||
describe('bytesToMB', () => {
|
||||
it('converts bytes to megabytes', () => {
|
||||
expect(bytesToMB(0)).toBe(0);
|
||||
expect(bytesToMB(512 * 1024)).toBeCloseTo(0.5, 5);
|
||||
expect(bytesToMB(5 * 1024 * 1024)).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatMemoryUsage', () => {
|
||||
it('formats values below one megabyte in KB', () => {
|
||||
expect(formatMemoryUsage(512 * 1024)).toBe('512.0 KB');
|
||||
});
|
||||
|
||||
it('formats values below one gigabyte in MB', () => {
|
||||
expect(formatMemoryUsage(5 * 1024 * 1024)).toBe('5.0 MB');
|
||||
});
|
||||
|
||||
it('formats values of one gigabyte or larger in GB', () => {
|
||||
expect(formatMemoryUsage(2 * 1024 * 1024 * 1024)).toBe('2.00 GB');
|
||||
});
|
||||
});
|
||||
@@ -4,13 +4,15 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
export const bytesToMB = (bytes: number): number => bytes / (1024 * 1024);
|
||||
|
||||
export const formatMemoryUsage = (bytes: number): string => {
|
||||
const gb = bytes / (1024 * 1024 * 1024);
|
||||
if (bytes < 1024 * 1024) {
|
||||
return `${(bytes / 1024).toFixed(1)} KB`;
|
||||
}
|
||||
if (bytes < 1024 * 1024 * 1024) {
|
||||
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
||||
return `${bytesToMB(bytes).toFixed(1)} MB`;
|
||||
}
|
||||
return `${gb.toFixed(2)} GB`;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user