summaryrefslogtreecommitdiff
path: root/src/include/mutex.i
diff options
context:
space:
mode:
authorAlex Gorrod <alexander.gorrod@mongodb.com>2016-10-24 14:28:49 +1100
committerAlex Gorrod <alexander.gorrod@mongodb.com>2016-10-24 14:28:49 +1100
commitef9a7983ea47cea78400a4472a3d4e46735385c5 (patch)
treef85d6f2d1861ec34788575ea87083f5009ee1133 /src/include/mutex.i
parent6a31c2118cce88c68281eda2ca9ab1df915a2773 (diff)
parent02dbad43779c17b0e2adceb31f4cd0b97bfaeb96 (diff)
downloadmongo-ef9a7983ea47cea78400a4472a3d4e46735385c5.tar.gz
Merge branch 'develop' into mongodb-3.4mongodb-3.4.0-rc2
Diffstat (limited to 'src/include/mutex.i')
-rw-r--r--src/include/mutex.i45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/include/mutex.i b/src/include/mutex.i
index cb1847d9991..a6309e0976b 100644
--- a/src/include/mutex.i
+++ b/src/include/mutex.i
@@ -32,6 +32,7 @@ __wt_spin_init(WT_SESSION_IMPL *session, WT_SPINLOCK *t, const char *name)
WT_UNUSED(name);
t->lock = 0;
+ t->stat_count_off = t->stat_app_usecs_off = t->stat_int_usecs_off = -1;
return (0);
}
@@ -111,6 +112,7 @@ __wt_spin_init(WT_SESSION_IMPL *session, WT_SPINLOCK *t, const char *name)
#endif
t->name = name;
+ t->stat_count_off = t->stat_app_usecs_off = t->stat_int_usecs_off = -1;
t->initialized = 1;
WT_UNUSED(session);
@@ -255,3 +257,46 @@ __wt_spin_unlock(WT_SESSION_IMPL *session, WT_SPINLOCK *t)
#error Unknown spinlock type
#endif
+
+/*
+ * WT_SPIN_INIT_TRACKED --
+ * Spinlock initialization, with tracking.
+ *
+ * Implemented as a macro so we can pass in a statistics field and convert
+ * it into a statistics structure array offset.
+ */
+#define WT_SPIN_INIT_TRACKED(session, t, name) do { \
+ WT_RET(__wt_spin_init(session, t, #name)); \
+ (t)->stat_count_off = (int16_t)WT_STATS_FIELD_TO_OFFSET( \
+ S2C(session)->stats, lock_##name##_count); \
+ (t)->stat_app_usecs_off = (int16_t)WT_STATS_FIELD_TO_OFFSET( \
+ S2C(session)->stats, lock_##name##_wait_application); \
+ (t)->stat_int_usecs_off = (int16_t)WT_STATS_FIELD_TO_OFFSET( \
+ S2C(session)->stats, lock_##name##_wait_internal); \
+} while (0)
+
+/*
+ * __wt_spin_lock_track --
+ * Spinlock acquisition, with tracking.
+ */
+static inline void
+__wt_spin_lock_track(WT_SESSION_IMPL *session, WT_SPINLOCK *t)
+{
+ struct timespec enter, leave;
+ int64_t **stats;
+
+ if (t->stat_count_off != -1 && WT_STAT_ENABLED(session)) {
+ __wt_epoch(session, &enter);
+ __wt_spin_lock(session, t);
+ __wt_epoch(session, &leave);
+ stats = (int64_t **)S2C(session)->stats;
+ stats[session->stat_bucket][t->stat_count_off]++;
+ if (F_ISSET(session, WT_SESSION_INTERNAL))
+ stats[session->stat_bucket][t->stat_int_usecs_off] +=
+ (int64_t)WT_TIMEDIFF_US(leave, enter);
+ else
+ stats[session->stat_bucket][t->stat_app_usecs_off] +=
+ (int64_t)WT_TIMEDIFF_US(leave, enter);
+ } else
+ __wt_spin_lock(session, t);
+}