/
outbreak
/
kilocode
Обзор
Документация
Войти
/
outbreak
/
kilocode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
webview-ui/src/services/MemoryService.ts
49 строк
1 KB
Chris Hasson
perf(webview): sample memory usage telemetry (#2194)
29 авг 2025, 05:32
Не верифицирован
29 авг 2025, 05:32
5d6bcc4
Код
Авторство
О чём код?
// kilocode_change - new file import { telemetryClient } from "../utils/TelemetryClient" import { TelemetryEventName } from "@roo-code/types" import { createSampledFunction } from "../utils/sampling" interface PerformanceMemory { usedJSHeapSize?: number totalJSHeapSize?: number } export class MemoryService { private intervalId: number | null = null private readonly intervalMs: number = 10 * 60 * 1000 // 10 min(s) private readonly sampledTelemetryCapture = createSampledFunction( telemetryClient.capture.bind(telemetryClient), 0.01, // 1% sampling rate ) public start(): void { if (this.intervalId) { return } this.reportMemoryUsage() this.intervalId = window.setInterval(() => { this.reportMemoryUsage() }, this.intervalMs) } public stop(): void { if (this.intervalId) { window.clearInterval(this.intervalId) this.intervalId = null } } private reportMemoryUsage(): void { const memory = (performance as Performance & { memory?: PerformanceMemory }).memory const memoryInfo = { heapUsedMb: this.bytesToMegabytes(memory?.usedJSHeapSize || 0), heapTotalMb: this.bytesToMegabytes(memory?.totalJSHeapSize || 0), } this.sampledTelemetryCapture(TelemetryEventName.WEBVIEW_MEMORY_USAGE, memoryInfo) } private bytesToMegabytes(bytes: number): number { return Math.round((bytes / 1024 / 1024) * 100) / 100 } }