2021-02-18 22:25:36 +01:00
|
|
|
#include "fastfetch.h"
|
2022-07-25 13:15:01 +02:00
|
|
|
#include "common/printing.h"
|
2022-08-26 16:02:04 +02:00
|
|
|
#include "common/parsing.h"
|
2022-09-05 10:57:09 +02:00
|
|
|
#include "detection/memory/memory.h"
|
2022-06-18 14:25:31 +02:00
|
|
|
|
2021-04-15 18:59:26 +02:00
|
|
|
#define FF_MEMORY_MODULE_NAME "Memory"
|
2022-08-26 16:02:04 +02:00
|
|
|
#define FF_MEMORY_NUM_FORMAT_ARGS 3
|
2021-04-15 18:59:26 +02:00
|
|
|
|
2021-02-27 18:30:05 +01:00
|
|
|
void ffPrintMemory(FFinstance* instance)
|
2021-02-18 22:25:36 +01:00
|
|
|
{
|
2022-09-05 10:57:09 +02:00
|
|
|
const FFMemoryResult* memory = ffDetectMemory();
|
2022-08-23 13:53:12 +02:00
|
|
|
|
2022-09-05 10:57:09 +02:00
|
|
|
if(memory->bytesUsed == 0 && memory->bytesTotal == 0)
|
2021-04-15 18:59:26 +02:00
|
|
|
{
|
2022-09-05 10:57:09 +02:00
|
|
|
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, "Failed to detect memory");
|
2021-04-15 18:59:26 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 16:02:04 +02:00
|
|
|
FFstrbuf usedPretty;
|
|
|
|
|
ffStrbufInit(&usedPretty);
|
2022-09-05 10:57:09 +02:00
|
|
|
ffParseSize(memory->bytesUsed, instance->config.binaryPrefixType, &usedPretty);
|
2022-08-26 16:02:04 +02:00
|
|
|
|
|
|
|
|
FFstrbuf totalPretty;
|
|
|
|
|
ffStrbufInit(&totalPretty);
|
2022-09-05 10:57:09 +02:00
|
|
|
ffParseSize(memory->bytesTotal, instance->config.binaryPrefixType, &totalPretty);
|
2022-08-26 16:02:04 +02:00
|
|
|
|
2022-06-17 18:15:36 +02:00
|
|
|
if(instance->config.memory.outputFormat.length == 0)
|
2021-03-19 20:57:07 +01:00
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintLogoAndKey(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory.key);
|
2022-09-05 10:57:09 +02:00
|
|
|
printf("%s / %s (%u%%)\n", usedPretty.chars, totalPretty.chars, memory->percentage);
|
2021-03-19 20:57:07 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintFormat(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){
|
2022-08-26 16:02:04 +02:00
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty},
|
2022-09-05 10:57:09 +02:00
|
|
|
{FF_FORMAT_ARG_TYPE_UINT8, &memory->percentage},
|
2021-04-15 18:59:26 +02:00
|
|
|
});
|
2021-03-19 20:57:07 +01:00
|
|
|
}
|
2022-08-26 16:02:04 +02:00
|
|
|
|
|
|
|
|
ffStrbufDestroy(&usedPretty);
|
|
|
|
|
ffStrbufDestroy(&totalPretty);
|
2021-03-27 18:14:19 +01:00
|
|
|
}
|