mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-26 04:54:25 -07:00
feat(test): add high-volume shell test and refine perf harness (#24983)
This commit is contained in:
+15
-13
@@ -1,24 +1,26 @@
|
||||
{
|
||||
"version": 1,
|
||||
"updatedAt": "2026-04-08T18:51:29.839Z",
|
||||
"updatedAt": "2026-04-09T02:30:22.000Z",
|
||||
"scenarios": {
|
||||
"cold-startup-time": {
|
||||
"wallClockMs": 1333.4230420000004,
|
||||
"cpuTotalUs": 1711,
|
||||
"eventLoopDelayP99Ms": 0,
|
||||
"timestamp": "2026-04-08T18:50:58.124Z"
|
||||
"wallClockMs": 927.553249999999,
|
||||
"cpuTotalUs": 1470,
|
||||
"timestamp": "2026-04-08T22:27:54.871Z"
|
||||
},
|
||||
"idle-cpu-usage": {
|
||||
"wallClockMs": 5001.926125,
|
||||
"cpuTotalUs": 128518,
|
||||
"eventLoopDelayP99Ms": 12.705791,
|
||||
"timestamp": "2026-04-08T18:51:23.938Z"
|
||||
"wallClockMs": 5000.460750000002,
|
||||
"cpuTotalUs": 12157,
|
||||
"timestamp": "2026-04-08T22:28:19.098Z"
|
||||
},
|
||||
"skill-loading-time": {
|
||||
"wallClockMs": 1372.4463749999995,
|
||||
"cpuTotalUs": 1550,
|
||||
"eventLoopDelayP99Ms": 0,
|
||||
"timestamp": "2026-04-08T18:51:29.839Z"
|
||||
"wallClockMs": 930.0920409999962,
|
||||
"cpuTotalUs": 1323,
|
||||
"timestamp": "2026-04-08T22:28:23.290Z"
|
||||
},
|
||||
"high-volume-shell-output": {
|
||||
"wallClockMs": 1119.9,
|
||||
"cpuTotalUs": 2100,
|
||||
"timestamp": "2026-04-09T02:30:22.000Z"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { describe, it, beforeAll, afterAll } from 'vitest';
|
||||
import { TestRig, PerfTestHarness } from '@google/gemini-cli-test-utils';
|
||||
import { join, dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const BASELINES_PATH = join(__dirname, 'baselines.json');
|
||||
@@ -33,7 +34,7 @@ describe('CPU Performance Tests', () => {
|
||||
afterAll(async () => {
|
||||
// Generate the summary report after all tests
|
||||
await harness.generateReport();
|
||||
});
|
||||
}, 30000);
|
||||
|
||||
it('cold-startup-time: startup completes within baseline', async () => {
|
||||
const result = await harness.runScenario('cold-startup-time', async () => {
|
||||
@@ -150,4 +151,119 @@ describe('CPU Performance Tests', () => {
|
||||
harness.assertWithinBaseline(result);
|
||||
}
|
||||
});
|
||||
|
||||
it('high-volume-shell-output: handles large output efficiently', async () => {
|
||||
const result = await harness.runScenario(
|
||||
'high-volume-shell-output',
|
||||
async () => {
|
||||
const rig = new TestRig();
|
||||
try {
|
||||
rig.setup('perf-high-volume-output', {
|
||||
fakeResponsesPath: join(__dirname, 'perf.high-volume.responses'),
|
||||
});
|
||||
|
||||
const snapshot = await harness.measureWithEventLoop(
|
||||
'high-volume-output',
|
||||
async () => {
|
||||
const runResult = await rig.run({
|
||||
args: ['Generate 1M lines of output'],
|
||||
timeout: 120000,
|
||||
env: {
|
||||
GEMINI_API_KEY: 'fake-perf-test-key',
|
||||
GEMINI_TELEMETRY_ENABLED: 'true',
|
||||
GEMINI_MEMORY_MONITOR_INTERVAL: '500',
|
||||
GEMINI_EVENT_LOOP_MONITOR_ENABLED: 'true',
|
||||
DEBUG: 'true',
|
||||
},
|
||||
});
|
||||
console.log(` Child Process Output:`, runResult);
|
||||
},
|
||||
);
|
||||
|
||||
// Query CLI's own performance metrics from telemetry logs
|
||||
await rig.waitForTelemetryReady();
|
||||
|
||||
// Debug: Read and log the telemetry file content
|
||||
try {
|
||||
const logFilePath = join(rig.homeDir!, 'telemetry.log');
|
||||
if (existsSync(logFilePath)) {
|
||||
const content = readFileSync(logFilePath, 'utf-8');
|
||||
console.log(` Telemetry Log Content:\n`, content);
|
||||
} else {
|
||||
console.log(` Telemetry log file not found at: ${logFilePath}`);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(` Failed to read telemetry log:`, e);
|
||||
}
|
||||
|
||||
const memoryMetric = rig.readMetric('memory.usage');
|
||||
const cpuMetric = rig.readMetric('cpu.usage');
|
||||
const toolLatencyMetric = rig.readMetric('tool.call.latency');
|
||||
const eventLoopMetric = rig.readMetric('event_loop.delay');
|
||||
|
||||
if (memoryMetric) {
|
||||
console.log(
|
||||
` CLI Memory Metric found:`,
|
||||
JSON.stringify(memoryMetric),
|
||||
);
|
||||
}
|
||||
if (cpuMetric) {
|
||||
console.log(` CLI CPU Metric found:`, JSON.stringify(cpuMetric));
|
||||
}
|
||||
if (toolLatencyMetric) {
|
||||
console.log(
|
||||
` CLI Tool Latency Metric found:`,
|
||||
JSON.stringify(toolLatencyMetric),
|
||||
);
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const logs = (rig as any)._readAndParseTelemetryLog();
|
||||
console.log(` Total telemetry log entries: ${logs.length}`);
|
||||
for (const logData of logs) {
|
||||
if (logData.scopeMetrics) {
|
||||
for (const scopeMetric of logData.scopeMetrics) {
|
||||
for (const metric of scopeMetric.metrics) {
|
||||
if (metric.descriptor.name.includes('event_loop')) {
|
||||
console.log(
|
||||
` Found event_loop metric in log:`,
|
||||
metric.descriptor.name,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (eventLoopMetric) {
|
||||
console.log(
|
||||
` CLI Event Loop Metric found:`,
|
||||
JSON.stringify(eventLoopMetric),
|
||||
);
|
||||
|
||||
const findValue = (percentile: string) => {
|
||||
const dp = eventLoopMetric.dataPoints.find(
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(p: any) => p.attributes.percentile === percentile,
|
||||
);
|
||||
return dp ? dp.value.min : undefined;
|
||||
};
|
||||
|
||||
snapshot.childEventLoopDelayP50Ms = findValue('p50');
|
||||
snapshot.childEventLoopDelayP95Ms = findValue('p95');
|
||||
snapshot.childEventLoopDelayMaxMs = findValue('max');
|
||||
}
|
||||
|
||||
return snapshot;
|
||||
} finally {
|
||||
await rig.cleanup();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if (UPDATE_BASELINES) {
|
||||
harness.updateScenarioBaseline(result);
|
||||
} else {
|
||||
harness.assertWithinBaseline(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{"method":"generateContent","response":{"candidates":[{"content":{"parts":[{"text":"0"}],"role":"model"},"finishReason":"STOP","index":0}]}}
|
||||
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"functionCall":{"name":"run_shell_command","args":{"command":"yes | head -n 1000000"}}}],"role":"model"},"finishReason":"STOP","index":0}]}]}
|
||||
{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"I have generated 1M lines of output."}],"role":"model"},"finishReason":"STOP","index":0}]}]}
|
||||
Reference in New Issue
Block a user