1717import React from "react"
1818
1919import { Log } from "../controller/charts/gpu"
20- import BaseChart , { BaseChartProps , Series } from "./Chart"
20+ import BaseChart , { BaseChartProps } from "./Chart"
21+ import { HostMap } from "../controller/charts/LogRecord"
2122
2223type Props = {
23- logs : Log [ ]
24+ logs : HostMap < Log >
2425}
2526
2627type State = {
@@ -39,49 +40,37 @@ export default class GPUChart extends React.PureComponent<Props, State> {
3940 }
4041 }
4142
42- private static data ( field : "utilizationGPU" | "utilizationMemory" | "temperatureGPU" , props : Props ) {
43- return props . logs . map ( ( log ) => ( {
44- name : log . gpuType ,
45- x : log . timestamp ,
46- y : log [ field ] ,
47- } ) )
48- }
49-
5043 private static charts ( props : Props ) : BaseChartProps [ ] {
51- const earliestTimestamp = props . logs . reduce ( ( min , line ) => Math . min ( min , line . timestamp ) , Number . MAX_VALUE )
52-
53- const perNodeData = props . logs . reduce ( ( M , line ) => {
54- if ( ! M [ line . cluster ] ) {
55- M [ line . cluster ] = [
56- { impl : "ChartArea" , stroke : BaseChart . colors [ 1 ] , data : [ ] } ,
57- { impl : "ChartLine" , stroke : BaseChart . colors [ 2 ] , data : [ ] } ,
58- { impl : "ChartDashedLine" , stroke : BaseChart . colors [ 3 ] , data : [ ] } ,
59- ]
60- }
61-
62- M [ line . cluster ] [ 0 ] . data . push ( {
63- name : BaseChart . nodeNameLabel ( line . cluster ) + " GPU Utilization" ,
44+ const earliestTimestamp : number = Object . values ( props . logs ) . reduce (
45+ ( min , logs ) => logs . reduce ( ( min , line ) => Math . min ( min , line . timestamp ) , Number . MAX_VALUE ) ,
46+ Number . MAX_VALUE
47+ )
48+
49+ return Object . entries ( props . logs ) . map ( ( [ node , lines ] ) => {
50+ const d1 = lines . map ( ( line ) => ( {
51+ name : BaseChart . nodeNameLabel ( node ) + " GPU Utilization" ,
6452 x : line . timestamp - earliestTimestamp ,
6553 y : line . utilizationGPU ,
66- } )
54+ } ) )
6755
68- M [ line . cluster ] [ 1 ] . data . push ( {
69- name : BaseChart . nodeNameLabel ( line . cluster ) + " GPU Memory Utilization" ,
56+ const d2 = lines . map ( ( line ) => ( {
57+ name : BaseChart . nodeNameLabel ( node ) + " GPU Memory Utilization" ,
7058 x : line . timestamp - earliestTimestamp ,
7159 y : line . utilizationMemory ,
72- } )
60+ } ) )
7361
74- M [ line . cluster ] [ 2 ] . data . push ( {
75- name : BaseChart . nodeNameLabel ( line . cluster ) + " GPU Temperature" ,
62+ const d3 = lines . map ( ( line ) => ( {
63+ name : BaseChart . nodeNameLabel ( node ) + " GPU Temperature" ,
7664 x : line . timestamp - earliestTimestamp ,
7765 y : line . temperatureGPU ,
78- } )
66+ } ) )
7967
80- return M
81- } , { } as Record < string , Series [ ] > )
68+ const series = [
69+ { impl : "ChartArea" as const , stroke : BaseChart . colors [ 1 ] , data : d1 } ,
70+ { impl : "ChartLine" as const , stroke : BaseChart . colors [ 2 ] , data : d2 } ,
71+ { impl : "ChartDashedLine" as const , stroke : BaseChart . colors [ 3 ] , data : d3 } ,
72+ ]
8273
83- return Object . keys ( perNodeData ) . map ( ( node ) => {
84- const series = perNodeData [ node ]
8574 const data = series . map ( ( _ , idx ) => BaseChart . normalize ( _ , idx !== 2 ? "percentage" : "celsius" ) )
8675
8776 return {
@@ -90,7 +79,7 @@ export default class GPUChart extends React.PureComponent<Props, State> {
9079 padding : GPUChart . padding ,
9180 yAxes : [
9281 {
93- label : "Utilization " ,
82+ label : "GPU " ,
9483 format : "percentage" ,
9584 y : data [ 0 ] . y ,
9685 tickFormat : data [ 0 ] . tickFormat ,
0 commit comments