From 39d887cbb483788066470aa887cfca517bbefcab Mon Sep 17 00:00:00 2001 From: Stuart Date: Sat, 27 Apr 2024 01:29:20 +0100 Subject: [PATCH] Conditional Render GPU Stats (#1) Check if GPU stats are available --- web/src/views/system/GeneralMetrics.tsx | 113 ++++++++++++------------ 1 file changed, 56 insertions(+), 57 deletions(-) diff --git a/web/src/views/system/GeneralMetrics.tsx b/web/src/views/system/GeneralMetrics.tsx index c62924732..1405b62b5 100644 --- a/web/src/views/system/GeneralMetrics.tsx +++ b/web/src/views/system/GeneralMetrics.tsx @@ -212,7 +212,7 @@ export default function GeneralMetrics({ } = {}; statsHistory.forEach((stats, statsIdx) => { - if (!stats) { + if (!stats || !canGetGpuInfo) { return; } @@ -225,7 +225,7 @@ export default function GeneralMetrics({ }); }); return Object.keys(series).length > 0 ? Object.values(series) : []; - }, [statsHistory]); + }, [statsHistory, canGetGpuInfo]); const gpuMemSeries = useMemo(() => { if (!statsHistory) { @@ -245,7 +245,7 @@ export default function GeneralMetrics({ } = {}; statsHistory.forEach((stats, statsIdx) => { - if (!stats) { + if (!stats || !canGetGpuInfo) { return; } @@ -258,7 +258,7 @@ export default function GeneralMetrics({ }); }); return Object.values(series); - }, [statsHistory]); + }, [statsHistory, canGetGpuInfo]); // other processes stats @@ -411,13 +411,13 @@ export default function GeneralMetrics({ )} - {(statsHistory.length == 0 || statsHistory[0].gpu_usages) && ( - <> -
-
- GPUs -
- {canGetGpuInfo && ( + {canGetGpuInfo && + (statsHistory.length == 0 || statsHistory[0].gpu_usages) && ( + <> +
+
+ GPUs +
- )} -
-
- {statsHistory.length != 0 ? ( -
-
GPU Usage
- {gpuSeries.map((series) => ( - - ))} -
- ) : ( - - )} - {statsHistory.length != 0 ? ( - <> - {gpuMemSeries && ( -
-
GPU Memory
- {gpuMemSeries.map((series) => ( - - ))} -
- )} - - ) : ( - - )} -
- - )} +
+
+ {statsHistory.length != 0 ? ( +
+
GPU Usage
+ {gpuSeries.map((series) => ( + + ))} +
+ ) : ( + + )} + {statsHistory.length != 0 ? ( + <> + {gpuMemSeries && ( +
+
GPU Memory
+ {gpuMemSeries.map((series) => ( + + ))} +
+ )} + + ) : ( + + )} +
+ + )}
Other Processes