Show huge ram values in GiB

#218
This commit is contained in:
Linus Dierheimer
2022-08-23 13:53:12 +02:00
parent aa1237b0fd
commit 952989c1e8
4 changed files with 41 additions and 15 deletions
+1 -1
View File
@@ -20,7 +20,7 @@
--cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; temperature: {}; bios: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}"
--cpu-usage-format "Percentage: {}"
--gpu-format "Vendor: {}; Vendor pretty: {}; Name: {}; Name pretty: {}; Driver: {}; Temperature: {}"
--memory-format "Used: {}; Total: {}; Percentage: {}"
--memory-format "Percentage: {}; Used KiB: {}, Total KiB: {}, Used MiB: {}, Total MiB: {}, Used GiB: {}, Total GiB: {}"
--disk-format "Used: {}; Total: {}; Files: {}; Percentage: {}"
--battery-format "Manufactor: {}; Model: {}; Technology: {}; Capacaty: {}; Status: {}"
--player-format "Name: {}"
+8 -4
View File
@@ -284,10 +284,14 @@ static inline void printCommandHelp(const char* command)
}
else if(strcasecmp(command, "memory-format") == 0)
{
constructAndPrintCommandHelpFormat("memory", "{}MiB / {}MiB ({}%)", 3,
"Used memory",
"Total memory",
"Used memory percentage"
constructAndPrintCommandHelpFormat("memory", "{6}GiB / {7}GiB ({1}%)", 7,
"Percentage",
"Used KiB",
"Total KiB",
"Used MiB",
"Total MiB",
"Used GiB",
"Total GiB"
);
}
else if(strcasecmp(command, "disk-format") == 0)
+1 -1
View File
@@ -43,7 +43,7 @@ static void printStatvfs(FFinstance* instance, FFstrbuf* key, struct statvfs* fs
else
printf("%.1f", used);
fputs(" GB / ", stdout);
fputs(" GiB / ", stdout);
if(total >= 100.0)
printf("%.0f", total);
+31 -9
View File
@@ -4,7 +4,17 @@
#include <stdlib.h>
#define FF_MEMORY_MODULE_NAME "Memory"
#define FF_MEMORY_NUM_FORMAT_ARGS 3
#define FF_MEMORY_NUM_FORMAT_ARGS 7
static void printValue(uint32_t kib, double mib, double gib)
{
if(gib >= 1.0)
printf("%.2f GiB", gib);
else if(mib >= 1.0)
printf("%.2f MiB", mib);
else
printf("%u KiB", kib);
}
// Impl inspired by: https://github.com/sam-barr/paleofetch/blob/b7c58a52c0de39b53c9b5f417889a5886d324bfa/paleofetch.c#L544
void ffPrintMemory(FFinstance* instance)
@@ -39,11 +49,16 @@ void ffPrintMemory(FFinstance* instance)
fclose(meminfo);
uint32_t used_mem = (total + shared - memfree - buffers - cached - reclaimable) / 1024;
uint32_t total_mem = total / 1024;
uint8_t percentage = (uint8_t) ((used_mem / (double) total_mem) * 100);
uint32_t used = total + shared - memfree - buffers - cached - reclaimable;
uint8_t percentage = (uint8_t) ((used / (double) total) * 100);
if(used_mem == 0 && total_mem == 0 && percentage == 0)
double usedMiB = used / 1024.0;
double totalMiB = total / 1024.0;
double usedGiB = usedMiB / 1024.0;
double totalGiB = totalMiB / 1024.0;
if(used == 0 && total == 0)
{
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, "/proc/meminfo could't be parsed");
return;
@@ -52,14 +67,21 @@ void ffPrintMemory(FFinstance* instance)
if(instance->config.memory.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory.key);
printf("%uMiB / %uMiB (%u%%)\n", used_mem, total_mem, percentage);
printValue(used, usedMiB, usedGiB);
fputs(" / ", stdout);
printValue(total, totalMiB, totalGiB);
printf(" (%u%%)\n", percentage);
}
else
{
ffPrintFormat(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT, &used_mem},
{FF_FORMAT_ARG_TYPE_UINT, &total_mem},
{FF_FORMAT_ARG_TYPE_UINT8, &percentage}
{FF_FORMAT_ARG_TYPE_UINT8, &percentage},
{FF_FORMAT_ARG_TYPE_UINT, &total},
{FF_FORMAT_ARG_TYPE_UINT, &used},
{FF_FORMAT_ARG_TYPE_DOUBLE, &usedMiB},
{FF_FORMAT_ARG_TYPE_DOUBLE, &totalMiB},
{FF_FORMAT_ARG_TYPE_DOUBLE, &usedGiB},
{FF_FORMAT_ARG_TYPE_DOUBLE, &totalGiB}
});
}
}