[Libguestfs] [PATCH nbdkit v3 3/5] filters: stats: Show time per operation

Nir Soffer nirsof at gmail.com
Wed Dec 4 22:34:45 UTC 2019


Use microseconds resolution so we get meaningful data even for rarely
called and fast operation like flush or extents. For consistency, use
same format in for elapsed time.
---
 filters/stats/nbdkit-stats-filter.pod | 10 +++++-----
 filters/stats/stats.c                 |  7 ++++---
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/filters/stats/nbdkit-stats-filter.pod b/filters/stats/nbdkit-stats-filter.pod
index 28693d4..0a9f10a 100644
--- a/filters/stats/nbdkit-stats-filter.pod
+++ b/filters/stats/nbdkit-stats-filter.pod
@@ -25,11 +25,11 @@ number of read, write and trim operations involved:
                  run : \
                  mkfs ext4 /dev/sda
  '
- elapsed time: 1.33377 s
- read: 248 ops, 4.75 MiB, 3.56 MiB/s
- write: 78 ops, 32.64 MiB, 24.48 MiB/s
- trim: 33 ops, 1.00 GiB, 767.75 MiB/s
- flush: 9 ops, 0 bytes, 0 bytes/s
+ elapsed time: 1.184586 s
+ read: 253 ops, 0.000342 s, 4.77 MiB, 4.03 MiB/s
+ write: 78 ops, 0.152594 s, 32.64 MiB, 27.56 MiB/s
+ trim: 33 ops, 0.000214 s, 1.00 GiB, 864.44 MiB/s
+ flush: 9 ops, 0.000003 s, 0 bytes, 0 bytes/s
 
 =head1 PARAMETERS
 
diff --git a/filters/stats/stats.c b/filters/stats/stats.c
index abcbff2..0914248 100644
--- a/filters/stats/stats.c
+++ b/filters/stats/stats.c
@@ -114,8 +114,9 @@ print_stat (const stat *st, int64_t usecs)
     char *size = humansize (st->bytes);
     char *rate = humanrate (st->bytes, usecs);
 
-    fprintf (fp, "%s: %" PRIu64 " ops, %s, %s/s\n",
-             st->name, st->ops, maybe (size), maybe (rate));
+    fprintf (fp, "%s: %" PRIu64 " ops, %.6f s, %s, %s/s\n",
+             st->name, st->ops, st->usecs / 1000000.0, maybe (size),
+             maybe (rate));
 
     free (size);
     free (rate);
@@ -125,7 +126,7 @@ print_stat (const stat *st, int64_t usecs)
 static inline void
 print_stats (int64_t usecs)
 {
-  fprintf (fp, "elapsed time: %g s\n", usecs / 1000000.);
+  fprintf (fp, "elapsed time: %.6f s\n", usecs / 1000000.);
   print_stat (&pread_st,   usecs);
   print_stat (&pwrite_st,  usecs);
   print_stat (&trim_st,    usecs);
-- 
2.21.0





More information about the Libguestfs mailing list