9 lines
1.1 KiB
JavaScript
9 lines
1.1 KiB
JavaScript
import { withQvacMaster, qvacSdk } from './qvac-master.js';
|
|
|
|
export class RuntimeTelemetry {
|
|
constructor({ now = () => Date.now() } = {}) { this.now = now; this.samples = []; this.latencies = {}; }
|
|
record(kind, startedAt, extra = {}) { const durationMs = this.now() - startedAt; const row = { kind, durationMs, ...extra }; this.samples.push(row); if (this.samples.length > 200) this.samples.shift(); this.latencies[kind] = { last_ms: durationMs, count: (this.latencies[kind]?.count || 0) + 1 }; return row; }
|
|
async sample() { try { const sdk = await qvacSdk(); const resources = await withQvacMaster(() => sdk.getSystemResources({ sample: true })); this.samples.push({ kind: 'gpu_sample', ts: this.now(), resources }); if (this.samples.length > 200) this.samples.shift(); return resources; } catch (error) { return { unavailable: error.message }; } }
|
|
snapshot() { const latest = [...this.samples].reverse().find((sample) => sample.kind === 'gpu_sample'); return { latest_resources: latest?.resources || null, latencies: { ...this.latencies }, samples: this.samples.length }; }
|
|
}
|