feat: add combineSeries for GPU combination aggregation
This commit is contained in:
@@ -22,6 +22,18 @@ const AGGREGATE: Record<GpuMetricKind, (values: number[]) => number> = {
|
||||
fan: avg,
|
||||
};
|
||||
|
||||
export function combineSeries(histories: number[][], kind: GpuMetricKind): { value?: number; history: number[] } {
|
||||
const n = Math.max(...histories.map((h) => h.length), 0);
|
||||
if (n === 0) return { value: undefined, history: [] };
|
||||
const history: number[] = [];
|
||||
for (let i = 0; i < n; i++) {
|
||||
const at = histories.map((h) => h[i]).filter((v): v is number => v !== undefined);
|
||||
if (at.length === 0) continue;
|
||||
history.push(AGGREGATE[kind](at));
|
||||
}
|
||||
return { value: history.length > 0 ? history[history.length - 1] : undefined, history };
|
||||
}
|
||||
|
||||
function key(gpuId: string, kind: GpuMetricKind): string {
|
||||
return `${gpuId}|${kind}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user