I find bytes and bits-per-second unhelpful and hard to parse.
Add also size in GiB, and show rate in MiB per second. This works
well for common disk images and storage.
Here is an example run with this change:
$ ./nbdkit --foreground \
--unix /tmp/nbd.sock \
--exportname '' \
--filter stats \
file file=/var/tmp/dst.img \
statsfile=/dev/stderr \
--run 'qemu-img convert -p -n -f raw -O raw -T none /var/tmp/fedora-30.img
nbd:unix:/tmp/nbd.sock'
(100.00/100%)
elapsed time: 2.055 s
write: 1271 ops, 1219244032 bytes, 1.136 GiB, 565.710 MiB/s
zero: 1027 ops, 5223206912 bytes, 4.864 GiB, 2423.486 MiB/s
extents: 1 ops, 2147483136 bytes, 2.000 GiB, 996.399 MiB/s
---
filters/stats/stats.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/filters/stats/stats.c b/filters/stats/stats.c
index ffc367c..6bef65c 100644
--- a/filters/stats/stats.c
+++ b/filters/stats/stats.c
@@ -49,6 +49,10 @@
#include "cleanup.h"
#include "tvdiff.h"
+#define MiB 1048576.0
+#define GiB 1073741824.0
+#define USEC 1000000.0
+
static char *filename;
static bool append;
static FILE *fp;
@@ -70,29 +74,35 @@ static stat extents_st = { "extents" };
static stat cache_st = { "cache" };
static inline double
-calc_bps (uint64_t bytes, int64_t usecs)
+calc_rate (uint64_t bytes, int64_t usecs)
{
- return 8.0 * bytes / usecs * 1000000.;
+ return bytes / MiB / usecs * USEC;
}
static inline void
print_stat (const stat *st, int64_t usecs)
{
if (st->ops > 0)
- fprintf (fp, "%s: %" PRIu64 " ops, %" PRIu64 " bytes, %g
bits/s\n",
- st->name, st->ops, st->bytes, calc_bps (st->bytes, usecs));
+ fprintf (fp, "%s: %" PRIu64 " ops, %" PRIu64 " bytes, %.3f
GiB, %.3f MiB/s\n",
+ st->name,
+ st->ops,
+ st->bytes,
+ st->bytes / GiB,
+ calc_rate (st->bytes, usecs));
}
static inline void
print_stats (int64_t usecs)
{
- fprintf (fp, "elapsed time: %g s\n", usecs / 1000000.);
+ fprintf (fp, "elapsed time: %.3f s\n", usecs / USEC);
+
print_stat (&pread_st, usecs);
print_stat (&pwrite_st, usecs);
print_stat (&trim_st, usecs);
print_stat (&zero_st, usecs);
print_stat (&extents_st, usecs);
print_stat (&cache_st, usecs);
+
fflush (fp);
}
--
2.21.0