diff options
author | xAlpharax <42233094+xAlpharax@users.noreply.github.com> | 2023-09-06 21:18:05 +0300 |
---|---|---|
committer | xAlpharax <42233094+xAlpharax@users.noreply.github.com> | 2023-09-06 21:18:05 +0300 |
commit | b2bcd0fc0f9b06cc021d46bdc954addb3c433f99 (patch) | |
tree | 809d58bf1a0ede4a258dcae0b33fe6e14194d9ce | |
parent | debe2e06f3a4b809e16913b11e1ce7460dffdf39 (diff) |
Added the following functions: vram_perc, vram_total, vram_used.
Changes to be committed:
modified: README
modified: components/vram.c
modified: config.def.h
modified: config.h
modified: slstatus.h
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | components/vram.c | 34 | ||||
-rw-r--r-- | config.def.h | 5 | ||||
-rw-r--r-- | config.h | 7 | ||||
-rw-r--r-- | slstatus.h | 2 |
5 files changed, 44 insertions, 6 deletions
@@ -26,7 +26,7 @@ Features - Network speeds (RX and TX) - Number of files in a directory (hint: Maildir) - Memory status (free memory, percentage, total memory and used memory) -- GPU Memory status (percentage used) +- GPU Memory status (percentage used, total amount and used amount of virtual memory) - Swap status (free swap, percentage, total swap and used swap) - Temperature - Uptime 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; + } +} diff --git a/config.def.h b/config.def.h index d805331..f60332c 100644 --- a/config.def.h +++ b/config.def.h @@ -60,6 +60,11 @@ static const char unknown_str[] = "n/a"; * username username of current user NULL * vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer) * NULL on OpenBSD/FreeBSD + * + * vram_perc gpu memory usage in percent NULL + * vram_total gpu total memory NULL + * vram_used gpu used memory NULL + * * wifi_essid WiFi ESSID interface name (wlan0) * wifi_perc WiFi signal in percent interface name (wlan0) */ @@ -17,6 +17,7 @@ const struct arg args[] = { { cpu_freq, " %sHz", NULL }, { ram_perc, " <%s ram>", NULL }, { vram_perc, " <%s vram>", NULL }, + { vram_total, " <%s vram>", NULL }, { disk_perc, " <%s nvme>", "/" }, { disk_perc, " <%s sata>", "/home/alphara/exfatssd" }, { wifi_perc, " <%s wifi>", "wlp5s0" }, @@ -58,7 +59,6 @@ const struct arg args[] = { * ram_perc memory usage in percent NULL * ram_total total memory size in GB NULL * ram_used used memory in GB NULL - * vram_perc gpu memory usage in percent NULL * run_command custom shell command command (echo foo) * separator string to echo NULL * swap_free free swap in GB NULL @@ -75,6 +75,11 @@ const struct arg args[] = { * username username of current user NULL * vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer) * NULL on OpenBSD + * + * vram_perc gpu memory usage in percent NULL + * vram_total gpu total memory NULL + * vram_used gpu used memory NULL + * * wifi_perc WiFi signal in percent interface name (wlan0) * wifi_essid WiFi ESSID interface name (wlan0) */ @@ -52,6 +52,8 @@ const char *num_files(const char *path); /* vram */ const char *vram_perc(const char *unused); +const char *vram_total(const char *unused); +const char *vram_used(const char *unused); /* ram */ const char *ram_free(const char *unused); |