Skip to content
Permalink
Browse files

SystemTap and DTrace integration

Change-Id: I307dac7b2985d2dce83c8c90b4928623c71f9c2a
Reviewed-on: http://review.couchbase.org/22828
Tested-by: Trond Norbye <trond.norbye@gmail.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
  • Loading branch information...
avsej committed Nov 26, 2012
1 parent effa17b commit 1e23a8036667de24e792134dd38e0a34b02106af
Showing with 656 additions and 52 deletions.
  1. +1 −0 .gitignore
  2. +50 −2 Makefile.am
  3. +32 −1 configure.ac
  4. +1 −0 src/arithmetic.c
  5. +1 −0 src/event.c
  6. +1 −0 src/flush.c
  7. +4 −1 src/get.c
  8. +74 −42 src/handler.c
  9. +14 −0 src/http.c
  10. +1 −0 src/internal.h
  11. +6 −2 src/observe.c
  12. +213 −0 src/probes.d
  13. +1 −0 src/remove.c
  14. +41 −4 src/server.c
  15. +2 −0 src/stats.c
  16. +1 −0 src/store.c
  17. +1 −0 src/touch.c
  18. +211 −0 src/trace.h
  19. +1 −0 src/verbosity.c
@@ -58,6 +58,7 @@
/m4/lt~obsolete.m4
/m4/version.m4
/src/config.h
/src/probes.h
/src/config.h.in
/src/stamp-h1
/tests/*-test
@@ -32,6 +32,8 @@ if BUILD_TOOLS
bin_PROGRAMS = tools/cbc
man_MANS = man/man1/cbc.1 man/man4/cbcrc.4
endif
CLEANFILES = tests/CouchbaseMock.jar
BUILT_SOURCES=

pkginclude_HEADERS = \
include/libcouchbase/behavior.h \
@@ -116,6 +118,7 @@ libcouchbase_la_SOURCES = \
src/timer.c \
src/timings.c \
src/touch.c \
src/trace.h \
src/utilities.c \
src/verbosity.c \
src/wait.c
@@ -141,6 +144,52 @@ libcouchbase_la_SOURCES += \
libcouchbase_la_CPPFLAGS += -DLIBCOUCHBASE_DEBUG_NOCTX
endif

if ENABLE_DTRACE
BUILT_SOURCES += src/probes.h
CLEANFILES += src/probes.h

src/probes.h: src/probes.d
$(DTRACE) -C -h -s $< -o $@

probes.o: src/probes.d
$(DTRACE) -C $(DTRACE_DASH_G) -s $< -o $@

probes.lo: probes.o
$(AM_V_GEN)printf %s\\n \
'# $@ - a libtool object file' \
'# Generated by libtool (GNU libtool) 2.4' \
'# Actually generated by Makefile.am, in order to shut up libtool' \
"pic_object='$<'" \
"non_pic_object='$<'" \
> $@

libcouchbase_la_SOURCES += src/probes.h

if DTRACE_INSTRUMENT_OBJECT

# We need to change the name from src/libcouchbase_la-fname.lo to
# src/.libs/libcouchbase_la-fname.o ;)
LIBCOUCHBASE_OBJS=$(libcouchbase_la_OBJECTS:%lo=%o)
LIBCOUCHBASE_OBJECTS=$(LIBCOUCHBASE_OBJS:src%=src/.libs%)
src/libcouchbase_la-probes.lo: $(lilbcouchbase_la_OBJECTS) src/probes.h
$(DTRACE) $(DTRACEFLAGS) -C -G \
-o src/.libs/libcouchb\ase_la-probes.o \
-s ${srcdir}/src/probes.d \
$(LIBCOUCHBASE_OBJECTS)
sed -e s,instance,probes,g src/libcouchbase_la-instance.lo > src/libcouchbase_la-probes.lo

libcouchbase_la_DEPENDENCIES += src/libcouchbase_la-probes.lo
libcouchbase_la_LIBADD += src/libcouchbase_la-probes.lo
else
if !APPLE_DTRACE
libcouchbase_la_DEPENDENCIES += probes.lo
libcouchbase_la_LIBADD += probes.lo
endif

endif

endif

libcouchbase_la_SOURCES += src/iofactory.c
if HAVE_WINSOCK2
if !HAVE_LIBEVENT
@@ -218,8 +267,6 @@ tests_unit_tests_CPPFLAGS += -I$(GTEST_ROOT) -I$(GTEST_ROOT)/include $(NO_WERROR
endif
endif

CLEANFILES = tests/CouchbaseMock.jar
BUILT_SOURCES=
if DOWNLOAD_GTEST
gtest-1.6.0: gtest-1.6.0.zip
${UNZIP} -o -qq gtest-1.6.0.zip
@@ -425,4 +472,5 @@ reformat:
$(top_srcdir)/plugins/io/*/*.[ch] \
$(top_srcdir)/win32/*.[ch]


sinclude packaging/*/package.mk
@@ -166,7 +166,7 @@ AC_CHECK_HEADERS_ONCE([mach/mach_time.h sys/socket.h sys/time.h
netinet/in.h inttypes.h netdb.h unistd.h
ws2tcpip.h winsock2.h event.h stdint.h
sys/uio.h sys/types.h fcntl.h dlfcn.h
ev.h libev/ev.h])
ev.h libev/ev.h sys/sdt.h])

AS_IF([test "x$ac_cv_header_stdint_h" != "xyes"],
[AC_MSG_ERROR(Failed to locate stdint.h)])
@@ -492,6 +492,37 @@ AM_CONDITIONAL(HAVE_GOOGLETEST_SRC, [test "$ac_cv_have_gtest_src" = "yes"])
AM_CONDITIONAL(HAVE_GOOGLETEST, [test "$ac_cv_have_gtest" = "yes" -o \
"$ac_cv_have_gtest_src" = "yes"])

#
# SystemTap and DTrace support
#
AC_CHECK_PROGS([DTRACE], [dtrace])

# On Solaris we need to instrument all of the object files, but this isn't
# true with DTrace on MacOSX or SystemTap. Instead of doing the hard
# work of trying to check if we have to do this, just do it if __sun is
# defined...
AC_CHECK_DECL([__sun])
AC_CHECK_DECL([__APPLE__])
AS_IF([test "x$ac_cv_have_decl___APPLE__" != "xyes"],
[DTRACE_DASH_G="-G"])
AC_SUBST(DTRACE_DASH_G)
AC_CACHE_CHECK([for SystemTap/DTrace requirements], [ac_cv_enable_dtrace], [
AS_IF([test "x$ac_cv_prog_DTRACE" != "xno" -a "x$ac_cv_header_sys_sdt_h" = "xyes"], [
AS_IF([test "x$ac_cv_have_decl___APPLE__" = "xyes"],
[ ac_cv_enable_dtrace=no ],
[ ac_cv_enable_dtrace=yes ])
], [
ac_cv_enable_dtrace=no
])
])
AS_IF([test "x$ac_cv_enable_dtrace" = "xyes"],
[AC_DEFINE([HAVE_DTRACE], [1], [Enables SystemTap / DTrace Support])])

AM_CONDITIONAL([ENABLE_DTRACE], [test "x$ac_cv_enable_dtrace" = xyes ])
AM_CONDITIONAL([DTRACE_INSTRUMENT_OBJECT],
[test "x$ac_cv_have_decl___sun" = "xyes"])
AM_CONDITIONAL([APPLE_DTRACE], [test "x$ac_cv_have_decl__APPLE__" = "xyes"])

AH_TOP([
#ifndef CONFIG_H
#define CONFIG_H
@@ -94,6 +94,7 @@ lcb_error_t lcb_arithmetic(lcb_t instance,
sizeof(req.message.body.expiration));
}

TRACE_ARITHMETIC_BEGIN(&req, key, nkey, delta, initial, create ? exp : 0xffffffff);
lcb_server_start_packet(server, command_cookie, req.bytes,
sizeof(req.bytes));
lcb_server_write_packet(server, key, nkey);
@@ -184,6 +184,7 @@ static int parse_single(lcb_server_t *c, hrtime_t stop)
* get code different from LCB_NOT_MY_VBUCKET */
ct.start = gethrtime();
lcb_server_retry_packet(new_srv, &ct, &req, sizeof(req));
/* FIXME dtrace instrumentation */
lcb_server_write_packet(new_srv, body, nbody);
lcb_server_end_packet(new_srv);
lcb_server_send_packets(new_srv);
@@ -50,6 +50,7 @@ lcb_error_t lcb_flush(lcb_t instance, const void *command_cookie,

for (ii = 0; ii < instance->nservers; ++ii) {
server = instance->servers + ii;
TRACE_FLUSH_BEGIN(&flush, server->authority);
lcb_server_complete_packet(server, command_cookie,
flush.bytes,
sizeof(flush.bytes));
@@ -106,6 +106,7 @@ lcb_error_t lcb_unlock(lcb_t instance,
req.message.header.request.opaque = ++instance->seqno;
req.message.header.request.opcode = CMD_UNLOCK_KEY;

TRACE_UNLOCK_BEGIN(&req, key, nkey);
lcb_server_start_packet(server, command_cookie, req.bytes,
sizeof(req.bytes));
lcb_server_write_packet(server, key, nkey);
@@ -166,6 +167,7 @@ lcb_error_t lcb_get_replica(lcb_t instance,
req.message.header.request.vbucket = ntohs((lcb_uint16_t)vb);
req.message.header.request.bodylen = ntohl((lcb_uint32_t)nkey);
req.message.header.request.opaque = ++instance->seqno;
TRACE_GET_BEGIN(&req, key, nkey, 0);
lcb_server_start_packet(server, command_cookie,
req.bytes, sizeof(req.bytes));
lcb_server_write_packet(server, key, nkey);
@@ -245,6 +247,7 @@ static lcb_error_t lcb_single_get(lcb_t instance,
/* the expiration is optional for GETL command */
req.message.header.request.opcode = CMD_GET_LOCKED;
}
TRACE_GET_BEGIN(&req, key, nkey, exp);
lcb_server_start_packet(server, command_cookie, req.bytes, nbytes);
lcb_server_write_packet(server, key, nkey);
lcb_server_end_packet(server);
@@ -342,7 +345,7 @@ static lcb_error_t lcb_multi_get(lcb_t instance,
/* the expiration is optional for GETL command */
req.message.header.request.opcode = CMD_GET_LOCKED;
}

TRACE_GET_BEGIN(&req, key, nkey, exp);
lcb_server_start_packet(server, command_cookie, req.bytes, nreq);
lcb_server_write_packet(server, key, nkey);
lcb_server_end_packet(server);
Oops, something went wrong.

0 comments on commit 1e23a80

Please sign in to comment.
You can’t perform that action at this time.