|
1 | 1 | import { abortOngoingRequests, generateStream, listModels, listRunningModels, getRuntimeName } from "../core/runtime.js"; |
2 | | -import { getMemoryUsage, detectThermalPressure, detectBatteryPowered, getSwapUsedGB } from "../core/hardware.js"; |
| 2 | +import { getMemoryUsage, detectThermalPressure, detectBatteryPowered, getSwapUsedGB, getCpuLoad } from "../core/hardware.js"; |
3 | 3 | import type { PerformanceMetrics, BenchEnvironment } from "../types.js"; |
4 | 4 | import { avg, stddev, withTimeout, hasThinkingContent, estimateTokenCount } from "../utils.js"; |
5 | 5 | import { createSpinner, subStep } from "../ui/progress.js"; |
@@ -115,6 +115,7 @@ export async function runPerformanceBench( |
115 | 115 | let failedPrompts = 0; |
116 | 116 | let thinkingDetected = false; |
117 | 117 | let totalThinkingTokens = 0; |
| 118 | + const cpuLoadSamples: number[] = []; |
118 | 119 |
|
119 | 120 | for (let i = 0; i < BENCH_PROMPTS.length; i++) { |
120 | 121 | spinner.start(`Running performance test ${i + 1}/${BENCH_PROMPTS.length}...`); |
@@ -180,6 +181,10 @@ export async function runPerformanceBench( |
180 | 181 | subStep( |
181 | 182 | ` Prompt ${i + 1}: ${tps.toFixed(1)} tok/s, first chunk ${firstChunkTime ?? "?"}ms, TTFT ${firstTokenTime ?? "?"}ms` |
182 | 183 | ); |
| 184 | + |
| 185 | + // Sample CPU load after each prompt |
| 186 | + const cpuSample = await optionalProbe(() => getCpuLoad(), -1); |
| 187 | + if (cpuSample >= 0) cpuLoadSamples.push(cpuSample); |
183 | 188 | } catch (err) { |
184 | 189 | failedPrompts++; |
185 | 190 | const message = err instanceof Error ? err.message : String(err); |
@@ -232,11 +237,21 @@ export async function runPerformanceBench( |
232 | 237 | swapBeforeResult.available && swapAfterResult.available |
233 | 238 | ? +(swapAfterResult.value - swapBeforeResult.value).toFixed(2) |
234 | 239 | : undefined; |
| 240 | + // CPU load metrics from prompt samples |
| 241 | + const cpuAvgLoad = cpuLoadSamples.length > 0 |
| 242 | + ? +(cpuLoadSamples.reduce((a, b) => a + b, 0) / cpuLoadSamples.length).toFixed(1) |
| 243 | + : undefined; |
| 244 | + const cpuPeakLoad = cpuLoadSamples.length > 0 |
| 245 | + ? +Math.max(...cpuLoadSamples).toFixed(1) |
| 246 | + : undefined; |
| 247 | + |
235 | 248 | const benchEnvironment: BenchEnvironment = { |
236 | 249 | thermalPressureBefore: thermalBefore, |
237 | 250 | thermalPressureAfter: thermalAfter, |
238 | 251 | ...(swapDeltaGB !== undefined && swapDeltaGB > 0 ? { swapDeltaGB } : {}), |
239 | 252 | ...(batteryPowered != null ? { batteryPowered } : {}), |
| 253 | + ...(cpuAvgLoad !== undefined ? { cpuAvgLoad } : {}), |
| 254 | + ...(cpuPeakLoad !== undefined ? { cpuPeakLoad } : {}), |
240 | 255 | }; |
241 | 256 |
|
242 | 257 | return { |
|
0 commit comments