ref: 821f716f5d2851e636b927561241318cc5a21fbd
parent: 7f9dc8e78ccd685387b0962fe61c671cd0a23f9e
author: Ori Bernstein <[email protected]>
date: Mon Jan 8 13:11:54 EST 2024
cons: show free space correctly in df
--- a/cons.c
+++ b/cons.c
@@ -207,11 +207,11 @@
showdf(int fd, char**, int)
{
char *units[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", nil};
- vlong size, used;
- double hsize, hused;
+ vlong size, used, free;
+ double hsize, hused, hfree;
double pct;
Arena *a;
- int i, us, uu;
+ int i, us, uu, uf;
size = 0;
used = 0;
@@ -223,17 +223,21 @@
qunlock(a);
fprint(fd, "arena %d: %llx/%llx (%.2f%%)\n", i, a->used, a->size, 100*(double)a->used/(double)a->size);
}
+ free = size - used;
hsize = size;
hused = used;
+ hfree = free;
for(us = 0; us < nelem(units)-1 && hsize >= 500 ; us++)
hsize /= 1024;
for(uu = 0; uu < nelem(units)-1 && hused >= 500 ; uu++)
hused /= 1024;
+ for(uf = 0; uf < nelem(units)-1 && hfree >= 500 ; uf++)
+ hfree /= 1024;
pct = 100.0*(double)used/(double)size;
fprint(fd, "fill:\t%.2f%%\n", pct);
fprint(fd, "used:\t%lld (%.2f %s)\n", used, hused, units[uu]);
fprint(fd, "size:\t%lld (%.2f %s)\n", size, hsize, units[us]);
- fprint(fd, "free:\t%lld (%.2f %s)\n", size-used, hsize, units[us]);
+ fprint(fd, "free:\t%lld (%.2f %s)\n", free, hfree, units[uf]);
}
void