From 7a9eb3fc5456568850fc2643837e1eabc37128ba Mon Sep 17 00:00:00 2001 From: Noah Watkins Date: Fri, 30 May 2014 14:13:12 -0700 Subject: [PATCH] tracing: bootstrap lttng-ust with mutex events See src/tracing/README.md Signed-off-by: Noah Watkins --- configure.ac | 1 + src/Makefile-env.am | 1 + src/Makefile.am | 4 ++-- src/common/Makefile.am | 3 ++- src/common/Mutex.cc | 14 +++++++++++--- src/tracing/Makefile.am | 8 ++++++++ src/tracing/README.md | 32 ++++++++++++++++++++++++++++++++ src/tracing/mutex.tp | 19 +++++++++++++++++++ src/tracing/mutex.tp.c | 7 +++++++ src/tracing/mutex.tp.h | 35 +++++++++++++++++++++++++++++++++++ 10 files changed, 118 insertions(+), 6 deletions(-) create mode 100644 src/tracing/Makefile.am create mode 100644 src/tracing/README.md create mode 100644 src/tracing/mutex.tp create mode 100644 src/tracing/mutex.tp.c create mode 100644 src/tracing/mutex.tp.h diff --git a/configure.ac b/configure.ac index 9506b427a3599..dd4ac404cb47f 100644 --- a/configure.ac +++ b/configure.ac @@ -819,6 +819,7 @@ AC_CONFIG_FILES([Makefile src/ocf/ceph src/ocf/rbd src/java/Makefile + src/tracing/Makefile man/Makefile ceph.spec]) AC_OUTPUT diff --git a/src/Makefile-env.am b/src/Makefile-env.am index 3bf1b6d937370..5a9d7f3ac482a 100644 --- a/src/Makefile-env.am +++ b/src/Makefile-env.am @@ -156,6 +156,7 @@ LIBRBD = librbd.la LIBKRBD = libkrbd.la LIBCEPHFS = libcephfs.la LIBERASURE_CODE = liberasure_code.la +LIBTRACEPOINTS = tracing/libtracepoints.la if WITH_LIBAIO LIBOS += -laio diff --git a/src/Makefile.am b/src/Makefile.am index b0f52b822de4f..257e6c104e0ff 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ include Makefile-env.am -SUBDIRS += ocf java -DIST_SUBDIRS += gtest ocf libs3 java +SUBDIRS += ocf java tracing +DIST_SUBDIRS += gtest ocf libs3 java tracing # subdirs diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 0b99c6e3f1589..1d290a69f3f1d 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -112,7 +112,8 @@ noinst_HEADERS += \ LIBCOMMON_DEPS += \ $(LIBERASURE_CODE) \ $(LIBMSG) $(LIBAUTH) \ - $(LIBCRUSH) $(LIBJSON_SPIRIT) $(LIBLOG) $(LIBARCH) + $(LIBCRUSH) $(LIBJSON_SPIRIT) $(LIBLOG) $(LIBARCH) \ + $(LIBTRACEPOINTS) if LINUX LIBCOMMON_DEPS += -lrt diff --git a/src/common/Mutex.cc b/src/common/Mutex.cc index f1e9a550c81b9..a79d6ade5d9f4 100644 --- a/src/common/Mutex.cc +++ b/src/common/Mutex.cc @@ -19,6 +19,7 @@ #include "common/config.h" #include "include/utime.h" #include "common/Clock.h" +#include "tracing/mutex.tp.h" Mutex::Mutex(const char *n, bool r, bool ld, bool bt, @@ -77,20 +78,27 @@ Mutex::~Mutex() { } void Mutex::Lock(bool no_lockdep) { + utime_t start; + int r; + + tracepoint(mutex, lock_enter, this, name); + if (lockdep && g_lockdep && !no_lockdep) _will_lock(); if (TryLock()) { - return; + goto out; } - utime_t start; if (logger && cct && cct->_conf->mutex_perf_counter) start = ceph_clock_now(cct); - int r = pthread_mutex_lock(&_m); + r = pthread_mutex_lock(&_m); if (logger && cct && cct->_conf->mutex_perf_counter) logger->tinc(l_mutex_wait, ceph_clock_now(cct) - start); assert(r == 0); if (lockdep && g_lockdep) _locked(); _post_lock(); + +out: + tracepoint(mutex, lock_exit, this, name); } diff --git a/src/tracing/Makefile.am b/src/tracing/Makefile.am new file mode 100644 index 0000000000000..8da61a843e7f2 --- /dev/null +++ b/src/tracing/Makefile.am @@ -0,0 +1,8 @@ +libtracepoints_la_SOURCES = \ + mutex.tp.c \ + mutex.tp.h + +libtracepoints_la_LIBADD = -llttng-ust -ldl +libtracepoints_la_CPPFLAGS = -DTRACEPOINT_DEFINE -DTRACEPOINT_PROBE_DYNAMIC_LINKAGE +libtracepoints_la_LDFLAGS = +noinst_LTLIBRARIES = libtracepoints.la diff --git a/src/tracing/README.md b/src/tracing/README.md new file mode 100644 index 0000000000000..1c86eb3b04ba5 --- /dev/null +++ b/src/tracing/README.md @@ -0,0 +1,32 @@ +Add New Provider +================ + +## Create tracepoint definition file + +Add tracepoint definitions for the provider into a `.tp` file. Documentation +on defining a tracepoint can be found in `man lttng-ust`. By convention files +are named according to the logical sub-system they correspond to (e.g. +`mutex.tp`, `pg.tp`). + +## Generate tracepoint source files + +The `.tp` file is converted into source files using the `lttng-gen-tp` tool. + + lttng-gen-tp mutex.tp -o mutex.tp.h -o mutex.tp.c + +## Add source files to libtracepoints.la + +Modify Makefile.am to include the generated source files from the previous +step. + +## Commit changes to Git + +Commit both the source `.tp` file as well as the generated sources, and the +changes to Makefile.am. + +Add Tracepoint to Existing Provider +=================================== + +New tracepoints can be added to an existing provider by updating the +corresponding `.tp` file and re-generating the source files. Make sure to +commit the updated files back into Git. diff --git a/src/tracing/mutex.tp b/src/tracing/mutex.tp new file mode 100644 index 0000000000000..82bdf15a52204 --- /dev/null +++ b/src/tracing/mutex.tp @@ -0,0 +1,19 @@ +TRACEPOINT_EVENT(mutex, lock_enter, + TP_ARGS( + const void *, addr, + const char *, name), + TP_FIELDS( + ctf_integer_hex(unsigned long, addr, addr) + ctf_string(name, name) + ) +) + +TRACEPOINT_EVENT(mutex, lock_exit, + TP_ARGS( + const void *, addr, + const char *, name), + TP_FIELDS( + ctf_integer_hex(unsigned long, addr, addr) + ctf_string(name, name) + ) +) diff --git a/src/tracing/mutex.tp.c b/src/tracing/mutex.tp.c new file mode 100644 index 0000000000000..1727e8089c76c --- /dev/null +++ b/src/tracing/mutex.tp.c @@ -0,0 +1,7 @@ + +#define TRACEPOINT_CREATE_PROBES +/* + * The header containing our TRACEPOINT_EVENTs. + */ +#define TRACEPOINT_DEFINE +#include "mutex.tp.h" diff --git a/src/tracing/mutex.tp.h b/src/tracing/mutex.tp.h new file mode 100644 index 0000000000000..24d45543863b1 --- /dev/null +++ b/src/tracing/mutex.tp.h @@ -0,0 +1,35 @@ + +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER mutex + +#undef TRACEPOINT_INCLUDE +#define TRACEPOINT_INCLUDE "./mutex.tp.h" + +#if !defined(MUTEX_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define MUTEX_TP_H + +#include + +TRACEPOINT_EVENT(mutex, lock_enter, + TP_ARGS( + const void *, addr, + const char *, name), + TP_FIELDS( + ctf_integer_hex(unsigned long, addr, addr) + ctf_string(name, name) + ) +) + +TRACEPOINT_EVENT(mutex, lock_exit, + TP_ARGS( + const void *, addr, + const char *, name), + TP_FIELDS( + ctf_integer_hex(unsigned long, addr, addr) + ctf_string(name, name) + ) +) + +#endif /* MUTEX_TP_H */ + +#include -- 2.39.5