YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/util/statistics.h
Line
Count
Source
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
#ifndef YB_ROCKSDB_UTIL_STATISTICS_H
21
#define YB_ROCKSDB_UTIL_STATISTICS_H
22
23
#include <atomic>
24
#include <mutex>
25
#include <string>
26
#include <vector>
27
28
#include "yb/gutil/ref_counted.h"
29
30
#include "yb/rocksdb/statistics.h"
31
32
namespace yb {
33
class MetricEntity;
34
class Histogram;
35
class HistogramPrototype;
36
37
template <class T>
38
class AtomicGauge;
39
template <class T>
40
class GaugePrototype;
41
}  // namespace yb
42
43
namespace rocksdb {
44
45
class StatisticsMetricPrototypes;
46
47
class StatisticsMetricImpl : public Statistics {
48
 public:
49
  StatisticsMetricImpl(
50
      const scoped_refptr<yb::MetricEntity>& hist_entity,
51
      const scoped_refptr<yb::MetricEntity>& tick_entity,
52
      const bool for_intents);
53
54
  virtual ~StatisticsMetricImpl();
55
56
  uint64_t getTickerCount(uint32_t ticker_type) const override;
57
  void histogramData(uint32_t histogram_type, HistogramData* const data) const override;
58
59
  void setTickerCount(uint32_t ticker_type, uint64_t count) override;
60
  void recordTick(uint32_t ticker_type, uint64_t count) override;
61
  void measureTime(uint32_t histogram_type, uint64_t value) override;
62
  void resetTickersForTest() override;
63
64
  const char* GetTickerName(uint32_t ticker_type) const override;
65
66
 private:
67
  std::vector<scoped_refptr<yb::Histogram>> histograms_;
68
  std::vector<scoped_refptr<yb::AtomicGauge<uint64_t>>> tickers_;
69
};
70
71
// Utility functions
72
inline void MeasureTime(Statistics* statistics, uint32_t histogram_type,
73
35.9M
                        uint64_t value) {
74
35.9M
  if (statistics) {
75
13.1M
    statistics->measureTime(histogram_type, value);
76
13.1M
  }
77
35.9M
}
78
79
inline void RecordTick(Statistics* statistics, uint32_t ticker_type,
80
3.99G
                       uint64_t count = 1) {
81
3.99G
  if (statistics) {
82
3.87G
    statistics->recordTick(ticker_type, count);
83
3.87G
  }
84
3.99G
}
85
86
inline void SetTickerCount(Statistics* statistics, uint32_t ticker_type,
87
29.7M
                           uint64_t count) {
88
29.7M
  if (statistics) {
89
14.4M
    statistics->setTickerCount(ticker_type, count);
90
14.4M
  }
91
29.7M
}
92
93
}  // namespace rocksdb
94
95
#endif  // YB_ROCKSDB_UTIL_STATISTICS_H