]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/monitoring/instrumented_mutex.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
6 #include "monitoring/instrumented_mutex.h"
7 #include "monitoring/perf_context_imp.h"
8 #include "monitoring/thread_status_util.h"
9 #include "util/sync_point.h"
13 bool ShouldReportToStats(Env
* env
, Statistics
* stats
) {
14 return env
!= nullptr && stats
!= nullptr &&
15 stats
->stats_level_
> kExceptTimeForMutex
;
19 void InstrumentedMutex::Lock() {
20 PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(db_mutex_lock_nanos
,
21 stats_code_
== DB_MUTEX_WAIT_MICROS
);
22 uint64_t wait_time_micros
= 0;
23 if (ShouldReportToStats(env_
, stats_
)) {
25 StopWatch
sw(env_
, nullptr, 0, &wait_time_micros
);
28 RecordTick(stats_
, stats_code_
, wait_time_micros
);
34 void InstrumentedMutex::LockInternal() {
36 ThreadStatusUtil::TEST_StateDelay(ThreadStatus::STATE_MUTEX_WAIT
);
41 void InstrumentedCondVar::Wait() {
42 PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(db_condition_wait_nanos
,
43 stats_code_
== DB_MUTEX_WAIT_MICROS
);
44 uint64_t wait_time_micros
= 0;
45 if (ShouldReportToStats(env_
, stats_
)) {
47 StopWatch
sw(env_
, nullptr, 0, &wait_time_micros
);
50 RecordTick(stats_
, stats_code_
, wait_time_micros
);
56 void InstrumentedCondVar::WaitInternal() {
58 ThreadStatusUtil::TEST_StateDelay(ThreadStatus::STATE_MUTEX_WAIT
);
63 bool InstrumentedCondVar::TimedWait(uint64_t abs_time_us
) {
64 PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(db_condition_wait_nanos
,
65 stats_code_
== DB_MUTEX_WAIT_MICROS
);
66 uint64_t wait_time_micros
= 0;
68 if (ShouldReportToStats(env_
, stats_
)) {
70 StopWatch
sw(env_
, nullptr, 0, &wait_time_micros
);
71 result
= TimedWaitInternal(abs_time_us
);
73 RecordTick(stats_
, stats_code_
, wait_time_micros
);
75 result
= TimedWaitInternal(abs_time_us
);
80 bool InstrumentedCondVar::TimedWaitInternal(uint64_t abs_time_us
) {
82 ThreadStatusUtil::TEST_StateDelay(ThreadStatus::STATE_MUTEX_WAIT
);
85 TEST_SYNC_POINT_CALLBACK("InstrumentedCondVar::TimedWaitInternal",
88 return cond_
.TimedWait(abs_time_us
);
91 } // namespace rocksdb