YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
77.7M
bool ShouldReportToStats(Env* env, Statistics* stats) {
32
77.7M
  return env != nullptr && stats != nullptr &&
33
42.3M
         stats->stats_level_ != kExceptTimeForMutex;
34
77.7M
}
35
}  // namespace
36
37
77.7M
void InstrumentedMutex::Lock() {
38
77.7M
  PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(db_mutex_lock_nanos,
39
77.7M
                                         stats_code_ == DB_MUTEX_WAIT_MICROS);
40
77.7M
  uint64_t wait_time_micros = 0;
41
77.7M
  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
77.7M
  } else {
48
77.7M
    LockInternal();
49
77.7M
  }
50
77.7M
}
51
52
77.7M
void InstrumentedMutex::LockInternal() {
53
77.7M
  mutex_.Lock();
54
77.7M
}
55
56
28.1k
void InstrumentedCondVar::Wait() {
57
28.1k
  PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(db_condition_wait_nanos,
58
28.1k
                                         stats_code_ == DB_MUTEX_WAIT_MICROS);
59
28.1k
  uint64_t wait_time_micros = 0;
60
28.1k
  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
28.1k
  } else {
67
28.1k
    WaitInternal();
68
28.1k
  }
69
28.1k
}
70
71
28.1k
void InstrumentedCondVar::WaitInternal() {
72
28.1k
  cond_.Wait();
73
28.1k
}
74
75
233
bool InstrumentedCondVar::TimedWait(uint64_t abs_time_us) {
76
233
  PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(db_condition_wait_nanos,
77
233
                                         stats_code_ == DB_MUTEX_WAIT_MICROS);
78
233
  uint64_t wait_time_micros = 0;
79
233
  bool result = false;
80
233
  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
233
  } else {
87
233
    result = TimedWaitInternal(abs_time_us);
88
233
  }
89
233
  return result;
90
233
}
91
92
233
bool InstrumentedCondVar::TimedWaitInternal(uint64_t abs_time_us) {
93
233
  return cond_.TimedWait(abs_time_us);
94
233
}
95
96
}  // namespace rocksdb