apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject svn commit: r891269 - in /apr/apr/trunk: configure.in include/apr_hooks.h test/testhooks.c
Date Wed, 16 Dec 2009 15:04:37 GMT
Author: trawick
Date: Wed Dec 16 15:04:37 2009
New Revision: 891269

URL: http://svn.apache.org/viewvc?rev=891269&view=rev
Log:
replace --enable-dtrace and corresponding DTrace-specific hook
probes with a general purpose facility that can be used with DTrace
or most anything else

no probe implementation, DTrace or otherwise, is provided with APR


Modified:
    apr/apr/trunk/configure.in
    apr/apr/trunk/include/apr_hooks.h
    apr/apr/trunk/test/testhooks.c

Modified: apr/apr/trunk/configure.in
URL: http://svn.apache.org/viewvc/apr/apr/trunk/configure.in?rev=891269&r1=891268&r2=891269&view=diff
==============================================================================
--- apr/apr/trunk/configure.in (original)
+++ apr/apr/trunk/configure.in Wed Dec 16 15:04:37 2009
@@ -2533,22 +2533,6 @@
 APU_FIND_EXPAT
 APU_FIND_ICONV
 
-AC_CHECK_HEADERS( \
-sys/sdt.h
-)
-
-AC_ARG_ENABLE(dtrace,APR_HELP_STRING(--enable-dtrace, Enable DTrace probes),
-[
-  enable_dtrace=$enableval
-],
-[
-  enable_dtrace=no
-])
-
-if test $enable_dtrace = "yes" -a "$ac_cv_header_sys_sdt_h" = "yes"; then
-    APR_ADDTO(CPPFLAGS, -DAPR_DTRACE_PROVIDER)
-fi
-
 dnl Enable DSO build; must be last:
 APR_MODULAR_DSO
 

Modified: apr/apr/trunk/include/apr_hooks.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_hooks.h?rev=891269&r1=891268&r2=891269&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_hooks.h (original)
+++ apr/apr/trunk/include/apr_hooks.h Wed Dec 16 15:04:37 2009
@@ -21,23 +21,6 @@
 /* For apr_array_header_t */
 #include "apr_tables.h"
 
-#ifdef APR_DTRACE_PROVIDER
-#include <sys/sdt.h>
-#ifndef OLD_DTRACE_PROBE
-#define OLD_DTRACE_PROBE(name) __dtrace_ap___##name()
-#endif
-#ifndef OLD_DTRACE_PROBE1
-#define OLD_DTRACE_PROBE1(name,a) __dtrace_ap___##name(a)
-#endif
-#ifndef OLD_DTRACE_PROBE2
-#define OLD_DTRACE_PROBE2(name,a,b) __dtrace_ap___##name(a,b)
-#endif
-#else
-#define OLD_DTRACE_PROBE(a)
-#define OLD_DTRACE_PROBE1(a,b)
-#define OLD_DTRACE_PROBE2(a,b,c)
-#endif
-
 /**
  * @file apr_hooks.h
  * @brief Apache hook functions
@@ -51,6 +34,74 @@
  * @ingroup APR_Util
  * @{
  */
+
+/**
+ * @defgroup apr_hook_probes Hook probe capability
+ * APR hooks provide a trace probe capability for capturing
+ * the flow of control and return values with hooks.
+ *
+ * In order to use this facility, the application must define
+ * the symbol APR_HOOK_PROBES_ENABLED and the four APR_HOOK_PROBE_
+ * macros described below before including apr_hooks.h in files
+ * that use the APR_IMPLEMENT_EXTERNAL_HOOK_* macros.
+ *
+ * This probe facility is not provided for APR optional hooks.
+ * @{
+ */
+
+#ifdef APR_HOOK_PROBES_ENABLED
+#define APR_HOOK_INT_DCL_UD void *ud = NULL
+#else
+/** internal implementation detail to avoid the ud declaration when
+ * hook probes are not used
+ */
+#define APR_HOOK_INT_DCL_UD
+/**
+ * User-defined hook probe macro that is invoked when the hook
+ * is run, before calling any hook functions.
+ * @param ud A void * user data field that should be filled in by
+ * this macro, and will be provided to the other hook probe macros.
+ * @param ns The namespace prefix of the hook functions
+ * @param name The name of the hook
+ */
+#define APR_HOOK_PROBE_ENTRY(ud,ns,name)
+/**
+ * User-defined hook probe macro that is invoked after the hook
+ * has run.
+ * @param ud A void * user data field that was filled in by the user-
+ * provided APR_HOOK_PROBE_ENTRY().
+ * @param ns The namespace prefix of the hook functions
+ * @param name The name of the hook
+ * @param rv The return value of the hook, or 0 if the hook is void.
+ */
+#define APR_HOOK_PROBE_RETURN(ud,ns,name,rv)
+/**
+ * User-defined hook probe macro that is invoked before calling a
+ * hook function.
+ * @param ud A void * user data field that was filled in by the user-
+ * provided APR_HOOK_PROBE_ENTRY().
+ * @param ns The namespace prefix of the hook functions
+ * @param name The name of the hook
+ * @param src The value of apr_hook_debug_current at the time the function
+ * was hooked (usually the source file implementing the hook function).
+ */
+#define APR_HOOK_PROBE_INVOKE(ud,ns,name,src)
+/**
+ * User-defined hook probe macro that is invoked before calling a
+ * hook function.
+ * @param ud A void * user data field that was filled in by the user-
+ * provided APR_HOOK_PROBE_ENTRY().
+ * @param ns The namespace prefix of the hook functions
+ * @param name The name of the hook
+ * @param src The value of apr_hook_debug_current at the time the function
+ * was hooked (usually the source file implementing the hook function).
+ * @param rv The return value of the hook function, or 0 if the hook is void.
+ */
+#define APR_HOOK_PROBE_COMPLETE(ud,ns,name,src,rv)
+#endif
+
+/** @} */
+
 /** macro to return the prototype of the hook function */    
 #define APR_IMPLEMENT_HOOK_GET_PROTO(ns,link,name) \
 link##_DECLARE(apr_array_header_t *) ns##_hook_get_##name(void)
@@ -123,21 +174,22 @@
     { \
     ns##_LINK_##name##_t *pHook; \
     int n; \
+    APR_HOOK_INT_DCL_UD; \
 \
-    OLD_DTRACE_PROBE(name##__entry); \
+    APR_HOOK_PROBE_ENTRY(ud, ns, name); \
 \
     if(_hooks.link_##name) \
         { \
         pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
         for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
             { \
-            OLD_DTRACE_PROBE1(name##__dispatch__invoke, (char *)pHook[n].szName); \
+            APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName); \
 	    pHook[n].pFunc args_use; \
-            OLD_DTRACE_PROBE2(name##__dispatch__complete, (char *)pHook[n].szName, 0); \
+            APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, 0); \
             } \
         } \
 \
-    OLD_DTRACE_PROBE1(name##__return, 0); \
+    APR_HOOK_PROBE_RETURN(ud, ns, name, 0); \
 \
     }
 
@@ -166,24 +218,25 @@
     ns##_LINK_##name##_t *pHook; \
     int n; \
     ret rv = ok; \
+    APR_HOOK_INT_DCL_UD; \
 \
-    OLD_DTRACE_PROBE(name##__entry); \
+    APR_HOOK_PROBE_ENTRY(ud, ns, name); \
 \
     if(_hooks.link_##name) \
         { \
         pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
         for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
             { \
-            OLD_DTRACE_PROBE1(name##__dispatch__invoke, (char *)pHook[n].szName); \
+            APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName); \
             rv=pHook[n].pFunc args_use; \
-            OLD_DTRACE_PROBE2(name##__dispatch__complete, (char *)pHook[n].szName, rv); \
+            APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, rv); \
             if(rv != ok && rv != decline) \
                 break; \
             rv = ok; \
             } \
         } \
 \
-    OLD_DTRACE_PROBE1(name##__return, rv); \
+    APR_HOOK_PROBE_RETURN(ud, ns, name, rv); \
 \
     return rv; \
     }
@@ -210,24 +263,25 @@
     ns##_LINK_##name##_t *pHook; \
     int n; \
     ret rv = decline; \
+    APR_HOOK_INT_DCL_UD; \
 \
-    OLD_DTRACE_PROBE(name##__entry); \
+    APR_HOOK_PROBE_ENTRY(ud, ns, name); \
 \
     if(_hooks.link_##name) \
         { \
         pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
         for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
             { \
-            OLD_DTRACE_PROBE1(name##__dispatch__invoke, (char *)pHook[n].szName); \
+            APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName); \
             rv=pHook[n].pFunc args_use; \
-            OLD_DTRACE_PROBE2(name##__dispatch__complete, (char *)pHook[n].szName, rv); \
+            APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, rv); \
 \
             if(rv != decline) \
                 break; \
             } \
         } \
 \
-    OLD_DTRACE_PROBE1(name##__return, rv); \
+    APR_HOOK_PROBE_RETURN(ud, ns, name, rv); \
 \
     return rv; \
     }

Modified: apr/apr/trunk/test/testhooks.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testhooks.c?rev=891269&r1=891268&r2=891269&view=diff
==============================================================================
--- apr/apr/trunk/test/testhooks.c (original)
+++ apr/apr/trunk/test/testhooks.c Wed Dec 16 15:04:37 2009
@@ -16,6 +16,21 @@
 
 #include "abts.h"
 #include "testutil.h"
+
+#define APR_HOOK_PROBES_ENABLED
+
+#define APR_HOOK_PROBE_ENTRY(ud,ns,name) \
+  ud = toy_hook_probe_entry(#name)
+
+#define APR_HOOK_PROBE_RETURN(ud,ns,name,rv) \
+  toy_hook_probe_return(ud, #name, rv)
+
+#define APR_HOOK_PROBE_INVOKE(ud,ns,name,src) \
+  toy_hook_probe_invoke(ud, #name, src)
+
+#define APR_HOOK_PROBE_COMPLETE(ud,ns,name,src,rv) \
+  toy_hook_probe_complete(ud, #name, src, rv)
+
 #include "apr_hooks.h"
 
 #define TEST_DECLARE(type) type
@@ -26,9 +41,23 @@
     APR_HOOK_LINK(toyhook)
 )
 
+static void *toy_hook_probe_entry(const char *name);
+static void toy_hook_probe_return(void *ud, const char *name, int rv);
+static void toy_hook_probe_invoke(void *ud, const char *name, const char *src);
+static void toy_hook_probe_complete(void *ud, const char *name,
+                                    const char *src, int rv);
+
 APR_IMPLEMENT_EXTERNAL_HOOK_RUN_ALL(test,TEST,int, toyhook,
                                     (char *x, apr_size_t s), (x, s), 0, -1)
 
+typedef struct {
+    char *buf;
+    apr_size_t buf_size;
+} hook_probe_data_t;
+
+static apr_pool_t *probe_buf_pool;
+static char *probe_buf;
+
 static void safe_concat(char *buf, apr_size_t buf_size, const char *append)
 {
     if (strlen(buf) + strlen(append) + 1 <= buf_size) {
@@ -36,6 +65,40 @@
     }
 }
 
+static void *toy_hook_probe_entry(const char *name)
+{
+    hook_probe_data_t *ud = apr_palloc(probe_buf_pool, sizeof *ud);
+    ud->buf_size = 18;
+    ud->buf = (char *)apr_palloc(probe_buf_pool, ud->buf_size);
+    safe_concat(ud->buf, ud->buf_size, "E");
+    return (void *)ud;
+}
+
+static void toy_hook_probe_return(void *vud, const char *name, int rv)
+{
+    hook_probe_data_t *ud = vud;
+
+    safe_concat(ud->buf, ud->buf_size, "R");
+    probe_buf = ud->buf;
+}
+
+static void toy_hook_probe_invoke(void *vud, const char *name,
+                                  const char *src)
+{
+    hook_probe_data_t *ud = vud;
+
+    safe_concat(ud->buf, ud->buf_size, "I");
+    safe_concat(ud->buf, ud->buf_size, src);
+}
+
+static void toy_hook_probe_complete(void *vud, const char *name,
+                                    const char *src, int rv)
+{
+    hook_probe_data_t *ud = vud;
+
+    safe_concat(ud->buf, ud->buf_size, "C");
+}
+
 static int toyhook_1(char *x, apr_size_t buf_size)
 {
     safe_concat(x, buf_size, "1");
@@ -73,18 +136,24 @@
     apr_hook_global_pool = p;
     apr_hook_deregister_all();
 
-    apr_hook_debug_current = "foo";
+    apr_hook_debug_current = "5";
     test_hook_toyhook(toyhook_5, NULL, NULL, APR_HOOK_MIDDLE + 2);
+    apr_hook_debug_current = "1";
     test_hook_toyhook(toyhook_1, NULL, NULL, APR_HOOK_MIDDLE - 2);
+    apr_hook_debug_current = "3";
     test_hook_toyhook(toyhook_3, NULL, NULL, APR_HOOK_MIDDLE);
+    apr_hook_debug_current = "2";
     test_hook_toyhook(toyhook_2, NULL, NULL, APR_HOOK_MIDDLE - 1);
+    apr_hook_debug_current = "4";
     test_hook_toyhook(toyhook_4, NULL, NULL, APR_HOOK_MIDDLE + 1);
 
     apr_hook_sort_all();
 
+    probe_buf_pool = p;
     test_run_toyhook(buf, sizeof buf);
     
     ABTS_STR_EQUAL(tc, "12345", buf);
+    ABTS_STR_EQUAL(tc, "EI1CI2CI3CI4CI5CR", probe_buf);
 }
 
 static void test_pred_ordering(abts_case *tc, void *data)
@@ -107,6 +176,7 @@
 
     apr_hook_sort_all();
 
+    probe_buf_pool = p;
     test_run_toyhook(buf, sizeof buf);
     
     /* FAILS ABTS_STR_EQUAL(tc, "1223", buf); */



Mime
View raw message