diff options
Diffstat (limited to 'components')
-rw-r--r-- | components/vram.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/components/vram.c b/components/vram.c index 3148d01..bb66c6c 100644 --- a/components/vram.c +++ b/components/vram.c @@ -38,16 +38,17 @@ float GetUsedVRAM() { float vram_used = -1.0; // Check if an NVIDIA card is present - command_output = runCommand("nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits"); + command_output = runCommand("nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits"); // Returns MiB if (command_output != NULL) { sscanf(command_output, "%f", &vram_used); free(command_output); } else { // If no NVIDIA card is found, check for an AMD Radeon card // todo intel: "intel-gpu-top -b -s 1 -o - | grep 'used:'" - command_output = runCommand("cat /sys/class/drm/card0/device/mem_info_vram_used"); + command_output = runCommand("cat /sys/class/drm/card0/device/mem_info_vram_used"); // Returns Bytes if (command_output != NULL) { sscanf(command_output, "%f", &vram_used); + vram_used = vram_used / 1024 / 1024; // Bytes --> MiB free(command_output); } } @@ -61,16 +62,17 @@ float GetTotalVRAM() { float vram_total = -1.0; // Check if an NVIDIA card is present - command_output = runCommand("nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits"); + command_output = runCommand("nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits");// Returns MiB if (command_output != NULL) { sscanf(command_output, "%f", &vram_total); free(command_output); } else { // If no NVIDIA card is found, check for an AMD Radeon card // todo intel: "intel-gpu-top -b -s 1 -o - | grep 'total:'" - command_output = runCommand("cat /sys/class/drm/card0/device/mem_info_vram_total"); + command_output = runCommand("cat /sys/class/drm/card0/device/mem_info_vram_total"); // Returns Bytes if (command_output != NULL) { sscanf(command_output, "%f", &vram_total); + vram_total = vram_total / 1024 / 1024; // Bytes --> MiB free(command_output); } } @@ -78,6 +80,8 @@ float GetTotalVRAM() { return vram_total; } +/// ACTUAL FUNCTIONS TO CALL IN CONFIG.H + const char * vram_perc(const char *unused) { float vram_used = GetUsedVRAM(); @@ -90,3 +94,25 @@ vram_perc(const char *unused) { return NULL; } } + +const char * +vram_used(const char *unused) { + int vram_used = (int) GetUsedVRAM(); + + if (vram_used >= 0.0) { + return fmt_human(vram_used * 1024, 1024); + } else { + return NULL; + } +} + +const char * +vram_total(const char *unused) { + int vram_total = (int) GetTotalVRAM(); + + if (vram_total >= 0.0) { + return fmt_human(vram_total * 1024, 1024); + } else { + return NULL; + } +} |