@@ -409,26 +409,18 @@ export default memo(function SystemDetail({ id }: { id: string }) {
409409 if ( lastGpus ) {
410410 // check if there are any GPUs at all
411411 hasGpuData = Object . keys ( lastGpus ) . length > 0
412- // check if there are any GPUs with engines
413- for ( let i = 0 ; i < systemStats . length && ! hasGpuEnginesData ; i ++ ) {
412+ // check if there are any GPUs with engines or power data
413+ for ( let i = 0 ; i < systemStats . length && ( ! hasGpuEnginesData || ! hasGpuPowerData ) ; i ++ ) {
414414 const gpus = systemStats [ i ] . stats ?. g
415415 if ( ! gpus ) continue
416416 for ( const id in gpus ) {
417- if ( gpus [ id ] . e !== undefined ) {
417+ if ( ! hasGpuEnginesData && gpus [ id ] . e !== undefined ) {
418418 hasGpuEnginesData = true
419- break
420419 }
421- }
422- }
423- // check if there are any GPUs with power data
424- for ( let i = 0 ; i < systemStats . length && ! hasGpuPowerData ; i ++ ) {
425- const gpus = systemStats [ i ] . stats ?. g
426- if ( ! gpus ) continue
427- for ( const id in gpus ) {
428- if ( gpus [ id ] . p !== undefined || gpus [ id ] . pp !== undefined ) {
420+ if ( ! hasGpuPowerData && ( gpus [ id ] . p !== undefined || gpus [ id ] . pp !== undefined ) ) {
429421 hasGpuPowerData = true
430- break
431422 }
423+ if ( hasGpuEnginesData && hasGpuPowerData ) break
432424 }
433425 }
434426 }
@@ -896,16 +888,30 @@ export default memo(function SystemDetail({ id }: { id: string }) {
896888} )
897889
898890function GpuEnginesChart ( { chartData } : { chartData : ChartData } ) {
899- const dataPoints : DataPoint [ ] = [ ]
900- const engines = Object . keys ( chartData . systemStats ?. at ( - 1 ) ?. stats . g ?. [ 0 ] ?. e ?? { } ) . sort ( )
901- for ( const engine of engines ) {
902- dataPoints . push ( {
903- label : engine ,
904- dataKey : ( { stats } : SystemStatsRecord ) => stats ?. g ?. [ 0 ] ?. e ?. [ engine ] ?? 0 ,
905- color : `hsl(${ 140 + ( ( ( engines . indexOf ( engine ) * 360 ) / engines . length ) % 360 ) } , 65%, 52%)` ,
906- opacity : 0.35 ,
907- } )
891+ const { gpuId, engines } = useMemo ( ( ) => {
892+ for ( let i = chartData . systemStats . length - 1 ; i >= 0 ; i -- ) {
893+ const gpus = chartData . systemStats [ i ] . stats ?. g
894+ if ( ! gpus ) continue
895+ for ( const id in gpus ) {
896+ if ( gpus [ id ] . e ) {
897+ return { gpuId : id , engines : Object . keys ( gpus [ id ] . e ) . sort ( ) }
898+ }
899+ }
900+ }
901+ return { gpuId : null , engines : [ ] }
902+ } , [ chartData . systemStats ] )
903+
904+ if ( ! gpuId ) {
905+ return null
908906 }
907+
908+ const dataPoints : DataPoint [ ] = engines . map ( ( engine , i ) => ( {
909+ label : engine ,
910+ dataKey : ( { stats } : SystemStatsRecord ) => stats ?. g ?. [ gpuId ] ?. e ?. [ engine ] ?? 0 ,
911+ color : `hsl(${ 140 + ( ( ( i * 360 ) / engines . length ) % 360 ) } , 65%, 52%)` ,
912+ opacity : 0.35 ,
913+ } ) )
914+
909915 return (
910916 < LineChartDefault
911917 legend = { true }
0 commit comments