[libvirt] [PATCH 3/7] Move dtrace probe macros into separate header file

Daniel P. Berrange berrange at redhat.com
Mon Mar 3 19:18:08 UTC 2014


The dtrace probe macros rely on the logging API. We can't make
the internal.h header include the virlog.h header though since
that'd be a circular include. Instead simply split the dtrace
probes into their own header file, since there's no compelling
reason for them to be in the main internal.h header.

Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
---
 daemon/remote.c              |   1 +
 src/internal.h               |  74 --------------------------------
 src/qemu/qemu_monitor.c      |   1 +
 src/qemu/qemu_monitor_json.c |   1 +
 src/qemu/qemu_monitor_text.c |   1 +
 src/rpc/virkeepalive.c       |   1 +
 src/rpc/virnetclient.c       |   1 +
 src/rpc/virnetserverclient.c |   1 +
 src/rpc/virnetsocket.c       |   1 +
 src/rpc/virnettlscontext.c   |   1 +
 src/util/vireventpoll.c      |   1 +
 src/util/virobject.c         |   1 +
 src/util/virprobe.h          | 100 +++++++++++++++++++++++++++++++++++++++++++
 13 files changed, 111 insertions(+), 74 deletions(-)
 create mode 100644 src/util/virprobe.h

diff --git a/daemon/remote.c b/daemon/remote.c
index 932f65f..3db5df3 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -52,6 +52,7 @@
 #include "object_event.h"
 #include "domain_conf.h"
 #include "network_conf.h"
+#include "virprobe.h"
 #include "viraccessapicheck.h"
 
 #define VIR_FROM_THIS VIR_FROM_RPC
diff --git a/src/internal.h b/src/internal.h
index cef3da0..dc1899e 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -365,78 +365,4 @@
 /* round up value to the closest multiple of size */
 # define VIR_ROUND_UP(value, size) (VIR_DIV_UP(value, size) * (size))
 
-
-# if WITH_DTRACE_PROBES
-#  ifndef LIBVIRT_PROBES_H
-#   define LIBVIRT_PROBES_H
-#   include "libvirt_probes.h"
-#  endif /* LIBVIRT_PROBES_H */
-
-/* Systemtap 1.2 headers have a bug where they cannot handle a
- * variable declared with array type.  Work around this by casting all
- * arguments.  This is some gross use of the preprocessor because
- * PROBE is a var-arg macro, but it is better than the alternative of
- * making all callers to PROBE have to be aware of the issues.  And
- * hopefully, if we ever add a call to PROBE with other than 9
- * end arguments, you can figure out the pattern to extend this hack.
- */
-#  define VIR_COUNT_ARGS(...) VIR_ARG11(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
-#  define VIR_ARG11(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, ...) _11
-#  define VIR_ADD_CAST_EXPAND(a, b, ...) VIR_ADD_CAST_PASTE(a, b, __VA_ARGS__)
-#  define VIR_ADD_CAST_PASTE(a, b, ...) a##b(__VA_ARGS__)
-
-/* The double cast is necessary to silence gcc warnings; any pointer
- * can safely go to intptr_t and back to void *, which collapses
- * arrays into pointers; while any integer can be widened to intptr_t
- * then cast to void *.  */
-#  define VIR_ADD_CAST(a) ((void *)(intptr_t)(a))
-#  define VIR_ADD_CAST1(a)                                  \
-    VIR_ADD_CAST(a)
-#  define VIR_ADD_CAST2(a, b)                               \
-    VIR_ADD_CAST(a), VIR_ADD_CAST(b)
-#  define VIR_ADD_CAST3(a, b, c)                            \
-    VIR_ADD_CAST(a), VIR_ADD_CAST(b), VIR_ADD_CAST(c)
-#  define VIR_ADD_CAST4(a, b, c, d)                         \
-    VIR_ADD_CAST(a), VIR_ADD_CAST(b), VIR_ADD_CAST(c),      \
-    VIR_ADD_CAST(d)
-#  define VIR_ADD_CAST5(a, b, c, d, e)                      \
-    VIR_ADD_CAST(a), VIR_ADD_CAST(b), VIR_ADD_CAST(c),      \
-    VIR_ADD_CAST(d), VIR_ADD_CAST(e)
-#  define VIR_ADD_CAST6(a, b, c, d, e, f)                   \
-    VIR_ADD_CAST(a), VIR_ADD_CAST(b), VIR_ADD_CAST(c),      \
-    VIR_ADD_CAST(d), VIR_ADD_CAST(e), VIR_ADD_CAST(f)
-#  define VIR_ADD_CAST7(a, b, c, d, e, f, g)                \
-    VIR_ADD_CAST(a), VIR_ADD_CAST(b), VIR_ADD_CAST(c),      \
-    VIR_ADD_CAST(d), VIR_ADD_CAST(e), VIR_ADD_CAST(f),      \
-    VIR_ADD_CAST(g)
-#  define VIR_ADD_CAST8(a, b, c, d, e, f, g, h)             \
-    VIR_ADD_CAST(a), VIR_ADD_CAST(b), VIR_ADD_CAST(c),      \
-    VIR_ADD_CAST(d), VIR_ADD_CAST(e), VIR_ADD_CAST(f),      \
-    VIR_ADD_CAST(g), VIR_ADD_CAST(h)
-#  define VIR_ADD_CAST9(a, b, c, d, e, f, g, h, i)          \
-    VIR_ADD_CAST(a), VIR_ADD_CAST(b), VIR_ADD_CAST(c),      \
-    VIR_ADD_CAST(d), VIR_ADD_CAST(e), VIR_ADD_CAST(f),      \
-    VIR_ADD_CAST(g), VIR_ADD_CAST(h), VIR_ADD_CAST(i)
-
-#  define VIR_ADD_CASTS(...)                                            \
-    VIR_ADD_CAST_EXPAND(VIR_ADD_CAST, VIR_COUNT_ARGS(__VA_ARGS__),      \
-                        __VA_ARGS__)
-
-#  define PROBE_EXPAND(NAME, ARGS) NAME(ARGS)
-#  define PROBE(NAME, FMT, ...)                              \
-    VIR_DEBUG_INT(VIR_LOG_FROM_TRACE,                        \
-                  __FILE__, __LINE__, __func__,              \
-                  #NAME ": " FMT, __VA_ARGS__);              \
-    if (LIBVIRT_ ## NAME ## _ENABLED()) {                    \
-        PROBE_EXPAND(LIBVIRT_ ## NAME,                       \
-                     VIR_ADD_CASTS(__VA_ARGS__));            \
-    }
-# else
-#  define PROBE(NAME, FMT, ...)                              \
-    VIR_DEBUG_INT(VIR_LOG_FROM_TRACE,                        \
-                  __FILE__, __LINE__, __func__,              \
-                  #NAME ": " FMT, __VA_ARGS__);
-# endif
-
-
 #endif                          /* __VIR_INTERNAL_H__ */
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index a2769db..8f8f5c3 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -40,6 +40,7 @@
 #include "virfile.h"
 #include "virprocess.h"
 #include "virobject.h"
+#include "virprobe.h"
 #include "virstring.h"
 
 #ifdef WITH_DTRACE_PROBES
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 5e825ac..0b39bf7 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -41,6 +41,7 @@
 #include "datatypes.h"
 #include "virerror.h"
 #include "virjson.h"
+#include "virprobe.h"
 #include "virstring.h"
 #include "cpu/cpu_x86.h"
 
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 7b81079..6e520bd 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -40,6 +40,7 @@
 #include "datatypes.h"
 #include "virerror.h"
 #include "virbuffer.h"
+#include "virprobe.h"
 #include "virstring.h"
 
 #ifdef WITH_DTRACE_PROBES
diff --git a/src/rpc/virkeepalive.c b/src/rpc/virkeepalive.c
index 8ae5c6c..fcc43ad 100644
--- a/src/rpc/virkeepalive.c
+++ b/src/rpc/virkeepalive.c
@@ -30,6 +30,7 @@
 #include "virnetsocket.h"
 #include "virkeepaliveprotocol.h"
 #include "virkeepalive.h"
+#include "virprobe.h"
 
 #define VIR_FROM_THIS VIR_FROM_RPC
 
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 9deec9e..fe3e055 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -36,6 +36,7 @@
 #include "virlog.h"
 #include "virutil.h"
 #include "virerror.h"
+#include "virprobe.h"
 #include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_RPC
diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
index 52b4941..7b6d82d 100644
--- a/src/rpc/virnetserverclient.c
+++ b/src/rpc/virnetserverclient.c
@@ -35,6 +35,7 @@
 #include "viralloc.h"
 #include "virthread.h"
 #include "virkeepalive.h"
+#include "virprobe.h"
 #include "virstring.h"
 #include "virutil.h"
 
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 04bf25a..be1df6c 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -51,6 +51,7 @@
 #include "virlog.h"
 #include "virfile.h"
 #include "virthread.h"
+#include "virprobe.h"
 #include "virprocess.h"
 #include "virstring.h"
 #include "passfd.h"
diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c
index cd69794..27a00d0 100644
--- a/src/rpc/virnettlscontext.c
+++ b/src/rpc/virnettlscontext.c
@@ -39,6 +39,7 @@
 #include "virfile.h"
 #include "virutil.h"
 #include "virlog.h"
+#include "virprobe.h"
 #include "virthread.h"
 #include "configmake.h"
 
diff --git a/src/util/vireventpoll.c b/src/util/vireventpoll.c
index 8a4c8bc..6f1e184 100644
--- a/src/util/vireventpoll.c
+++ b/src/util/vireventpoll.c
@@ -38,6 +38,7 @@
 #include "virutil.h"
 #include "virfile.h"
 #include "virerror.h"
+#include "virprobe.h"
 #include "virtime.h"
 
 #define EVENT_DEBUG(fmt, ...) VIR_DEBUG(fmt, __VA_ARGS__)
diff --git a/src/util/virobject.c b/src/util/virobject.c
index 4f83bc1..5e3ee71 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -28,6 +28,7 @@
 #include "viratomic.h"
 #include "virerror.h"
 #include "virlog.h"
+#include "virprobe.h"
 #include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
diff --git a/src/util/virprobe.h b/src/util/virprobe.h
new file mode 100644
index 0000000..1891135
--- /dev/null
+++ b/src/util/virprobe.h
@@ -0,0 +1,100 @@
+/*
+ * virlog.h: internal logging and debugging
+ *
+ * Copyright (C) 2006-2008, 2011-2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __VIR_PROBE_H__
+# define __VIR_PROBE_H__
+
+# include "internal.h"
+# include "virlog.h"
+
+# if WITH_DTRACE_PROBES
+#  ifndef LIBVIRT_PROBES_H
+#   define LIBVIRT_PROBES_H
+#   include "libvirt_probes.h"
+#  endif /* LIBVIRT_PROBES_H */
+
+/* Systemtap 1.2 headers have a bug where they cannot handle a
+ * variable declared with array type.  Work around this by casting all
+ * arguments.  This is some gross use of the preprocessor because
+ * PROBE is a var-arg macro, but it is better than the alternative of
+ * making all callers to PROBE have to be aware of the issues.  And
+ * hopefully, if we ever add a call to PROBE with other than 9
+ * end arguments, you can figure out the pattern to extend this hack.
+ */
+#  define VIR_COUNT_ARGS(...) VIR_ARG11(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
+#  define VIR_ARG11(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, ...) _11
+#  define VIR_ADD_CAST_EXPAND(a, b, ...) VIR_ADD_CAST_PASTE(a, b, __VA_ARGS__)
+#  define VIR_ADD_CAST_PASTE(a, b, ...) a##b(__VA_ARGS__)
+
+/* The double cast is necessary to silence gcc warnings; any pointer
+ * can safely go to intptr_t and back to void *, which collapses
+ * arrays into pointers; while any integer can be widened to intptr_t
+ * then cast to void *.  */
+#  define VIR_ADD_CAST(a) ((void *)(intptr_t)(a))
+#  define VIR_ADD_CAST1(a)                                  \
+    VIR_ADD_CAST(a)
+#  define VIR_ADD_CAST2(a, b)                               \
+    VIR_ADD_CAST(a), VIR_ADD_CAST(b)
+#  define VIR_ADD_CAST3(a, b, c)                            \
+    VIR_ADD_CAST(a), VIR_ADD_CAST(b), VIR_ADD_CAST(c)
+#  define VIR_ADD_CAST4(a, b, c, d)                         \
+    VIR_ADD_CAST(a), VIR_ADD_CAST(b), VIR_ADD_CAST(c),      \
+    VIR_ADD_CAST(d)
+#  define VIR_ADD_CAST5(a, b, c, d, e)                      \
+    VIR_ADD_CAST(a), VIR_ADD_CAST(b), VIR_ADD_CAST(c),      \
+    VIR_ADD_CAST(d), VIR_ADD_CAST(e)
+#  define VIR_ADD_CAST6(a, b, c, d, e, f)                   \
+    VIR_ADD_CAST(a), VIR_ADD_CAST(b), VIR_ADD_CAST(c),      \
+    VIR_ADD_CAST(d), VIR_ADD_CAST(e), VIR_ADD_CAST(f)
+#  define VIR_ADD_CAST7(a, b, c, d, e, f, g)                \
+    VIR_ADD_CAST(a), VIR_ADD_CAST(b), VIR_ADD_CAST(c),      \
+    VIR_ADD_CAST(d), VIR_ADD_CAST(e), VIR_ADD_CAST(f),      \
+    VIR_ADD_CAST(g)
+#  define VIR_ADD_CAST8(a, b, c, d, e, f, g, h)             \
+    VIR_ADD_CAST(a), VIR_ADD_CAST(b), VIR_ADD_CAST(c),      \
+    VIR_ADD_CAST(d), VIR_ADD_CAST(e), VIR_ADD_CAST(f),      \
+    VIR_ADD_CAST(g), VIR_ADD_CAST(h)
+#  define VIR_ADD_CAST9(a, b, c, d, e, f, g, h, i)          \
+    VIR_ADD_CAST(a), VIR_ADD_CAST(b), VIR_ADD_CAST(c),      \
+    VIR_ADD_CAST(d), VIR_ADD_CAST(e), VIR_ADD_CAST(f),      \
+    VIR_ADD_CAST(g), VIR_ADD_CAST(h), VIR_ADD_CAST(i)
+
+#  define VIR_ADD_CASTS(...)                                            \
+    VIR_ADD_CAST_EXPAND(VIR_ADD_CAST, VIR_COUNT_ARGS(__VA_ARGS__),      \
+                        __VA_ARGS__)
+
+#  define PROBE_EXPAND(NAME, ARGS) NAME(ARGS)
+#  define PROBE(NAME, FMT, ...)                              \
+    VIR_DEBUG_INT(VIR_LOG_FROM_TRACE,                        \
+                  NULL, __LINE__, __func__,                  \
+                  #NAME ": " FMT, __VA_ARGS__);              \
+    if (LIBVIRT_ ## NAME ## _ENABLED()) {                    \
+        PROBE_EXPAND(LIBVIRT_ ## NAME,                       \
+                     VIR_ADD_CASTS(__VA_ARGS__));            \
+    }
+# else
+#  define PROBE(NAME, FMT, ...)                              \
+    VIR_DEBUG_INT(VIR_LOG_FROM_TRACE,                        \
+                  NULL, __LINE__, __func__,                  \
+                  #NAME ": " FMT, __VA_ARGS__);
+# endif
+
+#endif /* __VIR_PROBE_H__ */
-- 
1.8.5.3




More information about the libvir-list mailing list