/Users/deen/code/yugabyte-db/src/yb/rocksdb/util/instrumented_mutex.cc
Line | Count | Source (jump to first uncovered line) |
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. |
5 | | // |
6 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | |
21 | | #include "yb/rocksdb/util/instrumented_mutex.h" |
22 | | |
23 | | #include "yb/rocksdb/util/perf_context_imp.h" |
24 | | #include "yb/rocksdb/util/statistics.h" |
25 | | #include "yb/rocksdb/util/stop_watch.h" |
26 | | |
27 | | #include "yb/util/stats/perf_step_timer.h" |
28 | | |
29 | | namespace rocksdb { |
30 | | namespace { |
31 | 199M | bool ShouldReportToStats(Env* env, Statistics* stats) { |
32 | 199M | return env != nullptr && stats != nullptr199M && |
33 | 199M | stats->stats_level_ != kExceptTimeForMutex163M ; |
34 | 199M | } |
35 | | } // namespace |
36 | | |
37 | 199M | void InstrumentedMutex::Lock() { |
38 | 199M | PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(db_mutex_lock_nanos, |
39 | 199M | stats_code_ == DB_MUTEX_WAIT_MICROS); |
40 | 199M | uint64_t wait_time_micros = 0; |
41 | 199M | if (ShouldReportToStats(env_, stats_)) { |
42 | 0 | { |
43 | 0 | StopWatch sw(env_, nullptr, 0, &wait_time_micros); |
44 | 0 | LockInternal(); |
45 | 0 | } |
46 | 0 | RecordTick(stats_, stats_code_, wait_time_micros); |
47 | 199M | } else { |
48 | 199M | LockInternal(); |
49 | 199M | } |
50 | 199M | } |
51 | | |
52 | 199M | void InstrumentedMutex::LockInternal() { |
53 | 199M | mutex_.Lock(); |
54 | 199M | } |
55 | | |
56 | 31.4k | void InstrumentedCondVar::Wait() { |
57 | 31.4k | PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(db_condition_wait_nanos, |
58 | 31.4k | stats_code_ == DB_MUTEX_WAIT_MICROS); |
59 | 31.4k | uint64_t wait_time_micros = 0; |
60 | 31.4k | if (ShouldReportToStats(env_, stats_)) { |
61 | 0 | { |
62 | 0 | StopWatch sw(env_, nullptr, 0, &wait_time_micros); |
63 | 0 | WaitInternal(); |
64 | 0 | } |
65 | 0 | RecordTick(stats_, stats_code_, wait_time_micros); |
66 | 31.4k | } else { |
67 | 31.4k | WaitInternal(); |
68 | 31.4k | } |
69 | 31.4k | } |
70 | | |
71 | 31.4k | void InstrumentedCondVar::WaitInternal() { |
72 | 31.4k | cond_.Wait(); |
73 | 31.4k | } |
74 | | |
75 | 253 | bool InstrumentedCondVar::TimedWait(uint64_t abs_time_us) { |
76 | 253 | PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(db_condition_wait_nanos, |
77 | 253 | stats_code_ == DB_MUTEX_WAIT_MICROS); |
78 | 253 | uint64_t wait_time_micros = 0; |
79 | 253 | bool result = false; |
80 | 253 | if (ShouldReportToStats(env_, stats_)) { |
81 | 0 | { |
82 | 0 | StopWatch sw(env_, nullptr, 0, &wait_time_micros); |
83 | 0 | result = TimedWaitInternal(abs_time_us); |
84 | 0 | } |
85 | 0 | RecordTick(stats_, stats_code_, wait_time_micros); |
86 | 253 | } else { |
87 | 253 | result = TimedWaitInternal(abs_time_us); |
88 | 253 | } |
89 | 253 | return result; |
90 | 253 | } |
91 | | |
92 | 253 | bool InstrumentedCondVar::TimedWaitInternal(uint64_t abs_time_us) { |
93 | 253 | return cond_.TimedWait(abs_time_us); |
94 | 253 | } |
95 | | |
96 | | } // namespace rocksdb |