Blame SOURCES/0002-vddk-Extend-D-vddk.stats-1-to-show-number-of-calls-a.patch

e7ca0c
From 262f7fcd22dd57ae30739703c94bc56f32a8ceec Mon Sep 17 00:00:00 2001
7084e2
From: "Richard W.M. Jones" <rjones@redhat.com>
7084e2
Date: Thu, 21 Oct 2021 15:10:00 +0100
7084e2
Subject: [PATCH] vddk: Extend -D vddk.stats=1 to show number of calls and
7084e2
 bytes transferred
7084e2
MIME-Version: 1.0
7084e2
Content-Type: text/plain; charset=UTF-8
7084e2
Content-Transfer-Encoding: 8bit
7084e2
7084e2
The new output looks like this:
7084e2
7084e2
nbdkit: debug: VDDK function stats (-D vddk.stats=1):
7084e2
nbdkit: debug: VixDiskLib_...                        µs calls           bytes
7084e2
nbdkit: debug:   Exit                           1000854     1
7084e2
nbdkit: debug:   InitEx                           79304     1
7084e2
nbdkit: debug:   Flush                            13577     1
7084e2
nbdkit: debug:   Write                            12534    21        10485760
7084e2
nbdkit: debug:   Open                              4753     3
7084e2
nbdkit: debug:   Read                               966    20         5242880
7084e2
nbdkit: debug:   Close                              574     3
7084e2
nbdkit: debug:   QueryAllocatedBlocks               116     4
7084e2
nbdkit: debug:   ConnectEx                          103     3
7084e2
nbdkit: debug:   Disconnect                          88     3
7084e2
nbdkit: debug:   GetTransportMode                    68     3
7084e2
nbdkit: debug:   GetInfo                             46     3
7084e2
nbdkit: debug:   FreeConnectParams                   36     3
7084e2
nbdkit: debug:   FreeInfo                            36     3
7084e2
nbdkit: debug:   FreeBlockList                       22     4
7084e2
nbdkit: debug:   AllocateConnectParams               22     3
7084e2
(cherry picked from commit 5c80f0d290db45a679d55baf37ff39bacb8ce7ec)
7084e2
---
7084e2
 plugins/vddk/nbdkit-vddk-plugin.pod |  3 +--
7084e2
 plugins/vddk/vddk.c                 | 41 +++++++++++++++++++++++++----
7084e2
 2 files changed, 37 insertions(+), 7 deletions(-)
7084e2
7084e2
diff --git a/plugins/vddk/nbdkit-vddk-plugin.pod b/plugins/vddk/nbdkit-vddk-plugin.pod
7084e2
index 078badcc..e53d3286 100644
7084e2
--- a/plugins/vddk/nbdkit-vddk-plugin.pod
7084e2
+++ b/plugins/vddk/nbdkit-vddk-plugin.pod
7084e2
@@ -517,8 +517,7 @@ Suppress debugging of datapath calls (C<Read> and C<Write>).
7084e2
 
7084e2
 =item B<-D vddk.stats=1>
7084e2
 
7084e2
-When the plugin exits print some statistics about the amount of time
7084e2
-spent waiting on each VDDK call.
7084e2
+When the plugin exits print some statistics about each VDDK call.
7084e2
 
7084e2
 =back
7084e2
 
7084e2
diff --git a/plugins/vddk/vddk.c b/plugins/vddk/vddk.c
7084e2
index 3d751544..5f1d223b 100644
7084e2
--- a/plugins/vddk/vddk.c
7084e2
+++ b/plugins/vddk/vddk.c
7084e2
@@ -106,6 +106,8 @@ static bool is_remote;
7084e2
 struct vddk_stat {
7084e2
   const char *name;             /* function name */
7084e2
   int64_t usecs;                /* total number of usecs consumed */
7084e2
+  uint64_t calls;               /* number of times called */
7084e2
+  uint64_t bytes;               /* bytes transferred, datapath calls only */
7084e2
 };
7084e2
 static pthread_mutex_t stats_lock = PTHREAD_MUTEX_INITIALIZER;
7084e2
 static void display_stats (void);
7084e2
@@ -141,6 +143,17 @@ static void display_stats (void);
7084e2
     gettimeofday (&end_t, NULL);                        \
7084e2
     ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&stats_lock);       \
7084e2
     stats_##fn.usecs += tvdiff_usec (&start_t, &end_t); \
7084e2
+    stats_##fn.calls++;                                 \
7084e2
+  }                                                     \
7084e2
+  } while (0)
7084e2
+#define VDDK_CALL_END_DATAPATH(fn, bytes_)              \
7084e2
+  while (0);                                            \
7084e2
+  if (vddk_debug_stats) {                               \
7084e2
+    gettimeofday (&end_t, NULL);                        \
7084e2
+    ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&stats_lock);       \
7084e2
+    stats_##fn.usecs += tvdiff_usec (&start_t, &end_t); \
7084e2
+    stats_##fn.calls++;                                 \
7084e2
+    stats_##fn.bytes += bytes_;                         \
7084e2
   }                                                     \
7084e2
   } while (0)
7084e2
 
7084e2
@@ -191,6 +204,12 @@ stat_compare (const void *vp1, const void *vp2)
7084e2
   else return 0;
7084e2
 }
7084e2
 
7084e2
+static const char *
7084e2
+api_name_without_prefix (const char *name)
7084e2
+{
7084e2
+  return strncmp (name, "VixDiskLib_", 11) == 0 ? name + 11 : name;
7084e2
+}
7084e2
+
7084e2
 static void
7084e2
 display_stats (void)
7084e2
 {
7084e2
@@ -206,10 +225,22 @@ display_stats (void)
7084e2
   qsort (stats.ptr, stats.size, sizeof stats.ptr[0], stat_compare);
7084e2
 
7084e2
   nbdkit_debug ("VDDK function stats (-D vddk.stats=1):");
7084e2
-  nbdkit_debug ("%-40s  %9s", "", "µs");
7084e2
+  nbdkit_debug ("%-24s  %15s %5s %15s",
7084e2
+                "VixDiskLib_...", "µs", "calls", "bytes");
7084e2
   for (i = 0; i < stats.size; ++i) {
7084e2
-    if (stats.ptr[i].usecs)
7084e2
-      nbdkit_debug ("%-40s %9" PRIi64, stats.ptr[i].name, stats.ptr[i].usecs);
7084e2
+    if (stats.ptr[i].usecs) {
7084e2
+      if (stats.ptr[i].bytes > 0)
7084e2
+        nbdkit_debug ("  %-22s %15" PRIi64 " %5" PRIu64 " %15" PRIu64,
7084e2
+                      api_name_without_prefix (stats.ptr[i].name),
7084e2
+                      stats.ptr[i].usecs,
7084e2
+                      stats.ptr[i].calls,
7084e2
+                      stats.ptr[i].bytes);
7084e2
+      else
7084e2
+        nbdkit_debug ("  %-22s %15" PRIi64 " %5" PRIu64,
7084e2
+                      api_name_without_prefix (stats.ptr[i].name),
7084e2
+                      stats.ptr[i].usecs,
7084e2
+                      stats.ptr[i].calls);
7084e2
+    }
7084e2
   }
7084e2
   statlist_reset (&stats);
7084e2
 }
7084e2
@@ -831,7 +862,7 @@ vddk_pread (void *handle, void *buf, uint32_t count, uint64_t offset,
7084e2
                             "%" PRIu32 " sectors, buffer",
7084e2
                             offset, count) {
7084e2
     err = VixDiskLib_Read (h->handle, offset, count, buf);
7084e2
-  } VDDK_CALL_END (VixDiskLib_Read);
7084e2
+  } VDDK_CALL_END_DATAPATH (VixDiskLib_Read, count * VIXDISKLIB_SECTOR_SIZE);
7084e2
   if (err != VIX_OK) {
7084e2
     VDDK_ERROR (err, "VixDiskLib_Read");
7084e2
     return -1;
7084e2
@@ -871,7 +902,7 @@ vddk_pwrite (void *handle, const void *buf, uint32_t count, uint64_t offset,
7084e2
                             "%" PRIu32 " sectors, buffer",
7084e2
                             offset, count) {
7084e2
     err = VixDiskLib_Write (h->handle, offset, count, buf);
7084e2
-  } VDDK_CALL_END (VixDiskLib_Write);
7084e2
+  } VDDK_CALL_END_DATAPATH (VixDiskLib_Write, count * VIXDISKLIB_SECTOR_SIZE);
7084e2
   if (err != VIX_OK) {
7084e2
     VDDK_ERROR (err, "VixDiskLib_Write");
7084e2
     return -1;
7084e2
-- 
7084e2
2.31.1
7084e2