mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
Swap: improve performance on Linux
We can't do the same thing with memory because there is no `cachedram` in `struct sysinfo`
This commit is contained in:
@@ -1,34 +1,13 @@
|
||||
#include "swap.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
void ffDetectSwap(FFMemoryStorage* swap)
|
||||
{
|
||||
FILE* meminfo = fopen("/proc/meminfo", "r");
|
||||
if(meminfo == NULL)
|
||||
{
|
||||
ffStrbufAppendS(&swap->error, "Failed to open /proc/meminfo");
|
||||
return;
|
||||
}
|
||||
struct sysinfo info;
|
||||
if(sysinfo(&info) != 0)
|
||||
ffStrbufAppendS(&swap->error, "sysinfo() failed");
|
||||
|
||||
char* line = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
uint32_t swapTotal = 0,
|
||||
swapFree = 0;
|
||||
|
||||
while (getline(&line, &len, meminfo) != EOF)
|
||||
{
|
||||
if(!sscanf(line, "SwapTotal: %u", &swapTotal))
|
||||
sscanf(line, "SwapFree: %u", &swapFree);
|
||||
}
|
||||
|
||||
if(line != NULL)
|
||||
free(line);
|
||||
|
||||
fclose(meminfo);
|
||||
|
||||
swap->bytesTotal = swapTotal * (uint64_t) 1024;
|
||||
swap->bytesUsed = (swapTotal - swapFree) * (uint64_t) 1024;
|
||||
swap->bytesTotal = info.totalswap * (uint64_t) info.mem_unit;
|
||||
swap->bytesUsed = (info.totalswap - info.freeswap) * (uint64_t) info.mem_unit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user