[Libreoffice-commits] core.git: config_host/config_probes.h.in configure.ac sal/rtl

Mark Wielaard mark at klomp.org
Sat Aug 3 00:34:08 PDT 2013


 config_host/config_probes.h.in |    7 +++++
 configure.ac                   |   48 +++++++++++++++++++++++++++++++++++++++++
 sal/rtl/strimp.hxx             |   18 +++++++++++++++
 sal/rtl/string.cxx             |    7 ++---
 sal/rtl/ustrbuf.cxx            |    4 +++
 sal/rtl/ustring.cxx            |    4 +++
 6 files changed, 84 insertions(+), 4 deletions(-)

New commits:
commit eeb3b8dc5c771915f9c011e95ae20babdf70bd02
Author: Mark Wielaard <mark at klomp.org>
Date:   Fri Aug 2 20:49:48 2013 +0200

    Add SDT probes for RTL_LOG_STRING_NEW/DELETE.
    
    Change-Id: I938259f90aee9d277c9ff5b72c9120b93311cbd3
    Signed-off-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/config_host/config_probes.h.in b/config_host/config_probes.h.in
new file mode 100644
index 0000000..b15a1f0
--- /dev/null
+++ b/config_host/config_probes.h.in
@@ -0,0 +1,7 @@
+#ifndef CONFIG_PROBES_H
+#define CONFIG_PROBES_H
+
+/* Whether we have and can use sys/sdt.h for probes.  */
+#define USE_SDT_PROBES 0
+
+#endif
diff --git a/configure.ac b/configure.ac
index 7809430..c623f38 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5322,6 +5322,54 @@ if test "$ENABLE_VALGRIND" = FALSE; then
 fi
 AC_SUBST([VALGRIND_CFLAGS])
 
+
+dnl ===================================================================
+dnl Check if SDT probes (for systemtap, gdb, dtrace) are available
+dnl ===================================================================
+
+# We need at least the sys/sdt.h include header.
+AC_CHECK_HEADER([sys/sdt.h], [SDT_H_FOUND='TRUE'], [SDT_H_FOUND='FALSE'])
+if test "$SDT_H_FOUND" = "TRUE"; then
+  # Found sys/sdt.h header, now make sure the c++ compiler works.
+  # Old g++ versions had problems with probes in constructors/destructors.
+  AC_MSG_CHECKING([working sys/sdt.h and c++ support])
+  AC_LANG_PUSH([C++])
+  AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+    #include <sys/sdt.h>
+    class ProbeClass
+    {
+    private:
+      int& ref;
+      const char *name;
+
+    public:
+      ProbeClass(int& v, const char *n) : ref(v), name(n)
+      {
+        DTRACE_PROBE2(_test_, cons, name, ref);
+      }
+
+      void method(int min)
+      {
+        DTRACE_PROBE3(_test_, meth, name, ref, min);
+        ref -= min;
+      }
+
+      ~ProbeClass()
+      {
+        DTRACE_PROBE2(_test_, dest, name, ref);
+      }
+    };
+  ]],[[
+    int i = 64;
+    DTRACE_PROBE1(_test_, call, i);
+    ProbeClass inst = ProbeClass(i, "call");
+    inst.method(24);
+  ]])], [AC_MSG_RESULT([yes]); AC_DEFINE([USE_SDT_PROBES])],
+        [AC_MSG_RESULT([no, sdt.h or c++ compiler too old])])
+  AC_LANG_POP([C++])
+fi
+AC_CONFIG_HEADERS([config_host/config_probes.h])
+
 dnl ===================================================================
 dnl Compiler plugins
 dnl ===================================================================
diff --git a/sal/rtl/strimp.hxx b/sal/rtl/strimp.hxx
index f54b882..544d579 100644
--- a/sal/rtl/strimp.hxx
+++ b/sal/rtl/strimp.hxx
@@ -20,6 +20,11 @@
 #ifndef INCLUDED_RTL_SOURCE_STRIMP_HXX
 #define INCLUDED_RTL_SOURCE_STRIMP_HXX
 
+#include <config_probes.h>
+#if USE_SDT_PROBES
+#include <sys/sdt.h>
+#endif
+
 #include <osl/interlck.h>
 
 #include "sal/types.h"
@@ -46,8 +51,21 @@ sal_Int16 rtl_ImplGetDigit( sal_Unicode ch, sal_Int16 nRadix );
 sal_Bool rtl_ImplIsWhitespace( sal_Unicode c );
 
 // string lifetime instrumentation / diagnostics
+#if USE_SDT_PROBES
+#  define PROBE_SNAME(n,b) n ## _ ## b
+#  define PROBE_NAME(n,b) PROBE_SNAME(n,b)
+#  define PROBE_NEW PROBE_NAME (new_string,RTL_LOG_STRING_BITS)
+#  define PROBE_DEL PROBE_NAME (delete_string,RTL_LOG_STRING_BITS)
+#  define RTL_LOG_STRING_NEW(s) \
+    DTRACE_PROBE4(libreoffice, PROBE_NEW, s, \
+                  (s)->refCount, (s)->length, (s)->buffer)
+#  define RTL_LOG_STRING_DELETE(s) \
+    DTRACE_PROBE4(libreoffice, PROBE_DEL, s, \
+                  (s)->refCount, (s)->length, (s)->buffer)
+#else
 #  define RTL_LOG_STRING_NEW(s)
 #  define RTL_LOG_STRING_DELETE(s)
+#endif /* USE_SDT_PROBES */
 
 #endif /* INCLUDED_RTL_SOURCE_STRIMP_HXX */
 
diff --git a/sal/rtl/string.cxx b/sal/rtl/string.cxx
index a68c093..313706d 100644
--- a/sal/rtl/string.cxx
+++ b/sal/rtl/string.cxx
@@ -61,10 +61,9 @@ static rtl_String const aImplEmpty_rtl_String =
 #define IMPL_RTL_STRINGDATA         rtl_String
 #define IMPL_RTL_EMPTYSTRING        aImplEmpty_rtl_String
 
-#undef RTL_LOG_STRING_NEW
-#define RTL_LOG_STRING_NEW(s)
-#undef RTL_LOG_STRING_DELETE
-#define RTL_LOG_STRING_DELETE(s)
+#if USE_SDT_PROBES
+#define RTL_LOG_STRING_BITS         8
+#endif
 
 /* ======================================================================= */
 
diff --git a/sal/rtl/ustrbuf.cxx b/sal/rtl/ustrbuf.cxx
index 9010a0e..30f4efe 100644
--- a/sal/rtl/ustrbuf.cxx
+++ b/sal/rtl/ustrbuf.cxx
@@ -24,6 +24,10 @@
 #include <rtl/ustrbuf.hxx>
 #include <strimp.hxx>
 
+#if USE_SDT_PROBES
+#define RTL_LOG_STRING_BITS         16
+#endif
+
 void SAL_CALL rtl_uStringbuffer_newFromStr_WithLength( rtl_uString ** newStr,
                                                        const sal_Unicode * value,
                                                        sal_Int32 count)
diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx
index bdebd89..1c02dfc 100644
--- a/sal/rtl/ustring.cxx
+++ b/sal/rtl/ustring.cxx
@@ -69,6 +69,10 @@ static rtl_uString const aImplEmpty_rtl_uString =
 #define IMPL_RTL_INTERN
 static void internRelease (rtl_uString *pThis);
 
+#if USE_SDT_PROBES
+#define RTL_LOG_STRING_BITS         16
+#endif
+
 /* ======================================================================= */
 
 /* Include String/UString template code */


More information about the Libreoffice-commits mailing list