|
|
7084e2 |
From d602150dbb5ebacea42c25a0f6c8c26c45766a49 Mon Sep 17 00:00:00 2001
|
|
|
7084e2 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
7084e2 |
Date: Wed, 27 Oct 2021 12:30:41 +0100
|
|
|
7084e2 |
Subject: [PATCH] vddk: Refactor -D vddk.stats=1 into a new file
|
|
|
7084e2 |
|
|
|
7084e2 |
Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
7084e2 |
(cherry picked from commit dcd5bc51ed7710c32d956345ea8da14ba15ef8f5)
|
|
|
7084e2 |
---
|
|
|
7084e2 |
plugins/vddk/Makefile.am | 1 +
|
|
|
7084e2 |
plugins/vddk/stats.c | 118 +++++++++++++++++++++++++++++++++++++++
|
|
|
7084e2 |
plugins/vddk/vddk.c | 78 +-------------------------
|
|
|
7084e2 |
plugins/vddk/vddk.h | 15 +++++
|
|
|
7084e2 |
4 files changed, 135 insertions(+), 77 deletions(-)
|
|
|
7084e2 |
create mode 100644 plugins/vddk/stats.c
|
|
|
7084e2 |
|
|
|
7084e2 |
diff --git a/plugins/vddk/Makefile.am b/plugins/vddk/Makefile.am
|
|
|
7084e2 |
index 232aaedd..4f470ff9 100644
|
|
|
7084e2 |
--- a/plugins/vddk/Makefile.am
|
|
|
7084e2 |
+++ b/plugins/vddk/Makefile.am
|
|
|
7084e2 |
@@ -46,6 +46,7 @@ nbdkit_vddk_plugin_la_SOURCES = \
|
|
|
7084e2 |
vddk.c \
|
|
|
7084e2 |
vddk.h \
|
|
|
7084e2 |
reexec.c \
|
|
|
7084e2 |
+ stats.c \
|
|
|
7084e2 |
vddk-structs.h \
|
|
|
7084e2 |
vddk-stubs.h \
|
|
|
7084e2 |
$(top_srcdir)/include/nbdkit-plugin.h \
|
|
|
7084e2 |
diff --git a/plugins/vddk/stats.c b/plugins/vddk/stats.c
|
|
|
7084e2 |
new file mode 100644
|
|
|
7084e2 |
index 00000000..18a42714
|
|
|
7084e2 |
--- /dev/null
|
|
|
7084e2 |
+++ b/plugins/vddk/stats.c
|
|
|
7084e2 |
@@ -0,0 +1,118 @@
|
|
|
7084e2 |
+/* nbdkit
|
|
|
7084e2 |
+ * Copyright (C) 2013-2021 Red Hat Inc.
|
|
|
7084e2 |
+ *
|
|
|
7084e2 |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
7084e2 |
+ * modification, are permitted provided that the following conditions are
|
|
|
7084e2 |
+ * met:
|
|
|
7084e2 |
+ *
|
|
|
7084e2 |
+ * * Redistributions of source code must retain the above copyright
|
|
|
7084e2 |
+ * notice, this list of conditions and the following disclaimer.
|
|
|
7084e2 |
+ *
|
|
|
7084e2 |
+ * * Redistributions in binary form must reproduce the above copyright
|
|
|
7084e2 |
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
7084e2 |
+ * documentation and/or other materials provided with the distribution.
|
|
|
7084e2 |
+ *
|
|
|
7084e2 |
+ * * Neither the name of Red Hat nor the names of its contributors may be
|
|
|
7084e2 |
+ * used to endorse or promote products derived from this software without
|
|
|
7084e2 |
+ * specific prior written permission.
|
|
|
7084e2 |
+ *
|
|
|
7084e2 |
+ * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
|
|
|
7084e2 |
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
7084e2 |
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
7084e2 |
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
|
|
|
7084e2 |
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
7084e2 |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
7084e2 |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
|
7084e2 |
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
7084e2 |
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
7084e2 |
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
|
7084e2 |
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
7084e2 |
+ * SUCH DAMAGE.
|
|
|
7084e2 |
+ */
|
|
|
7084e2 |
+
|
|
|
7084e2 |
+#include <config.h>
|
|
|
7084e2 |
+
|
|
|
7084e2 |
+#include <stdio.h>
|
|
|
7084e2 |
+#include <stdlib.h>
|
|
|
7084e2 |
+#include <stdint.h>
|
|
|
7084e2 |
+#include <inttypes.h>
|
|
|
7084e2 |
+
|
|
|
7084e2 |
+#include <pthread.h>
|
|
|
7084e2 |
+
|
|
|
7084e2 |
+#define NBDKIT_API_VERSION 2
|
|
|
7084e2 |
+#include <nbdkit-plugin.h>
|
|
|
7084e2 |
+
|
|
|
7084e2 |
+#include "vector.h"
|
|
|
7084e2 |
+
|
|
|
7084e2 |
+#include "vddk.h"
|
|
|
7084e2 |
+
|
|
|
7084e2 |
+/* Debug flags. */
|
|
|
7084e2 |
+NBDKIT_DLL_PUBLIC int vddk_debug_stats;
|
|
|
7084e2 |
+
|
|
|
7084e2 |
+pthread_mutex_t stats_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
7084e2 |
+
|
|
|
7084e2 |
+/* For each VDDK API define a variable to store the time taken (used
|
|
|
7084e2 |
+ * to implement -D vddk.stats=1).
|
|
|
7084e2 |
+ */
|
|
|
7084e2 |
+#define STUB(fn,ret,args) struct vddk_stat stats_##fn = { .name = #fn }
|
|
|
7084e2 |
+#define OPTIONAL_STUB(fn,ret,args) STUB(fn,ret,args)
|
|
|
7084e2 |
+#include "vddk-stubs.h"
|
|
|
7084e2 |
+#undef STUB
|
|
|
7084e2 |
+#undef OPTIONAL_STUB
|
|
|
7084e2 |
+
|
|
|
7084e2 |
+DEFINE_VECTOR_TYPE(statlist, struct vddk_stat)
|
|
|
7084e2 |
+
|
|
|
7084e2 |
+static int
|
|
|
7084e2 |
+stat_compare (const void *vp1, const void *vp2)
|
|
|
7084e2 |
+{
|
|
|
7084e2 |
+ const struct vddk_stat *st1 = vp1;
|
|
|
7084e2 |
+ const struct vddk_stat *st2 = vp2;
|
|
|
7084e2 |
+
|
|
|
7084e2 |
+ /* Note: sorts in reverse order of time spent in each API call. */
|
|
|
7084e2 |
+ if (st1->usecs < st2->usecs) return 1;
|
|
|
7084e2 |
+ else if (st1->usecs > st2->usecs) return -1;
|
|
|
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 |
+void
|
|
|
7084e2 |
+display_stats (void)
|
|
|
7084e2 |
+{
|
|
|
7084e2 |
+ statlist stats = empty_vector;
|
|
|
7084e2 |
+ size_t i;
|
|
|
7084e2 |
+
|
|
|
7084e2 |
+ if (!vddk_debug_stats) return;
|
|
|
7084e2 |
+
|
|
|
7084e2 |
+#define STUB(fn,ret,args) statlist_append (&stats, stats_##fn)
|
|
|
7084e2 |
+#define OPTIONAL_STUB(fn,ret,args) statlist_append (&stats, stats_##fn)
|
|
|
7084e2 |
+#include "vddk-stubs.h"
|
|
|
7084e2 |
+#undef STUB
|
|
|
7084e2 |
+#undef OPTIONAL_STUB
|
|
|
7084e2 |
+
|
|
|
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 ("%-24s %15s %5s %15s",
|
|
|
7084e2 |
+ "VixDiskLib_...", "µs", "calls", "bytes");
|
|
|
7084e2 |
+ for (i = 0; i < stats.size; ++i) {
|
|
|
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 |
diff --git a/plugins/vddk/vddk.c b/plugins/vddk/vddk.c
|
|
|
7084e2 |
index 041bff1a..67ac775c 100644
|
|
|
7084e2 |
--- a/plugins/vddk/vddk.c
|
|
|
7084e2 |
+++ b/plugins/vddk/vddk.c
|
|
|
7084e2 |
@@ -61,7 +61,6 @@
|
|
|
7084e2 |
NBDKIT_DLL_PUBLIC int vddk_debug_diskinfo;
|
|
|
7084e2 |
NBDKIT_DLL_PUBLIC int vddk_debug_extents;
|
|
|
7084e2 |
NBDKIT_DLL_PUBLIC int vddk_debug_datapath = 1;
|
|
|
7084e2 |
-NBDKIT_DLL_PUBLIC int vddk_debug_stats;
|
|
|
7084e2 |
|
|
|
7084e2 |
/* For each VDDK API define a global variable. These globals are
|
|
|
7084e2 |
* initialized when the plugin is loaded (by vddk_get_ready).
|
|
|
7084e2 |
@@ -99,25 +98,6 @@ bool unbuffered; /* unbuffered */
|
|
|
7084e2 |
const char *username; /* user */
|
|
|
7084e2 |
const char *vmx_spec; /* vm */
|
|
|
7084e2 |
|
|
|
7084e2 |
-/* For each VDDK API define a variable to store the time taken (used
|
|
|
7084e2 |
- * to implement -D vddk.stats=1).
|
|
|
7084e2 |
- */
|
|
|
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 |
-#define STUB(fn,ret,args) \
|
|
|
7084e2 |
- static struct vddk_stat stats_##fn = { .name = #fn }
|
|
|
7084e2 |
-#define OPTIONAL_STUB(fn,ret,args) \
|
|
|
7084e2 |
- static struct vddk_stat stats_##fn = { .name = #fn }
|
|
|
7084e2 |
-#include "vddk-stubs.h"
|
|
|
7084e2 |
-#undef STUB
|
|
|
7084e2 |
-#undef OPTIONAL_STUB
|
|
|
7084e2 |
-
|
|
|
7084e2 |
/* Unload the plugin. */
|
|
|
7084e2 |
static void
|
|
|
7084e2 |
vddk_unload (void)
|
|
|
7084e2 |
@@ -130,69 +110,13 @@ vddk_unload (void)
|
|
|
7084e2 |
if (dl)
|
|
|
7084e2 |
dlclose (dl);
|
|
|
7084e2 |
|
|
|
7084e2 |
- if (vddk_debug_stats)
|
|
|
7084e2 |
- display_stats ();
|
|
|
7084e2 |
+ display_stats ();
|
|
|
7084e2 |
|
|
|
7084e2 |
free (config);
|
|
|
7084e2 |
free (libdir);
|
|
|
7084e2 |
free (password);
|
|
|
7084e2 |
}
|
|
|
7084e2 |
|
|
|
7084e2 |
-DEFINE_VECTOR_TYPE(statlist, struct vddk_stat)
|
|
|
7084e2 |
-
|
|
|
7084e2 |
-static int
|
|
|
7084e2 |
-stat_compare (const void *vp1, const void *vp2)
|
|
|
7084e2 |
-{
|
|
|
7084e2 |
- const struct vddk_stat *st1 = vp1;
|
|
|
7084e2 |
- const struct vddk_stat *st2 = vp2;
|
|
|
7084e2 |
-
|
|
|
7084e2 |
- /* Note: sorts in reverse order of time spent in each API call. */
|
|
|
7084e2 |
- if (st1->usecs < st2->usecs) return 1;
|
|
|
7084e2 |
- else if (st1->usecs > st2->usecs) return -1;
|
|
|
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 |
- statlist stats = empty_vector;
|
|
|
7084e2 |
- size_t i;
|
|
|
7084e2 |
-
|
|
|
7084e2 |
-#define STUB(fn,ret,args) statlist_append (&stats, stats_##fn)
|
|
|
7084e2 |
-#define OPTIONAL_STUB(fn,ret,args) statlist_append (&stats, stats_##fn)
|
|
|
7084e2 |
-#include "vddk-stubs.h"
|
|
|
7084e2 |
-#undef STUB
|
|
|
7084e2 |
-#undef OPTIONAL_STUB
|
|
|
7084e2 |
-
|
|
|
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 ("%-24s %15s %5s %15s",
|
|
|
7084e2 |
- "VixDiskLib_...", "µs", "calls", "bytes");
|
|
|
7084e2 |
- for (i = 0; i < stats.size; ++i) {
|
|
|
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 |
-
|
|
|
7084e2 |
static void
|
|
|
7084e2 |
trim (char *str)
|
|
|
7084e2 |
{
|
|
|
7084e2 |
diff --git a/plugins/vddk/vddk.h b/plugins/vddk/vddk.h
|
|
|
7084e2 |
index 29775eb4..1400589d 100644
|
|
|
7084e2 |
--- a/plugins/vddk/vddk.h
|
|
|
7084e2 |
+++ b/plugins/vddk/vddk.h
|
|
|
7084e2 |
@@ -126,4 +126,19 @@ extern char *reexeced;
|
|
|
7084e2 |
extern void reexec_if_needed (const char *prepend);
|
|
|
7084e2 |
extern int restore_ld_library_path (void);
|
|
|
7084e2 |
|
|
|
7084e2 |
+/* stats.c */
|
|
|
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 |
+extern pthread_mutex_t stats_lock;
|
|
|
7084e2 |
+#define STUB(fn,ret,args) extern struct vddk_stat stats_##fn;
|
|
|
7084e2 |
+#define OPTIONAL_STUB(fn,ret,args) STUB(fn,ret,args)
|
|
|
7084e2 |
+#include "vddk-stubs.h"
|
|
|
7084e2 |
+#undef STUB
|
|
|
7084e2 |
+#undef OPTIONAL_STUB
|
|
|
7084e2 |
+extern void display_stats (void);
|
|
|
7084e2 |
+
|
|
|
7084e2 |
#endif /* NBDKIT_VDDK_H */
|
|
|
7084e2 |
--
|
|
|
7084e2 |
2.31.1
|
|
|
7084e2 |
|