@@ -81,6 +81,42 @@ export async function jobIdFrom(args: Arguments<Options>, cmd: string, offset =
81
81
return { jobId, profile }
82
82
}
83
83
84
+ /** @return grid model for the given `kind` for `jobId` in `profile` */
85
+ async function gridFor (
86
+ kind : SupportedGrid ,
87
+ profile : string ,
88
+ jobId : string ,
89
+ opts : Pick < Options , "demo" | "theme" >
90
+ ) : Promise < GridSpec > {
91
+ const tails = await tailf ( kind , profile , jobId )
92
+ return kind === "status"
93
+ ? status ( tails , { demo : opts . demo , theme : opts . theme , themeDefault : "colorbrewer" } )
94
+ : utilization ( kind , tails , opts )
95
+ }
96
+
97
+ /** @return all relevant grid models for `jobId` in `profile` */
98
+ async function allGridsFor ( profile : string , jobId : string , opts : Pick < Options , "demo" | "theme" > ) {
99
+ const usesGpus = opts . demo || ( await import ( "../env.js" ) . then ( ( _ ) => _ . usesGpus ( profile , jobId ) ) )
100
+
101
+ const all = [
102
+ gridFor ( "status" , profile , jobId , opts ) ,
103
+ null , // newline
104
+ gridFor ( "cpu%" , profile , jobId , opts ) ,
105
+ ]
106
+
107
+ if ( usesGpus ) {
108
+ all . push ( gridFor ( "gpu%" , profile , jobId , opts ) )
109
+ }
110
+
111
+ all . push ( gridFor ( "mem%" , profile , jobId , opts ) )
112
+
113
+ if ( usesGpus ) {
114
+ all . push ( gridFor ( "gpumem%" , profile , jobId , opts ) )
115
+ }
116
+
117
+ return Promise . all ( all )
118
+ }
119
+
84
120
export default async function dashboard ( args : Arguments < Options > , cmd : "db" | "dashboard" ) {
85
121
const { theme } = args . parsedOptions
86
122
@@ -98,25 +134,11 @@ export default async function dashboard(args: Arguments<Options>, cmd: "db" | "d
98
134
throw new Error ( usage ( cmd , [ "all" ] ) )
99
135
}
100
136
101
- const gridFor = async ( kind : SupportedGrid ) : Promise < GridSpec > => {
102
- const tails = await tailf ( kind , profile , jobId )
103
- return kind === "status"
104
- ? status ( tails , { demo, theme, themeDefault : "colorbrewer" } )
105
- : utilization ( kind , tails , { demo, theme } )
106
- }
107
-
108
137
const gridForA = async ( kind : KindA ) : Promise < null | GridSpec | ( null | GridSpec ) [ ] > => {
109
138
if ( kind === "all" ) {
110
- return Promise . all ( [
111
- gridFor ( "status" ) ,
112
- null , // newline
113
- gridFor ( "cpu%" ) ,
114
- gridFor ( "gpu%" ) ,
115
- gridFor ( "mem%" ) ,
116
- gridFor ( "gpumem%" ) ,
117
- ] )
139
+ return allGridsFor ( profile , jobId , { demo, theme } )
118
140
} else if ( isSupportedGrid ( kind ) ) {
119
- return gridFor ( kind )
141
+ return gridFor ( kind , profile , jobId , { demo , theme } )
120
142
} else {
121
143
return null
122
144
}
0 commit comments