mirror of
https://github.com/pikami/slstatus.git
synced 2024-11-27 22:05:42 +00:00
Changed RAM calculation formula.
Former : MemTotal - MemAvailable New : (MemTotal - MemFree) - (Buffers + Cached)
This commit is contained in:
parent
2fb476aaf6
commit
e241dbeba4
@ -162,7 +162,7 @@ char *
|
|||||||
get_ram_usage()
|
get_ram_usage()
|
||||||
{
|
{
|
||||||
int ram_perc;
|
int ram_perc;
|
||||||
long total, free, available;
|
long total, free, buffers, cached;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
/* open meminfo file */
|
/* open meminfo file */
|
||||||
@ -174,13 +174,14 @@ get_ram_usage()
|
|||||||
/* read the values */
|
/* read the values */
|
||||||
fscanf(fp, "MemTotal: %ld kB\n", &total);
|
fscanf(fp, "MemTotal: %ld kB\n", &total);
|
||||||
fscanf(fp, "MemFree: %ld kB\n", &free);
|
fscanf(fp, "MemFree: %ld kB\n", &free);
|
||||||
fscanf(fp, "MemAvailable: %ld kB\n", &available);
|
fscanf(fp, "MemAvailable: %ld kB\nBuffers: %ld kB\n", &buffers, &buffers);
|
||||||
|
fscanf(fp, "Cached: %ld kB\n", &cached);
|
||||||
|
|
||||||
/* close meminfo file */
|
/* close meminfo file */
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
/* calculate percentage */
|
/* calculate percentage */
|
||||||
ram_perc = 100 * (total - available) / total;
|
ram_perc = 100 * ((total - free) - (buffers + cached)) / total;
|
||||||
|
|
||||||
/* return ram_perc as string */
|
/* return ram_perc as string */
|
||||||
return smprintf("%d%%",ram_perc);
|
return smprintf("%d%%",ram_perc);
|
||||||
|
Loading…
Reference in New Issue
Block a user