From 0214012508364028b7ac4c9a6774659436887227 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Wed, 5 Nov 2008 14:36:57 +0000 Subject: [PATCH] threshhold and ./configure option for lock profiler --- configure.in | 9 +++++++++ src/libstrongswan/Makefile.am | 4 ++++ src/libstrongswan/utils/mutex.c | 17 +++++++++++------ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/configure.in b/configure.in index 4caa11235..b016451c7 100644 --- a/configure.in +++ b/configure.in @@ -377,6 +377,14 @@ AC_ARG_ENABLE( fi] ) +AC_ARG_ENABLE( + [lock-profiler], + AS_HELP_STRING([--enable-lock-profiling],[enable lock/mutex profiling code (default is NO).]), + [if test x$enableval = xyes; then + lock_profiler=true + fi] +) + AC_ARG_ENABLE( [unit-tests], AS_HELP_STRING([--enable-unit-tests],[enable unit tests on IKEv2 daemon startup (default is NO).]), @@ -899,6 +907,7 @@ dnl ============= AM_CONDITIONAL(USE_SMARTCARD, test x$smartcard = xtrue) AM_CONDITIONAL(USE_CISCO_QUIRKS, test x$cisco_quirks = xtrue) AM_CONDITIONAL(USE_LEAK_DETECTIVE, test x$leak_detective = xtrue) +AM_CONDITIONAL(USE_LOCK_PROFILER, test x$lock_profiler = xtrue) AM_CONDITIONAL(USE_NAT_TRANSPORT, test x$nat_transport = xtrue) AM_CONDITIONAL(USE_VENDORID, test x$vendor_id = xtrue) AM_CONDITIONAL(USE_XAUTH_VID, test x$xauth_vid = xtrue) diff --git a/src/libstrongswan/Makefile.am b/src/libstrongswan/Makefile.am index 52f2f1892..1423db5c3 100644 --- a/src/libstrongswan/Makefile.am +++ b/src/libstrongswan/Makefile.am @@ -64,6 +64,10 @@ if USE_LEAK_DETECTIVE libstrongswan_la_SOURCES += utils/leak_detective.c utils/leak_detective.h endif +if USE_LOCK_PROFILER + AM_CFLAGS += -DLOCK_PROFILER +endif + if USE_INTEGRITY_TEST libstrongswan_la_SOURCES += \ fips/fips_canister_end.c diff --git a/src/libstrongswan/utils/mutex.c b/src/libstrongswan/utils/mutex.c index 25d2788aa..326a93255 100644 --- a/src/libstrongswan/utils/mutex.c +++ b/src/libstrongswan/utils/mutex.c @@ -27,6 +27,10 @@ #include #include +/** + * Do not report mutexes with an overall waiting time smaller than this (in us) + */ +#define PROFILE_TRESHHOLD 1000 typedef struct private_mutex_t private_mutex_t; typedef struct private_r_mutex_t private_r_mutex_t; @@ -103,17 +107,18 @@ struct private_condvar_t { }; #ifdef LOCK_PROFILER - -#include - /** * Print and cleanup mutex profiler */ static void profiler_cleanup(private_mutex_t *this) { - fprintf(stderr, "waited %d.%06ds in mutex, created at:", - this->waited.tv_sec, this->waited.tv_usec); - this->backtrace->log(this->backtrace, stderr); + if (this->waited.tv_sec > 0 || + this->waited.tv_usec > PROFILE_TRESHHOLD) + { + fprintf(stderr, "waited %d.%06ds in mutex, created at:", + this->waited.tv_sec, this->waited.tv_usec); + this->backtrace->log(this->backtrace, stderr); + } this->backtrace->destroy(this->backtrace); }