aboutsummaryrefslogtreecommitdiffstats
path: root/src/stats.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stats.c')
-rw-r--r--src/stats.c139
1 files changed, 139 insertions, 0 deletions
diff --git a/src/stats.c b/src/stats.c
new file mode 100644
index 0000000..1fb7c03
--- /dev/null
+++ b/src/stats.c
@@ -0,0 +1,139 @@
+#include "project.h"
+
+uint64_t stats_inodes;
+uint64_t stats_ea_blocks;
+uint64_t stats_bytes;
+static uint64_t last_bytes;
+
+
+struct timeval start_time, last_time;
+
+static int first = 1;
+
+
+
+static int do_time (char *ptr, double t)
+{
+ double h, m, s;
+
+ if (t < 60.0)
+ return sprintf (ptr, "%.1fs", t);
+
+ if (t < 3600.0) {
+ m = floor (t / 60.0);
+ t -= 60 * m;
+ s = floor (t);
+ t -= s;
+ t *= 10;
+ return sprintf (ptr, "%d:%02d.%dm", (int) m, (int) s, (int) t);
+ }
+
+ h = floor (t / 3600.0);
+ t -= 3600 * h;
+ m = floor (t / 60.0);
+ t -= 60 * m;
+ s = floor (t);
+ t -= s;
+ t *= 10;
+ return sprintf (ptr, "%d:%02d:%02d.%dh", (int) h, (int) m, (int) s,
+ (int) t);
+}
+
+static int do_rate (char *ptr, double r)
+{
+ if (r < 1024.0)
+ return sprintf (ptr, "%.1f b", r);
+
+ if (r < 1048576.0)
+ return sprintf (ptr, "%.1f K", r / 1024.0);
+
+ if (r < 1073741824.0)
+ return sprintf (ptr, "%.1f M", r / 1048576.0);
+
+ return sprintf (ptr, "%.1f G", r / 1073741824.0);
+}
+
+
+void stats (int force)
+{
+ struct timeval now, diff1, diff2;
+ char charbuf[128], *ptr = charbuf;
+ double totaltime, totalbytes, intertime, interbytes;
+
+ gettimeofday (&now, NULL);
+
+
+ if (first) {
+ first = 0;
+ last_time = now;
+ start_time = now;
+ return;
+ }
+
+
+ timersub (&now, &last_time, &diff1);
+
+ if ((!force) && (diff1.tv_sec < 10))
+ return;
+
+ timersub (&now, &start_time, &diff2);
+
+ intertime = (double) diff1.tv_usec;
+ intertime /= 1000000.0;
+ intertime += (double) diff1.tv_sec;
+
+ totaltime = (double) diff2.tv_usec;
+ totaltime /= 1000000.0;
+ totaltime += (double) diff2.tv_sec;
+
+ totalbytes = (double) stats_bytes;
+ interbytes = stats_bytes - (double) last_bytes;
+
+ last_bytes = stats_bytes;
+ last_time = now;
+
+ intertime += 0.001;
+ totaltime += 0.001;
+
+ ptr += do_time (ptr, totaltime);
+ ptr += sprintf (ptr, " rate:");
+ ptr += do_rate (ptr, interbytes / intertime);
+ ptr += sprintf (ptr, "/");
+ ptr += do_rate (ptr, totalbytes / totaltime);
+ ptr += sprintf (ptr, " bytes:");
+ ptr += do_rate (ptr, totalbytes);
+ ptr += sprintf (ptr, " inodes %lld ea_blocks %lld\n",
+ (long long int) stats_inodes, (long long int) stats_ea_blocks);
+ fputs (charbuf, stderr);
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+