shithub: gefs

Download patch

ref: e373badb4eb3c4844a5e2259f278220e501e4336
parent: 73614f633a0175c704470fdbd2284938270e0f8d
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Nov 5 11:40:54 EST 2023

cons: give human-friendly units for disk usage

--- a/cache.c
+++ b/cache.c
@@ -176,7 +176,8 @@
 	assert(b->ref == 0);
 	if(checkflag(b, Bcached))
 		cachedel_lk(b->bp.addr);
-	if(checkflag(b, Bcached)) print("%B cached %#p freed %#p\n", b->bp, b->cached, b->freed);
+	if(checkflag(b, Bcached))
+		print("%B cached %#p freed %#p\n", b->bp, b->cached, b->freed);
 	lrudel(b);
 	assert(!checkflag(b, Bcached));
 	b->flag = 0;
--- a/cons.c
+++ b/cons.c
@@ -161,10 +161,12 @@
 static void
 showdf(int fd, char**, int)
 {
+	char *units[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", nil};
 	vlong size, used;
+	double hsize, hused;
 	double pct;
 	Arena *a;
-	int i;
+	int i, us, uu;
 
 	size = 0;
 	used = 0;
@@ -175,8 +177,17 @@
 		used += a->used;
 		qunlock(a);
 	}
+	hsize = size;
+	hused = used;
+	for(us = 0; us < nelem(units)-1 && hsize >= 500 ; us++)
+		hsize /= 1024;
+	for(uu = 0; uu < nelem(units)-1 && hused >= 500 ; uu++)
+		hused /= 1024;
 	pct = 100.0*(double)used/(double)size;
-	fprint(fd, "used: %lld / %lld (%.2f%%)\n", used, size, pct);
+	fprint(fd, "fill:\t%.2f%%\n", pct);
+	fprint(fd, "used:\t%lld (%.2f %s)\n", used, hused, units[uu]);
+	fprint(fd, "avail:\t%lld (%.2f %s)\n", size, hsize, units[us]);
+
 }
 
 static void