mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-04 04:04:17 +01:00
@@ -3,14 +3,19 @@
|
||||
|
||||
void ffDetectMemoryImpl(FFMemoryResult* memory);
|
||||
|
||||
static void calculatePercentage(FFMemoryStorage* storage)
|
||||
{
|
||||
if(storage->bytesTotal == 0)
|
||||
storage->percentage = 0;
|
||||
else
|
||||
storage->percentage = (uint8_t) ((storage->bytesUsed / (long double) storage->bytesTotal) * 100.0);
|
||||
}
|
||||
|
||||
const FFMemoryResult* ffDetectMemory()
|
||||
{
|
||||
FF_DETECTION_INTERNAL_GUARD(FFMemoryResult,
|
||||
ffDetectMemoryImpl(&result);
|
||||
|
||||
if(result.bytesTotal > 0)
|
||||
result.percentage = (uint8_t) ((result.bytesUsed / (long double) result.bytesTotal) * 100.0);
|
||||
else
|
||||
result.percentage = 0;
|
||||
calculatePercentage(&result.ram);
|
||||
calculatePercentage(&result.swap);
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,11 +5,17 @@
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
typedef struct FFMemoryResult
|
||||
typedef struct FFMemoryStorage
|
||||
{
|
||||
uint64_t bytesUsed;
|
||||
uint64_t bytesTotal;
|
||||
uint8_t percentage;
|
||||
} FFMemoryStorage;
|
||||
|
||||
typedef struct FFMemoryResult
|
||||
{
|
||||
FFMemoryStorage ram;
|
||||
FFMemoryStorage swap;
|
||||
} FFMemoryResult;
|
||||
|
||||
const FFMemoryResult* ffDetectMemory();
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
#include "memory.h"
|
||||
#include "common/settings.h"
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include <mach/mach.h>
|
||||
|
||||
void ffDetectMemoryImpl(FFMemoryResult* memory)
|
||||
{
|
||||
memory->bytesTotal = (uint64_t) ffSettingsGetAppleInt64("hw.memsize", 0);
|
||||
memset(memory, 0, sizeof(FFMemoryResult));
|
||||
|
||||
memory->bytesUsed = 0;
|
||||
memory->ram.bytesTotal = (uint64_t) ffSettingsGetAppleInt64("hw.memsize", 0);
|
||||
|
||||
uint32_t pagesize = (uint32_t) ffSettingsGetAppleInt("hw.pagesize", 0);
|
||||
if(pagesize == 0)
|
||||
@@ -18,5 +20,5 @@ void ffDetectMemoryImpl(FFMemoryResult* memory)
|
||||
if(host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t) (&vmstat), &count) != KERN_SUCCESS)
|
||||
return;
|
||||
|
||||
memory->bytesUsed = ((uint64_t) vmstat.active_count + vmstat.wire_count) * pagesize;
|
||||
memory->ram.bytesUsed = ((uint64_t) vmstat.active_count + vmstat.wire_count) * pagesize;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "memory.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void ffDetectMemoryImpl(FFMemoryResult* memory)
|
||||
{
|
||||
memory->bytesUsed = 0;
|
||||
memory->bytesTotal = 0;
|
||||
memset(memory, 0, sizeof(FFMemoryResult));
|
||||
|
||||
FILE* meminfo = fopen("/proc/meminfo", "r");
|
||||
if(meminfo == NULL)
|
||||
@@ -19,7 +19,9 @@ void ffDetectMemoryImpl(FFMemoryResult* memory)
|
||||
memFree = 0,
|
||||
buffers = 0,
|
||||
cached = 0,
|
||||
sReclaimable = 0;
|
||||
sReclaimable = 0,
|
||||
swapTotal = 0,
|
||||
swapFree = 0;
|
||||
|
||||
while (getline(&line, &len, meminfo) != EOF)
|
||||
{
|
||||
@@ -29,6 +31,8 @@ void ffDetectMemoryImpl(FFMemoryResult* memory)
|
||||
sscanf(line, "Buffers: %u", &buffers);
|
||||
sscanf(line, "Cached: %u", &cached);
|
||||
sscanf(line, "SReclaimable: %u", &sReclaimable);
|
||||
sscanf(line, "SwapTotal: %u", &swapTotal);
|
||||
sscanf(line, "SwapFree: %u", &swapFree);
|
||||
}
|
||||
|
||||
if(line != NULL)
|
||||
@@ -36,6 +40,9 @@ void ffDetectMemoryImpl(FFMemoryResult* memory)
|
||||
|
||||
fclose(meminfo);
|
||||
|
||||
memory->bytesTotal = memTotal * (uint64_t) 1024;
|
||||
memory->bytesUsed = (memTotal + shmem - memFree - buffers - cached - sReclaimable) * (uint64_t) 1024;
|
||||
memory->ram.bytesTotal = memTotal * (uint64_t) 1024;
|
||||
memory->ram.bytesUsed = (memTotal + shmem - memFree - buffers - cached - sReclaimable) * (uint64_t) 1024;
|
||||
|
||||
memory->swap.bytesTotal = swapTotal * (uint64_t) 1024;
|
||||
memory->swap.bytesUsed = (swapTotal - swapFree) * (uint64_t) 1024;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user