YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rpc/proxy_base.h
Line
Count
Source
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#ifndef YB_RPC_PROXY_BASE_H
15
#define YB_RPC_PROXY_BASE_H
16
17
#include "yb/rpc/rpc_fwd.h"
18
19
#include "yb/util/metrics_fwd.h"
20
#include "yb/util/monotime.h"
21
#include "yb/util/net/net_fwd.h"
22
23
namespace yb {
24
namespace rpc {
25
26
struct OutboundMethodMetrics {
27
  scoped_refptr<Counter> request_bytes;
28
  scoped_refptr<Counter> response_bytes;
29
};
30
31
struct ProxyMetrics {};
32
using ProxyMetricsPtr = std::shared_ptr<ProxyMetrics>;
33
34
using ProxyMetricsFactory = ProxyMetricsPtr(*)(const scoped_refptr<MetricEntity>& entity);
35
36
template <size_t size>
37
struct ProxyMetricsImpl : public ProxyMetrics {
38
  std::array<OutboundMethodMetrics, size> value;
39
};
40
41
class ProxyBase {
42
 public:
43
  ProxyBase(const std::string& service_name, ProxyMetricsFactory metrics_factory,
44
            ProxyCache* cache, const HostPort& remote,
45
            const Protocol* protocol = nullptr,
46
            const MonoDelta& resolve_cache_timeout = MonoDelta());
47
48
  template <size_t size>
49
25.2M
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
25.2M
    if (!metrics_) {
51
1.42M
      return nullptr;
52
1.42M
    }
53
23.8M
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
23.8M
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
23.8M
  }
_ZNK2yb3rpc9ProxyBase7metricsILm1EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
Line
Count
Source
49
403k
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
403k
    if (!metrics_) {
51
9
      return nullptr;
52
9
    }
53
403k
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
403k
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
403k
  }
_ZNK2yb3rpc9ProxyBase7metricsILm10EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
Line
Count
Source
49
159
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
159
    if (!metrics_) {
51
0
      return nullptr;
52
0
    }
53
159
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
159
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
159
  }
_ZNK2yb3rpc9ProxyBase7metricsILm12EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
Line
Count
Source
49
9.72M
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
9.72M
    if (!metrics_) {
51
0
      return nullptr;
52
0
    }
53
9.72M
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
9.72M
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
9.72M
  }
_ZNK2yb3rpc9ProxyBase7metricsILm9EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
Line
Count
Source
49
199
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
199
    if (!metrics_) {
51
191
      return nullptr;
52
191
    }
53
8
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
8
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
8
  }
_ZNK2yb3rpc9ProxyBase7metricsILm7EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
Line
Count
Source
49
186k
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
186k
    if (!metrics_) {
51
25.1k
      return nullptr;
52
25.1k
    }
53
161k
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
161k
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
161k
  }
_ZNK2yb3rpc9ProxyBase7metricsILm18EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
Line
Count
Source
49
4.59M
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
4.59M
    if (!metrics_) {
51
1.26M
      return nullptr;
52
1.26M
    }
53
3.33M
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
3.33M
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
3.33M
  }
_ZNK2yb3rpc9ProxyBase7metricsILm6EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
Line
Count
Source
49
120k
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
120k
    if (!metrics_) {
51
0
      return nullptr;
52
0
    }
53
120k
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
120k
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
120k
  }
_ZNK2yb3rpc9ProxyBase7metricsILm29EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
Line
Count
Source
49
136k
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
136k
    if (!metrics_) {
51
3
      return nullptr;
52
3
    }
53
136k
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
136k
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
136k
  }
_ZNK2yb3rpc9ProxyBase7metricsILm5EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
Line
Count
Source
49
57.9k
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
57.9k
    if (!metrics_) {
51
85
      return nullptr;
52
85
    }
53
57.8k
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
57.8k
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
57.8k
  }
_ZNK2yb3rpc9ProxyBase7metricsILm14EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
Line
Count
Source
49
2.70k
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
2.70k
    if (!metrics_) {
51
14
      return nullptr;
52
14
    }
53
2.69k
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
2.69k
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
2.69k
  }
_ZNK2yb3rpc9ProxyBase7metricsILm24EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
Line
Count
Source
49
1.00M
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
1.00M
    if (!metrics_) {
51
0
      return nullptr;
52
0
    }
53
1.00M
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
1.00M
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
1.00M
  }
_ZNK2yb3rpc9ProxyBase7metricsILm11EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
Line
Count
Source
49
912k
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
912k
    if (!metrics_) {
51
4.65k
      return nullptr;
52
4.65k
    }
53
908k
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
908k
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
908k
  }
_ZNK2yb3rpc9ProxyBase7metricsILm13EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
Line
Count
Source
49
157k
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
157k
    if (!metrics_) {
51
30
      return nullptr;
52
30
    }
53
157k
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
157k
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
157k
  }
Unexecuted instantiation: _ZNK2yb3rpc9ProxyBase7metricsILm2EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
_ZNK2yb3rpc9ProxyBase7metricsILm21EEENSt3__110shared_ptrIKNS0_21OutboundMethodMetricsEEEm
Line
Count
Source
49
7.98M
  std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const {
50
7.98M
    if (!metrics_) {
51
137k
      return nullptr;
52
137k
    }
53
7.84M
    auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get());
54
7.84M
    return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]);
55
7.84M
  }
56
57
25.3M
  Proxy& proxy() const { return *proxy_; }
58
59
 private:
60
  ProxyPtr proxy_;
61
  ProxyMetricsPtr metrics_;
62
};
63
64
}  // namespace rpc
65
}  // namespace yb
66
67
#endif  // YB_RPC_PROXY_BASE_H