diff --git a/patches/nginx-1.2.1-dtrace.patch b/patches/nginx-1.2.1-dtrace.patch index 7a2b76e..a9936b2 100644 --- a/patches/nginx-1.2.1-dtrace.patch +++ b/patches/nginx-1.2.1-dtrace.patch @@ -45,7 +45,7 @@ index 2f68e14..4f2c4a7 100644 +The original Nginx documentation is available at http://nginx.org diff --git a/auto/install b/auto/install -index c2c0ade..bdc0eee 100644 +index c2c0ade..01cea03 100644 --- a/auto/install +++ b/auto/install @@ -16,6 +16,20 @@ END @@ -73,12 +73,12 @@ index c2c0ade..bdc0eee 100644 esac -+case ".$NGX_TAPSET_PATH" in ++case ".$NGX_TAPSET_PREFIX" in + ./* | .) + ;; + + *) -+ NGX_TAPSET_PATH=$NGX_PREFIX/$NGX_TAPSET_PATH ++ NGX_TAPSET_PREFIX=$NGX_PREFIX/$NGX_TAPSET_PREFIX + ;; +esac + @@ -86,17 +86,32 @@ index c2c0ade..bdc0eee 100644 case ".$NGX_ERROR_LOG_PATH" in ./* | .) ;; -@@ -151,6 +175,21 @@ install: $NGX_OBJS${ngx_dirsep}nginx${ngx_binext} \ +@@ -151,6 +175,36 @@ install: $NGX_OBJS${ngx_dirsep}nginx${ngx_binext} \ || cp -R $NGX_HTML '\$(DESTDIR)$NGX_PREFIX' END +if [ $NGX_DTRACE = YES ]; then + -+ cat << END >> $NGX_MAKEFILE ++ ngx_tapset_srcs="$NGX_TAPSET_SRCS" + -+ test -d '\$(DESTDIR)`dirname "$NGX_TAPSET_PATH"`' || \ -+ mkdir -p '\$(DESTDIR)`dirname "$NGX_TAPSET_PATH"`' -+ cp $NGX_OBJS/nginx.stp '\$(DESTDIR)$NGX_TAPSET_PATH' ++ cat << END >> $NGX_MAKEFILE ++ test -d '\$(DESTDIR)$NGX_TAPSET_PREFIX' || \ ++ mkdir -p '\$(DESTDIR)$NGX_TAPSET_PREFIX' ++END ++ ++ for ngx_tapset_src in $ngx_tapset_srcs ++ do ++ ngx_tapset_file=`basename $ngx_tapset_src` ++ ++ cat << END >> $NGX_MAKEFILE ++ ++ sed -e "s|NGX_SBIN_PATH|$NGX_SBIN_PATH|g" $ngx_long_cont \ ++ $ngx_tapset_src > '\$(DESTDIR)$NGX_TAPSET_PREFIX/$ngx_tapset_file' ++END ++ ++ done ++ ++ cat << END >> $NGX_MAKEFILE + + test -d '\$(DESTDIR)`dirname "$NGX_STAP_NGX_PATH"`' || \ + mkdir -p '\$(DESTDIR)`dirname "$NGX_STAP_NGX_PATH"`' @@ -108,18 +123,17 @@ index c2c0ade..bdc0eee 100644 if test -n "$NGX_ERROR_LOG_PATH"; then cat << END >> $NGX_MAKEFILE -@@ -162,6 +201,18 @@ END +@@ -162,6 +216,17 @@ END fi +if [ $NGX_DTRACE = YES ]; then + cat << END >> $NGX_MAKEFILE + -+$NGX_OBJS${ngx_dirsep}nginx.stp: src/dtrace/nginx.stp -+ sed -e "s|NGX_SBIN_PATH|$NGX_SBIN_PATH|g" src/dtrace/nginx.stp > $NGX_OBJS${ngx_dirsep}nginx.stp -+ +$NGX_OBJS${ngx_dirsep}stap-nginx: src/dtrace/stap-nginx -+ sed -e "s|NGX_TAPSET_DIR|`dirname $NGX_TAPSET_PATH`|g" $ngx_long_cont -e "s|NGX_SBIN_DIR|`dirname $NGX_SBIN_PATH`|g" $ngx_long_cont src/dtrace/stap-nginx > $NGX_OBJS${ngx_dirsep}stap-nginx ++ sed -e "s|NGX_TAPSET_PREFIX|$NGX_TAPSET_PREFIX|g" $ngx_long_cont \ ++ -e "s|NGX_SBIN_DIR|`dirname $NGX_SBIN_PATH`|g" $ngx_long_cont \ ++ src/dtrace/stap-nginx > $NGX_OBJS${ngx_dirsep}stap-nginx +END +fi + @@ -128,7 +142,7 @@ index c2c0ade..bdc0eee 100644 cat << END >> Makefile diff --git a/auto/make b/auto/make -index e7f5490..72288e8 100644 +index e7f5490..ed2c098 100644 --- a/auto/make +++ b/auto/make @@ -26,6 +26,9 @@ LINK = $LINK @@ -141,19 +155,29 @@ index e7f5490..72288e8 100644 if test -n "$NGX_PERL_CFLAGS"; then echo NGX_PERL_CFLAGS = $NGX_PERL_CFLAGS >> $NGX_MAKEFILE -@@ -177,6 +180,26 @@ ngx_objs=`echo $ngx_all_objs $ngx_modules_obj \ +@@ -177,6 +180,36 @@ ngx_objs=`echo $ngx_all_objs $ngx_modules_obj \ | sed -e "s/ *\([^ ][^ ]*\)/$ngx_long_regex_cont\1/g" \ -e "s/\//$ngx_regex_dirsep/g"` +if [ $NGX_DTRACE = YES ]; then -+ ngx_dtrace_obj=$NGX_OBJS${ngx_dirsep}ngx_dtrace_provider.$ngx_objext -+ ngx_dtrace_h=$NGX_OBJS${ngx_dirsep}ngx_dtrace_provider.h -+ ngx_dtrace_d=$NGX_DTRACE_D + -+cat << END >> $NGX_MAKEFILE ++ ngx_dtrace_obj=$NGX_OBJS${ngx_dirsep}ngx_dtrace_provider.$ngx_objext ++ ++ ngx_dtrace_h=$NGX_OBJS${ngx_dirsep}ngx_dtrace_provider.h ++ ++ ngx_dtrace_d=$NGX_OBJS${ngx_dirsep}dtrace_providers.d ++ ++ ngx_dtrace_providers=`echo $NGX_DTRACE_PROVIDERS \ ++ | sed -e "s/ *\([^ ][^ ]*\)/$ngx_long_regex_cont\1/g" \ ++ -e "s/\//$ngx_regex_dirsep/g"` ++ ++ cat << END >> $NGX_MAKEFILE + +all: $NGX_OBJS${ngx_dirsep}nginx${ngx_binext} + ++$ngx_dtrace_d: $ngx_dtrace_providers ++ cat $ngx_dtrace_providers > $ngx_dtrace_d ++ +$ngx_dtrace_h: $ngx_dtrace_d + \$(DTRACE) -xnolibs -h -o $ngx_dtrace_h -s $ngx_dtrace_d + @@ -161,7 +185,7 @@ index e7f5490..72288e8 100644 + \$(DTRACE) -xnolibs -G -o $ngx_dtrace_obj -s $ngx_dtrace_d $ngx_objs +END + -+ ngx_deps="$ngx_deps$ngx_long_cont$ngx_dtrace_obj$ngx_long_cont$NGX_OBJS${ngx_dirsep}nginx.stp$ngx_long_cont$NGX_OBJS${ngx_dirsep}stap-nginx" ++ ngx_deps="$ngx_deps$ngx_long_cont$ngx_dtrace_obj$ngx_long_cont$NGX_OBJS${ngx_dirsep}stap-nginx" + ngx_objs="$ngx_objs$ngx_long_cont$ngx_dtrace_obj" +fi + @@ -169,14 +193,14 @@ index e7f5490..72288e8 100644 ngx_libs=`echo $NGX_LD_OPT $CORE_LIBS \ | sed -e "s/\//$ngx_regex_dirsep/g" -e "s/^/$ngx_long_regex_cont/"` diff --git a/auto/options b/auto/options -index 393be40..e063dba 100644 +index 393be40..05609c6 100644 --- a/auto/options +++ b/auto/options @@ -12,6 +12,8 @@ NGX_CONF_PATH= NGX_ERROR_LOG_PATH= NGX_PID_PATH= NGX_LOCK_PATH= -+NGX_TAPSET_PATH= ++NGX_TAPSET_PREFIX= +NGX_STAP_NGX_PATH= NGX_USER= NGX_GROUP= @@ -194,7 +218,7 @@ index 393be40..e063dba 100644 --error-log-path=*) NGX_ERROR_LOG_PATH="$value";; --pid-path=*) NGX_PID_PATH="$value" ;; --lock-path=*) NGX_LOCK_PATH="$value" ;; -+ --tapset-path=*) NGX_TAPSET_PATH="$value" ;; ++ --tapset-prefix=*) NGX_TAPSET_PREFIX="$value" ;; + --stap-nginx-path=*) NGX_STAP_NGX_PATH="$value" ;; --user=*) NGX_USER="$value" ;; --group=*) NGX_GROUP="$value" ;; @@ -213,7 +237,7 @@ index 393be40..e063dba 100644 --error-log-path=PATH set error log pathname --pid-path=PATH set nginx.pid pathname --lock-path=PATH set nginx.lock pathname -+ --tapset-path=PATH set nginx.stp systemtap tapset pathname ++ --tapset-prefix=PATH set systemtap tapset directory prefix + --stap-nginx-path=PATH set stap-nginx pathname --user=USER set non-privileged user for @@ -231,12 +255,12 @@ index 393be40..e063dba 100644 NGX_CONF_PREFIX=`dirname $NGX_CONF_PATH` NGX_PID_PATH=${NGX_PID_PATH:-logs/nginx.pid} NGX_LOCK_PATH=${NGX_LOCK_PATH:-logs/nginx.lock} -+NGX_TAPSET_PATH=${NGX_TAPSET_PATH:-tapset/nginx.stp} ++NGX_TAPSET_PREFIX=${NGX_TAPSET_PREFIX:-tapset} if [ ".$NGX_ERROR_LOG_PATH" = ".stderr" ]; then NGX_ERROR_LOG_PATH= diff --git a/auto/sources b/auto/sources -index 374ad66..70eed77 100644 +index 374ad66..72bb1b0 100644 --- a/auto/sources +++ b/auto/sources @@ -39,6 +39,11 @@ CORE_DEPS="src/core/nginx.h \ @@ -261,13 +285,34 @@ index 374ad66..70eed77 100644 HTTP_SRCS="src/http/ngx_http.c \ src/http/ngx_http_core_module.c \ -@@ -524,3 +530,6 @@ NGX_GOOGLE_PERFTOOLS_MODULE=ngx_google_perftools_module +@@ -524,3 +530,8 @@ NGX_GOOGLE_PERFTOOLS_MODULE=ngx_google_perftools_module NGX_GOOGLE_PERFTOOLS_SRCS=src/misc/ngx_google_perftools_module.c NGX_CPP_TEST_SRCS=src/misc/ngx_cpp_test_module.cpp + -+NGX_DTRACE_D=src/dtrace/nginx_provider.d ++NGX_DTRACE_PROVIDERS=src/dtrace/nginx_provider.d + ++NGX_TAPSET_SRCS=src/dtrace/nginx.stp ++ +diff --git a/auto/summary b/auto/summary +index dcebec9..06c4aa9 100644 +--- a/auto/summary ++++ b/auto/summary +@@ -92,6 +92,14 @@ else + echo " nginx logs errors to stderr" + fi + ++if [ $NGX_DTRACE = YES ]; then ++ cat << END ++ nginx dtrace static probes enabled ++ nginx systemtap tapset prefix: "$NGX_TAPSET_PREFIX" ++ nginx systemtap wrapper script: "$NGX_STAP_NGX_PATH" ++END ++fi ++ + cat << END + nginx http access log file: "$NGX_HTTP_LOG_PATH" + nginx http client request body temporary files: "$NGX_HTTP_CLIENT_TEMP_PATH" diff --git a/configure b/configure index 45ea154..332c011 100755 --- a/configure @@ -284,10 +329,13 @@ index 45ea154..332c011 100755 echo "checking for OS" diff --git a/src/dtrace/nginx.stp b/src/dtrace/nginx.stp new file mode 100644 -index 0000000..a00dc40 +index 0000000..648a962 --- /dev/null +++ b/src/dtrace/nginx.stp -@@ -0,0 +1,22 @@ +@@ -0,0 +1,46 @@ ++/* tapset for nginx */ ++ ++/* retrieve the request uri string from the ngx_http_request_t pointer */ +function ngx_http_req_uri(r) +{ + len = @cast(r, "ngx_http_request_s", "NGX_SBIN_PATH")->uri->len @@ -299,6 +347,8 @@ index 0000000..a00dc40 + return user_string_n(@cast(r, "ngx_http_request_s", "NGX_SBIN_PATH")->uri->data, len) +} + ++ ++/* retrieve the request query string from the ngx_http_request_t pointer */ +function ngx_http_req_args(r) +{ + len = @cast(r, "ngx_http_request_s", "NGX_SBIN_PATH")->args->len @@ -310,15 +360,36 @@ index 0000000..a00dc40 + return user_string_n(@cast(r, "ngx_http_request_s", "NGX_SBIN_PATH")->args->data, len) +} + ++ ++/* retrieve the first command name (or directive name) from ++ * the ngx_module_t pointer */ ++function ngx_http_module_cmd(m) ++{ ++ cmds = @cast(m, "ngx_module_t", "NGX_SBIN_PATH")->commands ++ if (cmds == 0) { ++ return "" ++ } ++ ++ len = @cast(cmds, "ngx_command_t", "NGX_SBIN_PATH")->name->len ++ ++ if (len == 0) { ++ return "" ++ } ++ ++ return user_string_n(@cast(cmds, "ngx_command_t", "NGX_SBIN_PATH")->name->data, len) ++} ++ diff --git a/src/dtrace/nginx_provider.d b/src/dtrace/nginx_provider.d new file mode 100644 -index 0000000..1f47aef +index 0000000..ff7a4e8 --- /dev/null +++ b/src/dtrace/nginx_provider.d -@@ -0,0 +1,24 @@ +@@ -0,0 +1,27 @@ +typedef struct { int dummy; } ngx_http_request_t; +typedef struct { int dummy; } ngx_str_t; +typedef int64_t ngx_int_t; ++typedef struct { int dummy; } ngx_module_t; ++typedef struct { int dummy; } ngx_http_module_t; + + +provider nginx { @@ -331,6 +402,7 @@ index 0000000..1f47aef + probe http__subrequest__done(ngx_http_request_t *r); + probe http__subrequest__post__start(ngx_http_request_t *r, ngx_int_t rc); + probe http__subrequest__post__done(ngx_http_request_t *r, ngx_int_t rc); ++ probe http__module__post__config(ngx_module_t *m); +}; + + @@ -341,16 +413,39 @@ index 0000000..1f47aef +#pragma D attributes Evolving/Evolving/Common provider nginx args + diff --git a/src/dtrace/stap-nginx b/src/dtrace/stap-nginx -new file mode 100644 -index 0000000..37f9367 +new file mode 100755 +index 0000000..e5d4070 --- /dev/null +++ b/src/dtrace/stap-nginx -@@ -0,0 +1,5 @@ +@@ -0,0 +1,6 @@ +#!/bin/sh + -+export PATH=NGX_SBIN_DIR:$PATH -+exec stap -I "NGX_TAPSET_DIR" "$@" ++PATH="NGX_SBIN_DIR:$PATH" ++export PATH ++exec stap -I "NGX_TAPSET_PREFIX" "$@" + +diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c +index 3e077fb..b7edb7b 100644 +--- a/src/http/ngx_http.c ++++ b/src/http/ngx_http.c +@@ -8,6 +8,7 @@ + #include + #include + #include ++#include + + + static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +@@ -307,6 +308,9 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) + module = ngx_modules[m]->ctx; + + if (module->postconfiguration) { ++ ++ ngx_http_probe_module_post_config(ngx_modules[m]); ++ + if (module->postconfiguration(cf) != NGX_OK) { + return NGX_CONF_ERROR; + } diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 31832ce..9c5ebf3 100644 --- a/src/http/ngx_http_core_module.c @@ -383,13 +478,19 @@ index 31832ce..9c5ebf3 100644 diff --git a/src/http/ngx_http_probe.h b/src/http/ngx_http_probe.h new file mode 100644 -index 0000000..1538560 +index 0000000..0727968 --- /dev/null +++ b/src/http/ngx_http_probe.h -@@ -0,0 +1,49 @@ +@@ -0,0 +1,59 @@ +#ifndef _NGX_HTTP_PROBE_H_INCLUDED_ +#define _NGX_HTTP_PROBE_H_INCLUDED_ + ++ ++#include ++#include ++#include ++ ++ +#if (NGX_DTRACE) + +#include @@ -418,9 +519,12 @@ index 0000000..1538560 +#define ngx_http_probe_subrequest_post_start(r, rc) \ + NGINX_HTTP_SUBREQUEST_POST_START(r, rc) + -+#define ngx_http_probe_subrequest_post_done(r, rc) \ ++#define ngx_http_probe_subrequest_post_done(r, rc) \ + NGINX_HTTP_SUBREQUEST_POST_DONE(r, rc) + ++#define ngx_http_probe_module_post_config(m) \ ++ NGINX_HTTP_MODULE_POST_CONFIG(m) ++ +#else /* !(NGX_DTRACE) */ + +#define ngx_http_probe_subrequest_cycle(pr, uri, args) @@ -431,6 +535,7 @@ index 0000000..1538560 +#define ngx_http_probe_subrequest_done(r) +#define ngx_http_probe_subrequest_post_start(r, rc) +#define ngx_http_probe_subrequest_post_done(r, rc) ++#define ngx_http_probe_module_post_config(m) + +#endif /* NGX_DTRACE */ +