1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "common/mutex_debug.h"
16 #include "common/perf_counters.h"
17 #include "common/ceph_context.h"
18 #include "common/config.h"
21 namespace mutex_debug_detail {
23 l_mutex_first = 999082,
28 mutex_debugging_base::mutex_debugging_base(const std::string &n, bool bt,
30 id(-1), backtrace(bt), nlock(0), locked_by(thread::id()),
35 name = string("Unnamed-Mutex-") + uu.to_string();
40 PerfCountersBuilder b(cct, string("mutex-") + name,
41 l_mutex_first, l_mutex_last);
42 b.add_time_avg(l_mutex_wait, "wait",
43 "Average time of mutex in locked state");
44 logger = b.create_perf_counters();
45 cct->get_perfcounters_collection()->add(logger);
46 logger->set(l_mutex_wait, 0);
52 mutex_debugging_base::~mutex_debugging_base() {
55 cct->get_perfcounters_collection()->remove(logger);
59 lockdep_unregister(id);
63 void mutex_debugging_base::_register() {
64 id = lockdep_register(name.c_str());
66 void mutex_debugging_base::_will_lock() { // about to lock
67 id = lockdep_will_lock(name.c_str(), id, backtrace);
69 void mutex_debugging_base::_locked() { // just locked
70 id = lockdep_locked(name.c_str(), id, backtrace);
72 void mutex_debugging_base::_will_unlock() { // about to unlock
73 id = lockdep_will_unlock(name.c_str(), id);
76 ceph::mono_time mutex_debugging_base::before_lock_blocks() {
77 if (logger && cct && cct->_conf->mutex_perf_counter)
78 return ceph::mono_clock::now();
79 return ceph::mono_time::min();
82 void mutex_debugging_base::after_lock_blocks(ceph::mono_time start,
84 if (logger && cct && cct->_conf->mutex_perf_counter)
85 logger->tinc(l_mutex_wait,
86 ceph::mono_clock::now() - start);
87 if (!no_lockdep && g_lockdep)
90 } // namespace mutex_debug_detail