11import { execCommand } from './utils' ;
22
3+
4+ export type GPUUtilization = {
5+ /** GPU memory utilization as a percentage (0.0-1.0). */
6+ memory ?: number ;
7+
8+ /** GPU memory temperature in Celsius. */
9+ memoryTemperature ?: number ;
10+
11+ /** GPU processing utilization as a percentage (0.0-1.0). */
12+ processing ?: number ;
13+
14+ /** GPU temperature in Celsius. */
15+ temperature ?: number ;
16+
17+ /** Fan speed in percentage (0.0-1.0). */
18+ fanSpeed ?: number ;
19+
20+ /** GPU power draw in watts. */
21+ powerDraw ?: number ;
22+ } ;
23+
24+
325export type GPU = {
426 /** Unique ID of the GPU device. */
527 id : string ;
@@ -22,15 +44,6 @@ export type GPU = {
2244 /** Memory size of the GPU in bytes. */
2345 memory ?: number ;
2446
25- /** Memory utilization of the GPU in percentage (0.0-1.0) */
26- memoryUtilization ?: number ;
27-
28- /** Temperature of the memory in Celsius. */
29- memoryTemperature ?: number ;
30-
31- /** GPU processing utilization in percentage (0.0-1.0) */
32- utilization ?: number ;
33-
3447 /** Index of the GPU device. */
3548 index ?: number ;
3649
@@ -40,14 +53,8 @@ export type GPU = {
4053 /** If memory is allocated inside the GPU for display purposes. Can be true even if no physical display is attached. */
4154 displayActive ?: boolean ;
4255
43- /** Fan speed in percentage (0.0-1.0). */
44- fanSpeed ?: number ;
45-
46- /** Temperature of the GPU in Celsius. */
47- temperature ?: number ;
48-
49- /** Power draw of the GPU in watts. */
50- powerDraw ?: number ;
56+ /** Utilization data of the GPU. */
57+ utilization ?: GPUUtilization ;
5158} ;
5259
5360export async function getGPUs ( ) : Promise < GPU [ ] > {
@@ -159,17 +166,32 @@ export async function getGPUs(): Promise<GPU[]> {
159166 }
160167 if ( displayAttached ) currGpu . displayAttached = [ 'yes' , 'enabled' , '1' ] . includes ( displayAttached . toLowerCase ( ) ) ;
161168 if ( displayActive ) currGpu . displayActive = [ 'yes' , 'enabled' , '1' ] . includes ( displayActive . toLowerCase ( ) ) ;
162- if ( fanSpeed && ! Number . isNaN ( parseFloat ( fanSpeed ) ) ) currGpu . fanSpeed = parseFloat ( fanSpeed ) / 100 ;
169+ if ( fanSpeed && ! Number . isNaN ( parseFloat ( fanSpeed ) ) ) {
170+ if ( ! currGpu . utilization ) currGpu . utilization = { } as GPUUtilization ;
171+ currGpu . utilization . fanSpeed = parseFloat ( fanSpeed ) / 100 ;
172+ }
163173 if ( memoryTotal && ! Number . isNaN ( parseInt ( memoryTotal , 10 ) ) )
164174 currGpu . memory = parseInt ( memoryTotal , 10 ) * 1024 * 1024 ; // convert MiB to bytes
165- if ( utilizationGPU && ! Number . isNaN ( parseFloat ( utilizationGPU ) ) )
166- currGpu . utilization = parseFloat ( utilizationGPU ) / 100 ;
167- if ( utilizationMemory && ! Number . isNaN ( parseFloat ( utilizationMemory ) ) )
168- currGpu . memoryUtilization = parseFloat ( utilizationMemory ) / 100 ;
169- if ( temperatureGPU && ! Number . isNaN ( parseFloat ( temperatureGPU ) ) ) currGpu . temperature = parseFloat ( temperatureGPU ) ;
170- if ( temperatureMemory && ! Number . isNaN ( parseFloat ( temperatureMemory ) ) )
171- currGpu . memoryTemperature = parseFloat ( temperatureMemory ) ;
172- if ( powerDraw && ! Number . isNaN ( parseFloat ( powerDraw ) ) ) currGpu . powerDraw = parseFloat ( powerDraw ) ;
175+ if ( utilizationGPU && ! Number . isNaN ( parseFloat ( utilizationGPU ) ) ) {
176+ if ( ! currGpu . utilization ) currGpu . utilization = { } as GPUUtilization ;
177+ currGpu . utilization . processing = parseFloat ( utilizationGPU ) / 100 ;
178+ }
179+ if ( utilizationMemory && ! Number . isNaN ( parseFloat ( utilizationMemory ) ) ) {
180+ if ( ! currGpu . utilization ) currGpu . utilization = { } as GPUUtilization ;
181+ currGpu . utilization . memory = parseFloat ( utilizationMemory ) / 100 ;
182+ }
183+ if ( temperatureGPU && ! Number . isNaN ( parseFloat ( temperatureGPU ) ) ) {
184+ if ( ! currGpu . utilization ) currGpu . utilization = { } as GPUUtilization ;
185+ currGpu . utilization . temperature = parseFloat ( temperatureGPU ) ;
186+ }
187+ if ( temperatureMemory && ! Number . isNaN ( parseFloat ( temperatureMemory ) ) ) {
188+ if ( ! currGpu . utilization ) currGpu . utilization = { } as GPUUtilization ;
189+ currGpu . utilization . memoryTemperature = parseFloat ( temperatureMemory ) ;
190+ }
191+ if ( powerDraw && ! Number . isNaN ( parseFloat ( powerDraw ) ) ) {
192+ if ( ! currGpu . utilization ) currGpu . utilization = { } as GPUUtilization ;
193+ currGpu . utilization . powerDraw = parseFloat ( powerDraw ) ;
194+ }
173195 gpus [ currIdx ] = currGpu ;
174196 }
175197 }
0 commit comments