[gjs] Add support for dtrace/SystemTap



commit 38281cc832aa8eb49ce9adbbe19bcf5ccbab4caf
Author: Colin Walters <walters verbum org>
Date:   Thu Apr 1 16:21:56 2010 -0400

    Add support for dtrace/SystemTap
    
    Similar to the probes that will be added to glib,
    this commit adds basic infrastructure for probes, and
    a *very* limited set of probe points.
    
    The current probe points just track proxies for GObjects; other
    ideas for useful probes would be function invocations, boxed/structs,
    etc.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=614619

 .gitignore         |    2 ++
 Makefile-gi.am     |   11 +++++++++++
 Makefile.am        |    9 +++++++++
 configure.ac       |   32 ++++++++++++++++++++++++++++++++
 gi/gjs_gi_probes.d |    4 ++++
 gi/gjs_gi_trace.h  |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 gi/object.c        |    7 +++++++
 gjs/gjs.stp.in     |   18 ++++++++++++++++++
 8 files changed, 130 insertions(+), 0 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 72a2b2c..2fc3d5f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,6 +29,8 @@ gjstest.c
 gjstest.c.stamp
 gjstest.h
 gjstest.h.stamp
+gjs/gjs.stp
+gjs_gi_probes.h
 install-sh
 libtool
 ltmain.sh
diff --git a/Makefile-gi.am b/Makefile-gi.am
index 1bdf56c..c6f9de6 100644
--- a/Makefile-gi.am
+++ b/Makefile-gi.am
@@ -18,6 +18,7 @@ nobase_gjsgiinclude_HEADERS =	\
 	gi/enumeration.h	\
 	gi/function.h	\
 	gi/keep-alive.h	\
+	gi/gjs_gi_trace.h \
 	gi/ns.h	        \
 	gi/object.h	\
 	gi/foreign.h	\
@@ -41,6 +42,16 @@ libgjs_gi_la_SOURCES =	\
 	gi/union.c	\
         gi/value.c
 
+if ENABLE_DTRACE
+gjs_gi_probes.h: gi/gjs_gi_probes.d
+	$(DTRACE) -C -h -s $< -o $@
+gjs_gi_probes.o: gi/gjs_gi_probes.d
+	$(DTRACE) -G -s $< -o $@
+BUILT_SOURCES += gjs_gi_probes.h gjs_gi_probes.o
+libgjs_gi_la_LIBADD += gjs_gi_probes.o
+endif
+
+
 ########################################################################
 pkgconfig_DATA += gjs-gi-1.0.pc
 
diff --git a/Makefile.am b/Makefile.am
index 3923ad6..f0f0256 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -89,6 +89,15 @@ gjstest_files_with_tests += 	\
 	gjs/stack.c				\
 	util/glib.c
 
+if ENABLE_SYSTEMTAP
+gjs/gjs.stp: gjs/gjs.stp.in Makefile
+	sed -e s,@EXPANDED_LIBDIR@,$(libdir), < $< > $  tmp && mv $  tmp $@
+tapset_in_files = gjs/gjs.stp.in
+tapsetdir   = $(DESTDIR)$(datadir)/systemtap/tapset
+tapset_DATA = $(tapset_in_files:.stp.in=.stp)
+EXTRA_DIST += $(tapset_in_files)
+endif
+
 include Makefile-gjs-dbus.am
 include Makefile-gi.am
 include Makefile-modules.am
diff --git a/configure.ac b/configure.ac
index 906253d..2df0ad6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -248,6 +248,38 @@ LIBS=$LIBS_no_readline
 
 AC_CHECK_FUNCS([backtrace])
 
+dnl
+dnl Tracing
+dnl
+
+AC_MSG_CHECKING([whether to include systemtap tracing support])
+AC_ARG_ENABLE([systemtap],
+             [AS_HELP_STRING([--enable-systemtap],
+                              [Enable inclusion of systemtap trace support])],
+              [ENABLE_SYSTEMTAP="${enableval}"], [ENABLE_SYSTEMTAP='no'])
+AC_MSG_RESULT(${ENABLE_SYSTEMTAP})
+
+AC_MSG_CHECKING([whether to include dtrace tracing support])
+AC_ARG_ENABLE([dtrace],
+             [AS_HELP_STRING([--enable-dtrace],
+                              [Enable inclusion of dtrace trace support])],
+              [ENABLE_DTRACE="${enableval}"], [ENABLE_DTRACE='no'])
+AC_MSG_RESULT(${ENABLE_DTRACE})
+
+AM_CONDITIONAL([ENABLE_SYSTEMTAP], [test x$ENABLE_SYSTEMTAP = xyes])
+AM_CONDITIONAL([ENABLE_DTRACE], [test x$ENABLE_DTRACE = xyes -o x$ENABLE_SYSTEMTAP = xyes])
+
+if test "x${ENABLE_DTRACE}" = xyes -o "x${ENABLE_SYSTEMTAP}" = xyes; then
+  AC_CHECK_PROGS(DTRACE, dtrace)
+  if test -z "$DTRACE"; then
+    AC_MSG_ERROR([dtrace not found])
+  fi
+  AC_CHECK_HEADER([sys/sdt.h], [SDT_H_FOUND='yes'],
+                  [SDT_H_FOUND='no';
+                   AC_MSG_ERROR([tracing support needs sys/sdt.h header])])
+  AC_DEFINE([HAVE_DTRACE], [1], [Define to 1 if using dtrace probes.])
+fi
+
 # Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
 
diff --git a/gi/gjs_gi_probes.d b/gi/gjs_gi_probes.d
new file mode 100644
index 0000000..20e8ad3
--- /dev/null
+++ b/gi/gjs_gi_probes.d
@@ -0,0 +1,4 @@
+provider gjs {
+	probe object__proxy__new(void*, void*, char *, char *);
+	probe object__proxy__finalize(void*, void*, char *, char *);
+};
diff --git a/gi/gjs_gi_trace.h b/gi/gjs_gi_trace.h
new file mode 100644
index 0000000..0440be5
--- /dev/null
+++ b/gi/gjs_gi_trace.h
@@ -0,0 +1,47 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (c) 2010 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Author: Colin Walters <walters verbum org>
+ */
+
+
+#ifndef __GJS_TRACE_H__
+#define __GJS_TRACE_H__
+
+#ifndef GETTEXT_PACKAGE
+#error "config.h must be included prior to gjs_trace.h"
+#endif
+
+#ifdef HAVE_DTRACE
+
+/* include the generated probes header and put markers in code */
+#include "gjs_gi_probes.h"
+#define TRACE(probe) probe
+
+#else
+
+/* Wrap the probe to allow it to be removed when no systemtap available */
+#define TRACE(probe)
+
+#endif
+
+#endif /* __GJS_TRACE_H__ */
diff --git a/gi/object.c b/gi/object.c
index 7114819..703c41e 100644
--- a/gi/object.c
+++ b/gi/object.c
@@ -31,6 +31,7 @@
 #include "function.h"
 #include "value.h"
 #include "keep-alive.h"
+#include "gjs_gi_trace.h"
 
 #include <gjs/gjs.h>
 
@@ -765,6 +766,9 @@ object_instance_constructor(JSContext *context,
         gjs_debug_lifecycle(GJS_DEBUG_GOBJECT,
                             "JSObject created with GObject %p %s",
                             priv->gobj, g_type_name_from_instance((GTypeInstance*) priv->gobj));
+
+        TRACE(GJS_OBJECT_PROXY_NEW(priv, priv->gobj, g_base_info_get_namespace ( (GIBaseInfo*) priv->info),
+                                    g_base_info_get_name ( (GIBaseInfo*) priv->info) ));
     }
 
     return JS_TRUE;
@@ -786,6 +790,9 @@ object_instance_finalize(JSContext *context,
     if (priv == NULL)
         return; /* we are the prototype, not a real instance, so constructor never called */
 
+    TRACE(GJS_OBJECT_PROXY_FINALIZE(priv, priv->gobj, g_base_info_get_namespace ( (GIBaseInfo*) priv->info),
+                                    g_base_info_get_name ( (GIBaseInfo*) priv->info) ));
+
     if (priv->gobj) {
         g_assert(priv->gobj->ref_count > 0);
         set_js_obj(context, priv->gobj, NULL);
diff --git a/gjs/gjs.stp.in b/gjs/gjs.stp.in
new file mode 100644
index 0000000..4170f23
--- /dev/null
+++ b/gjs/gjs.stp.in
@@ -0,0 +1,18 @@
+
+probe gjs.object_proxy_new = process("@EXPANDED_LIBDIR@/libgjs-gi.so.0.0.0").mark("object__proxy__new")
+{
+  proxy_address = $arg1;
+  gobject_address = $arg2;
+  gi_namespace = user_string($arg3);
+  gi_name = user_string($arg4);
+  probestr = sprintf("gjs.object_proxy_new(%p, %s, %s)", proxy_address, gi_namespace, gi_name);
+}
+
+probe gjs.object_proxy_finalize = process("@EXPANDED_LIBDIR@/libgjs-gi.so.0.0.0").mark("object__proxy__finalize")
+{
+  proxy_address = $arg1;
+  gobject_address = $arg2;
+  gi_namespace = user_string($arg3);
+  gi_name = user_string($arg4);
+  probestr = sprintf("gjs.object_proxy_finalize(%p, %s, %s)", proxy_address, gi_namespace, gi_name);
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]