Skip to content
Browse files

initial checkin. tested on Solaris 11 Express 2010_11 (i386).

  • Loading branch information...
0 parents commit ac92a6392d12239041a1234a3164d9a14b57bcd4 @agentzh committed Jul 17, 2012
Showing with 204 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +25 −0 Makefile
  3. +13 −0 README
  4. +18 −0 run.d
  5. +34 −0 test.c
  6. +80 −0 test.d
  7. +10 −0 test_provider.d
  8. +19 −0 test_provider_impl.h
5 .gitignore
@@ -0,0 +1,5 @@
+*~
+*.swp
+test_provider.h
+*.o
+test
25 Makefile
@@ -0,0 +1,25 @@
+.PHONY: all clean
+
+OBJS=test.o
+CC=gcc
+
+all: test
+
+test: test.o test_provider.o
+ $(CC) -o $@ $^
+
+test.o: test.c test_provider.h
+ $(CC) -c $<
+
+test_provider.h: test_provider.d
+ dtrace -xnolibs -h -o $@ -s test_provider.d
+
+test_provider.o: test_provider.d $(OBJS)
+ dtrace -xnolibs -G -o $@ -s $< $(OBJS)
+
+install: all
+ cp test.d /usr/lib/dtrace/
+
+clean:
+ rm -f *.o test_provider.h
+
13 README
@@ -0,0 +1,13 @@
+Build:
+
+ gmake
+ sudo gmake install
+
+Run:
+ Terminal 1:
+ ./test
+
+ Terminal 2:
+ sudo dtrace -n \
+ '' (Terminal 2)
+
18 run.d
@@ -0,0 +1,18 @@
+#!/usr/sbin/dtrace -s
+
+#pragma D option quiet
+
+BEGIN {
+ printf("Tracing. Hit CTRL-C to stop.\n");
+}
+
+ngx_http*:::request-start
+{
+ printf("start: %s -> %s (id %d, %s?%s)\n", args[0]->ci_remote, args[0]->ci_local, args[1]->ri_id, args[1]->ri_uri, args[1]->ri_args)
+}
+
+ngx_http*:::request-done
+{
+ printf("done: %s -> %s (id %d, %s?%s)\n", args[0]->ci_remote, args[0]->ci_local, args[1]->ri_id, args[1]->ri_uri, args[1]->ri_args)
+}
+
34 test.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include "test_provider_impl.h"
+#include "test_provider.h"
+#include <unistd.h>
+
+int main(void)
+{
+ ngx_http_dtrace_request_t dt_r;
+
+ dt_r.id = 256;
+ dt_r.uri = "/foo/bar";
+ dt_r.args = "foo=3&bar=4";
+ dt_r.laddr = "local";
+ dt_r.raddr = "remote";
+
+ for (;;) {
+ if (NGX_HTTP_REQUEST_START_ENABLED()) {
+ NGX_HTTP_REQUEST_START(&dt_r);
+ }
+
+ sleep(1);
+
+ if (NGX_HTTP_REQUEST_DONE_ENABLED()) {
+ NGX_HTTP_REQUEST_DONE(&dt_r);
+ }
+
+ printf("next\n");
+ }
+
+ printf("done\n");
+
+ return 0;
+}
+
80 test.d
@@ -0,0 +1,80 @@
+/* for abstracting out ngx_http_request_t */
+typedef struct ngx_http_dtrace_request_32_s {
+ uint64_t id;
+ uint32_t uri;
+ uint32_t args;
+ uint32_t laddr;
+ uint32_t raddr;
+} ngx_http_dtrace_request_32_t;
+
+
+typedef struct ngx_http_dtrace_request_s {
+ uint64_t id;
+ uint64_t uri;
+ uint64_t args;
+ uint64_t laddr;
+ uint64_t raddr;
+} ngx_http_dtrace_request_t;
+
+
+typedef struct ngx_conn_info_s {
+ string ci_local; /* local host address */
+ string ci_remote; /* remote host address */
+ string ci_protocol; /* protocol (ipv4, ipv6, etc) */
+} ngx_conn_info_t;
+
+
+typedef struct ngx_http_req_info_s {
+ uint64_t ri_id;
+ string ri_uri;
+ string ri_args;
+} ngx_http_req_info_t;
+
+
+#pragma D binding "1.6.1" translator
+translator ngx_conn_info_t < ngx_http_dtrace_request_t *r > {
+ ci_local =
+ curpsinfo->pr_dmodel == PR_MODEL_ILP32 ?
+ copyinstr((uintptr_t)(uint64_t)(*(uint32_t *)copyin(
+ (uintptr_t)&((ngx_http_dtrace_request_32_t *)r)->laddr,
+ sizeof(((ngx_http_dtrace_request_32_t *)r)->laddr)))) :
+ copyinstr(*(uintptr_t *)copyin(
+ (uintptr_t)&r->laddr, sizeof(uint64_t)));
+
+ ci_remote =
+ curpsinfo->pr_dmodel == PR_MODEL_ILP32 ?
+ copyinstr((uintptr_t)(uint64_t)(*(uint32_t *)copyin(
+ (uintptr_t)&((ngx_http_dtrace_request_32_t *)r)->raddr,
+ sizeof(uint32_t)))) :
+ copyinstr(*(uintptr_t *)copyin(
+ (uintptr_t)&r->raddr, sizeof(uint64_t)));
+
+ ci_protocol = "ipv4";
+};
+
+#pragma D binding "1.6.1" translator
+translator ngx_http_req_info_t < ngx_http_dtrace_request_t *r > {
+ ri_id =
+ curpsinfo->pr_dmodel == PR_MODEL_ILP32 ?
+ *(uint64_t *)copyin(
+ (uintptr_t) &((ngx_http_dtrace_request_32_t *)r)->id,
+ sizeof(uint32_t)) :
+ *(uint64_t *)copyin((uintptr_t) &r->id, sizeof(uint64_t));
+
+ ri_uri =
+ curpsinfo->pr_dmodel == PR_MODEL_ILP32 ?
+ copyinstr((uintptr_t)(uint64_t)(*(uint32_t *)copyin(
+ (uintptr_t)&((ngx_http_dtrace_request_32_t *)r)->uri,
+ sizeof(uint32_t)))) :
+ copyinstr(*(uintptr_t *)copyin(
+ (uintptr_t)&r->uri, sizeof(uint64_t)));
+
+ ri_args =
+ curpsinfo->pr_dmodel == PR_MODEL_ILP32 ?
+ copyinstr((uintptr_t)(uint64_t)(*(uint32_t *)copyin(
+ (uintptr_t)&((ngx_http_dtrace_request_32_t *)r)->args,
+ sizeof(uint32_t)))) :
+ copyinstr(*(uintptr_t *)copyin(
+ (uintptr_t)&r->args, sizeof(uint64_t)));
+};
+
10 test_provider.d
@@ -0,0 +1,10 @@
+typedef struct { int dummy; } ngx_http_dtrace_request_t;
+typedef struct { int dummy; } ngx_http_req_info_t;
+typedef struct { int dummy; } ngx_conn_info_t;
+
+
+provider ngx_http {
+ probe request__start(ngx_http_dtrace_request_t *p) : (ngx_conn_info_t *p, ngx_http_req_info_t *p);
+ probe request__done(ngx_http_dtrace_request_t *p) : (ngx_conn_info_t *p, ngx_http_req_info_t *p);
+};
+
19 test_provider_impl.h
@@ -0,0 +1,19 @@
+#ifndef TEST_PROVIDER_IMPL_H
+#define TEST_PROVIDER_IMPL_H
+
+
+#include <stdlib.h>
+#include <stdint.h>
+
+
+typedef struct ngx_http_dtrace_request_s {
+ uint64_t id;
+ const char *uri;
+ const char *args;
+ const char *laddr;
+ const char *raddr;
+} ngx_http_dtrace_request_t;
+
+
+#endif
+

0 comments on commit ac92a63

Please sign in to comment.
Something went wrong with that request. Please try again.