Hi all,

For my confoo.ca presentation of last week, I've done a prototype
instrumentation of apache with UST. So far, it only have few
tracepoints, but I want to share it anyway, in case somebody need to the
work and want to improve it. (I won't have time to work on it soon.)

It's done againts the httpd-trunk svn version.
Index: os/unix/Makefile.in
===================================================================
--- os/unix/Makefile.in	(révision 1074269)
+++ os/unix/Makefile.in	(copie de travail)
@@ -1,5 +1,5 @@
 
 LTLIBRARY_NAME    = libos.la
-LTLIBRARY_SOURCES = unixd.c
+LTLIBRARY_SOURCES = unixd.c ust_probes.c
 
 include $(top_srcdir)/build/ltlib.mk
Index: os/unix/ust_probes.c
===================================================================
--- os/unix/ust_probes.c	(révision 0)
+++ os/unix/ust_probes.c	(révision 0)
@@ -0,0 +1,97 @@
+/* TODO Add copyright */
+#include <ust/ust.h>
+
+#include "ap_config.h"
+
+DEFINE_TRACE(ust_process_request_entry);
+DEFINE_TRACE(ust_process_request_return);
+DEFINE_TRACE(ust_read_request_entry);
+DEFINE_TRACE(ust_read_request_success);
+DEFINE_TRACE(ust_read_request_failure);
+DEFINE_TRACE(ust_rewrite_log);
+DEFINE_TRACE(ust_internal_redirect);
+DEFINE_TRACE(ust_cgi_handler_entry);
+DEFINE_TRACE(ust_cgi_handler_exit);
+
+notrace void probe_ust_process_request_entry(void *data, void *r, char *uri)
+{
+  trace_mark_tp(ust, ust_process_request_entry,
+		ust_process_request_entry, probe_ust_process_request_entry,
+		"r %p uri %s",
+		r, uri);
+}
+notrace void probe_ust_process_request_return(void *data, void *r, char *uri, int status)
+{
+  trace_mark_tp(ust, ust_process_request_return,
+		ust_process_request_return, probe_ust_process_request_return,
+		"r %p uri %s status %d",
+		r, uri, status);
+}
+
+notrace void probe_ust_read_request_entry(void *data, void *r, void *conn)
+{
+  trace_mark_tp(ust, ust_read_request_entry,
+		ust_read_request_entry, probe_ust_read_request_entry,
+		"r %p conn %p",
+		r, conn);
+}
+
+notrace void probe_ust_read_request_success(void *data, void *r, char *method, char *uri, char *server, int status)
+{
+  trace_mark_tp(ust, ust_read_request_success,
+		ust_read_request_success, probe_ust_read_request_success,
+		"request %p method %s uri %s server %s status %d",
+		r, method, uri, server, status);
+}
+
+notrace void probe_ust_read_request_failure(void *data, void *r)
+{
+  trace_mark_tp(ust, ust_read_request_failure,
+		ust_read_request_failure, probe_ust_read_request_failure,
+		"request %p ",
+		r);
+}
+
+notrace void probe_ust_rewrite_log(void *data, void *r, int level, int main, char *server_name, char *logline)
+{
+  trace_mark_tp(ust, ust_rewrite_log,
+		ust_rewrite_log, probe_ust_rewrite_log,
+		"request %p level %d main %d server_name %s logline %s",
+		r, level, main, server_name, logline);
+}
+
+notrace void probe_ust_internal_redirect(void *data, char *uri, char *new_uri)
+{
+  trace_mark_tp(ust, ust_internal_redirect,
+		ust_internal_redirect, probe_ust_internal_redirect,
+		"uri %s new_uri %s",
+		uri, new_uri);
+}
+
+notrace void probe_ust_cgi_handler_entry(void *data, void *r)
+{
+  trace_mark_tp(ust, ust_cgi_handler_entry,
+		ust_cgi_handler_entry, probe_ust_cgi_handler_entry,
+		"request %p",
+		r);
+}
+
+notrace void probe_ust_cgi_handler_exit(void *data, void *r, int status)
+{
+  trace_mark_tp(ust, ust_cgi_handler_exit,
+		ust_cgi_handler_exit, probe_ust_cgi_handler_exit,
+		"request %p status %d",
+		r, status);
+}
+
+static void __attribute__((constructor)) init()
+{
+  register_trace_ust_process_request_entry(probe_ust_process_request_entry, NULL);
+  register_trace_ust_process_request_return(probe_ust_process_request_return, NULL);
+
+  register_trace_ust_read_request_entry(probe_ust_read_request_entry, NULL);
+  register_trace_ust_read_request_success(probe_ust_read_request_success, NULL);
+  register_trace_ust_read_request_failure(probe_ust_read_request_failure, NULL);
+  register_trace_ust_internal_redirect(probe_ust_internal_redirect, NULL);
+
+}
Index: server/Makefile.in
===================================================================
--- server/Makefile.in	(révision 1074269)
+++ server/Makefile.in	(copie de travail)
@@ -62,7 +62,7 @@
 	for dir in $(EXPORT_DIRS_APR); do \
 	    (ls $$dir/ap[ru].h $$dir/ap[ru]_*.h >> $$tmp 2>/dev/null); \
 	done; \
-	sort -u $$tmp > $@; \
+	sort -u $$tmp | grep -v apache_noprobes.h > $@; \
 	rm -f $$tmp
 
 exports.c: export_files
Index: modules/generators/mod_cgi.c
===================================================================
--- modules/generators/mod_cgi.c	(révision 1074269)
+++ modules/generators/mod_cgi.c	(copie de travail)
@@ -761,6 +761,8 @@
         return DECLINED;
     }
 
+
+
     c = r->connection;
 
     is_included = !strcmp(r->protocol, "INCLUDED");
@@ -800,6 +802,8 @@
     }
 
 */
+    trace_ust_cgi_handler_entry(r);
+
     ap_add_common_vars(r);
     ap_add_cgi_vars(r);
 
@@ -820,6 +824,7 @@
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
                       "don't know how to spawn child process: %s",
                       r->filename);
+	trace_ust_cgi_handler_exit(r, HTTP_INTERNAL_SERVER_ERROR);
         return HTTP_INTERNAL_SERVER_ERROR;
     }
 
@@ -828,6 +833,7 @@
                             command, argv, r, p, &e_info)) != APR_SUCCESS) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
                       "couldn't spawn child process: %s", r->filename);
+	trace_ust_cgi_handler_exit(r, HTTP_INTERNAL_SERVER_ERROR);
         return HTTP_INTERNAL_SERVER_ERROR;
     }
 
@@ -851,10 +857,14 @@
             if (APR_STATUS_IS_TIMEUP(rv)) {
                 ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
                               "Timeout during reading request entity data");
+		trace_ust_cgi_handler_exit(r,HTTP_REQUEST_TIME_OUT );
+
                 return HTTP_REQUEST_TIME_OUT;
             }
             ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
                           "Error reading request entity data");
+	    trace_ust_cgi_handler_exit(r, HTTP_INTERNAL_SERVER_ERROR );
+
             return HTTP_INTERNAL_SERVER_ERROR;
         }
 
@@ -926,8 +936,11 @@
     apr_file_pipe_timeout_set(script_err, 0);
 
     b = cgi_bucket_create(r, script_in, script_err, c->bucket_alloc);
-    if (b == NULL)
+    if (b == NULL) {
+      trace_ust_cgi_handler_exit(r, HTTP_INTERNAL_SERVER_ERROR );
+
 	return HTTP_INTERNAL_SERVER_ERROR;
+    }
 #else
     b = apr_bucket_pipe_create(script_in, c->bucket_alloc);
 #endif
@@ -966,8 +979,11 @@
              */
             if (ret == HTTP_NOT_MODIFIED) {
                 r->status = ret;
+		trace_ust_cgi_handler_exit(r, OK );
+
                 return OK;
             }
+	    trace_ust_cgi_handler_exit(r, ret );
 
             return ret;
         }
@@ -998,12 +1014,16 @@
             apr_table_unset(r->headers_in, "Content-Length");
 
             ap_internal_redirect_handler(location, r);
+	    trace_ust_cgi_handler_exit(r, OK );
+
             return OK;
         }
         else if (location && r->status == 200) {
             /* XXX: Note that if a script wants to produce its own Redirect
              * body, it now has to explicitly *say* "Status: 302"
              */
+	  trace_ust_cgi_handler_exit(r,  HTTP_MOVED_TEMPORARILY );
+
             return HTTP_MOVED_TEMPORARILY;
         }
 
@@ -1036,7 +1056,8 @@
     }
 
     apr_file_close(script_err);
-
+    trace_ust_cgi_handler_exit(r, OK );
+	    
     return OK;                      /* NOT r->status, even if it has changed. */
 }
 
Index: include/ap_config.h
===================================================================
--- include/ap_config.h	(révision 1074269)
+++ include/ap_config.h	(copie de travail)
@@ -244,11 +244,21 @@
 #undef _DTRACE_VERSION
 #endif
 
+#if AP_ENABLE_UST
+#include <ust/ust.h>
+#else
+/* bla */
+#endif
+
 #ifdef _DTRACE_VERSION
 #include "apache_probes.h"
 #else
-#include "apache_noprobes.h"
+#ifdef DEFINE_MARKER
+#include "apache_probes_ust.h"
+#else
+
 #endif
+#endif
 
 /* If APR has OTHER_CHILD logic, use reliable piped logs. */
 #if APR_HAS_OTHER_CHILD
Index: include/ust_probes.h
===================================================================
--- include/ust_probes.h	(révision 0)
+++ include/ust_probes.h	(révision 0)
@@ -0,0 +1,39 @@
+#ifndef _UST_PROBES_H_
+#define _UST_PROBES_H_
+
+#include <ust/tracepoint.h>
+
+DECLARE_TRACE(ust_process_request_entry,
+	      TP_PROTO(void *r, char *uri),
+	      TP_ARGS(r, uri));
+DECLARE_TRACE(ust_process_request_return,
+	      TP_PROTO(void *r, char *uri, int status),
+	      TP_ARGS(r, uri, status));
+
+
+DECLARE_TRACE(ust_read_request_entry,
+	       TP_PROTO(void* r, void *conn),
+	      TP_ARGS(r, conn));
+DECLARE_TRACE(ust_read_request_success,
+	      TP_PROTO(void* r, char *method, char *uri, char *server, int status),
+	      TP_ARGS(r, method, uri, server, status));
+DECLARE_TRACE(ust_read_request_failure,
+	       TP_PROTO(void* r),
+	       TP_ARGS(r));
+
+DECLARE_TRACE(ust_rewrite_log, 
+	      TP_PROTO( void *r, int level, int main, char *server_name, char *logline),
+	      TP_ARGS(r, level, main, server_name, logline));
+
+DECLARE_TRACE(ust_internal_redirect,
+	      TP_PROTO( char* uri, char* new_uri),
+	      TP_ARGS(uri, new_uri));
+
+DECLARE_TRACE(ust_cgi_handler_entry,
+	      TP_PROTO( void *r),
+	      TP_ARGS(r));
+
+DECLARE_TRACE(ust_cgi_handler_exit,
+	      TP_PROTO( void *r, int status),
+	      TP_ARGS(r, status));
+#endif
Index: include/http_request.h
===================================================================
--- include/http_request.h	(révision 1074269)
+++ include/http_request.h	(copie de travail)
@@ -33,6 +33,7 @@
  * how the server would handle some other file or URI, or perhaps even
  * direct the server to serve that other file instead of the one the
  * client requested directly.
+
  *
  * There are two ways to do that.  The first is the sub_request mechanism,
  * which handles looking up files and URIs as adjuncts to some other
Index: configure.in
===================================================================
--- configure.in	(révision 1074269)
+++ configure.in	(copie de travail)
@@ -504,6 +504,22 @@
 
 APACHE_SUBST(DTRACE)
 
+AC_ARG_ENABLE(ust,APACHE_HELP_STRING(--enable-ust, Enable UST probes),
+[
+   enable_ust=$enableval
+dnl  APR_ADDTO(CPPFLAGS, -DAPR_DTRACE_PROVIDER)
+   APR_ADDTO(LDFLAGS, -lust )  
+
+],
+[
+  enable_ust=no
+])
+
+if test $enable_ust = "yes"; then
+        AC_DEFINE(AP_ENABLE_UST, 1,
+                  [Enable UST probes])
+fi
+
 APR_CHECK_APR_DEFINE(APR_HAVE_IPV6)
 
 AC_ARG_ENABLE(v4-mapped,APACHE_HELP_STRING(--enable-v4-mapped,Allow IPv6 sockets to handle IPv4 connections),
Index: support/apachectl.in
===================================================================
--- support/apachectl.in	(révision 1074269)
+++ support/apachectl.in	(copie de travail)
@@ -78,7 +78,7 @@
 
 case $ACMD in
 start|stop|restart|graceful|graceful-stop)
-    $HTTPD -k $ARGV
+    usttrace -f $HTTPD -k $ARGV
     ERROR=$?
     ;;
 startssl|sslstart|start-SSL)
_______________________________________________
ltt-dev mailing list
[email protected]
http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev

Reply via email to