@@ -18,6 +18,9 @@ import React from "react"
1818import { join } from "path"
1919import { Arguments } from "@kui-shell/core"
2020
21+ import { toHostMap } from "./LogRecord"
22+ import { timeRange } from "./timestamps"
23+
2124/** Oops, sometimes we have no data for a give node */
2225function noData ( node : string , kind : "CPU Utilization" | "GPU Utilization" ) {
2326 return (
@@ -52,32 +55,42 @@ export default async function all(args: Arguments) {
5255 ] )
5356
5457 // get a canonical list of nodes
55- const nodes = Array . from ( new Set ( Object . keys ( gpuData ) . concat ( Object . keys ( cpuData ) ) ) ) . sort ( ( a , b ) => {
58+ const gpuMap = toHostMap ( gpuData )
59+ const cpuMap = toHostMap ( cpuData )
60+ const nodes = Array . from ( new Set ( Object . keys ( gpuMap ) . concat ( Object . keys ( cpuMap ) ) ) ) . sort ( ( a , b ) => {
5661 // sort them so that nodes for which we have both gpu and cpu
5762 // data float to the top; in second place will be the group of
5863 // nodes for which we have only gpu data; in last place will be
5964 // the nodes for which we only have cpu data
60- const aHasG = gpuData [ a ]
61- const aHasC = cpuData [ a ]
62- const bHasG = gpuData [ b ]
63- const bHasC = cpuData [ b ]
65+ const aHasG = gpuMap [ a ]
66+ const aHasC = cpuMap [ a ]
67+ const bHasG = gpuMap [ b ]
68+ const bHasC = cpuMap [ b ]
6469
6570 // 2 vs 1 to get the gpu-first priority described above
6671 const vA = ( aHasG ? 2 : 0 ) + ( aHasC ? 1 : 0 )
6772 const vB = ( bHasG ? 2 : 0 ) + ( bHasC ? 1 : 0 )
6873 return vB - vA
6974 } )
7075
71- const linearized = nodes . map ( ( node ) => {
72- const gpuForNode = gpuData [ node ]
73- const cpuForNode = cpuData [ node ]
74- return [
75- ! gpuForNode ? noData ( node , "GPU Utilization" ) : < GPUChart logs = { { [ node ] : gpuForNode } } /> ,
76- ! cpuForNode ? noData ( node , "CPU Utilization" ) : < VmstatChart logs = { { [ node ] : cpuData [ node ] } } /> ,
77- ]
78- } )
76+ const range = timeRange ( gpuData , cpuData )
77+
78+ const linearized = nodes
79+ . map ( ( node ) => {
80+ const gpuForNode = gpuMap [ node ]
81+ const cpuForNode = cpuMap [ node ]
82+ return [
83+ ! gpuForNode ? noData ( node , "GPU Utilization" ) : < GPUChart timeRange = { range } logs = { { [ node ] : gpuForNode } } /> ,
84+ ! cpuForNode ? (
85+ noData ( node , "CPU Utilization" )
86+ ) : (
87+ < VmstatChart timeRange = { range } logs = { { [ node ] : cpuMap [ node ] } } />
88+ ) ,
89+ ]
90+ } )
91+ . flatMap ( ( _ ) => _ )
7992
8093 return {
81- react : < div className = "codeflare-chart-grid flex-fill" > { linearized . flatMap ( ( _ ) => _ ) } </ div > ,
94+ react : < div className = "codeflare-chart-grid flex-fill" > { linearized } </ div > ,
8295 }
8396}
0 commit comments