Skip to content

Commit c0b1193

Browse files
committed
fix: improve sort order of combined gpu/cpu chart set
so that nodes for which we have better information float to the top; better meaning "both cpu and gpu", otherwise "has only gpu", in last place "has only cpu"
1 parent 90b573e commit c0b1193

File tree

1 file changed

+18
-1
lines changed
  • plugins/plugin-codeflare/src/controller/charts

1 file changed

+18
-1
lines changed

plugins/plugin-codeflare/src/controller/charts/all.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,34 @@ export default async function all(args: Arguments) {
3939
return `Usage chart all ${filepath}`
4040
}
4141

42+
// parse the data
4243
const [gpuData, cpuData] = await Promise.all([
4344
import("./gpu").then((_) => _.parse(join(filepath, "resources/gpu.txt"), args.REPL)),
4445
import("./vmstat").then((_) => _.parse(join(filepath, "resources/pod-vmstat.txt"), args.REPL)),
4546
])
4647

48+
// load the UI components
4749
const [GPUChart, VmstatChart] = await Promise.all([
4850
import("../../components/GPUChart").then((_) => _.default),
4951
import("../../components/VmstatChart").then((_) => _.default),
5052
])
5153

52-
const nodes = Array.from(new Set(Object.keys(gpuData).concat(Object.keys(cpuData))))
54+
// get a canonical list of nodes
55+
const nodes = Array.from(new Set(Object.keys(gpuData).concat(Object.keys(cpuData)))).sort((a, b) => {
56+
// sort them so that nodes for which we have both gpu and cpu
57+
// data float to the top; in second place will be the group of
58+
// nodes for which we have only gpu data; in last place will be
59+
// 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]
64+
65+
// 2 vs 1 to get the gpu-first priority described above
66+
const vA = (aHasG ? 2 : 0) + (aHasC ? 1 : 0)
67+
const vB = (bHasG ? 2 : 0) + (bHasC ? 1 : 0)
68+
return vB - vA
69+
})
5370

5471
const linearized = nodes.map((node) => {
5572
const gpuForNode = gpuData[node]

0 commit comments

Comments
 (0)