/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 | 86.0M | std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const { |
50 | 86.0M | if (!metrics_) { |
51 | 1.53M | return nullptr; |
52 | 1.53M | } |
53 | 84.5M | auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get()); |
54 | 84.5M | return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]); |
55 | 86.0M | } std::__1::shared_ptr<yb::rpc::OutboundMethodMetrics const> yb::rpc::ProxyBase::metrics<5ul>(unsigned long) const Line | Count | Source | 49 | 69.6k | std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const { | 50 | 69.6k | if (!metrics_) { | 51 | 176 | return nullptr; | 52 | 176 | } | 53 | 69.5k | auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get()); | 54 | 69.5k | return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]); | 55 | 69.6k | } |
std::__1::shared_ptr<yb::rpc::OutboundMethodMetrics const> yb::rpc::ProxyBase::metrics<13ul>(unsigned long) const Line | Count | Source | 49 | 259k | std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const { | 50 | 259k | if (!metrics_) { | 51 | 32 | return nullptr; | 52 | 32 | } | 53 | 259k | auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get()); | 54 | 259k | return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]); | 55 | 259k | } |
std::__1::shared_ptr<yb::rpc::OutboundMethodMetrics const> yb::rpc::ProxyBase::metrics<10ul>(unsigned long) const Line | Count | Source | 49 | 219 | std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const { | 50 | 219 | if (!metrics_) { | 51 | 0 | return nullptr; | 52 | 0 | } | 53 | 219 | auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get()); | 54 | 219 | return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]); | 55 | 219 | } |
std::__1::shared_ptr<yb::rpc::OutboundMethodMetrics const> yb::rpc::ProxyBase::metrics<1ul>(unsigned long) const Line | Count | Source | 49 | 5.25M | std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const { | 50 | 5.25M | if (!metrics_) { | 51 | 9 | return nullptr; | 52 | 9 | } | 53 | 5.25M | auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get()); | 54 | 5.25M | return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]); | 55 | 5.25M | } |
std::__1::shared_ptr<yb::rpc::OutboundMethodMetrics const> yb::rpc::ProxyBase::metrics<9ul>(unsigned long) const Line | Count | Source | 49 | 40 | std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const { | 50 | 40 | if (!metrics_) { | 51 | 40 | return nullptr; | 52 | 40 | } | 53 | 0 | auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get()); | 54 | 0 | return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]); | 55 | 40 | } |
std::__1::shared_ptr<yb::rpc::OutboundMethodMetrics const> yb::rpc::ProxyBase::metrics<29ul>(unsigned long) const Line | Count | Source | 49 | 2.94M | std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const { | 50 | 2.94M | if (!metrics_) { | 51 | 34.8k | return nullptr; | 52 | 34.8k | } | 53 | 2.91M | auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get()); | 54 | 2.91M | return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]); | 55 | 2.94M | } |
std::__1::shared_ptr<yb::rpc::OutboundMethodMetrics const> yb::rpc::ProxyBase::metrics<21ul>(unsigned long) const Line | Count | Source | 49 | 15.2M | std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const { | 50 | 15.2M | if (!metrics_) { | 51 | 98.6k | return nullptr; | 52 | 98.6k | } | 53 | 15.1M | auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get()); | 54 | 15.1M | return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]); | 55 | 15.2M | } |
std::__1::shared_ptr<yb::rpc::OutboundMethodMetrics const> yb::rpc::ProxyBase::metrics<11ul>(unsigned long) const Line | Count | Source | 49 | 75.6k | std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const { | 50 | 75.6k | if (!metrics_) { | 51 | 3.99k | return nullptr; | 52 | 3.99k | } | 53 | 71.6k | auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get()); | 54 | 71.6k | return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]); | 55 | 75.6k | } |
std::__1::shared_ptr<yb::rpc::OutboundMethodMetrics const> yb::rpc::ProxyBase::metrics<7ul>(unsigned long) const Line | Count | Source | 49 | 655k | std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const { | 50 | 655k | if (!metrics_) { | 51 | 25.9k | return nullptr; | 52 | 25.9k | } | 53 | 629k | auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get()); | 54 | 629k | return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]); | 55 | 655k | } |
std::__1::shared_ptr<yb::rpc::OutboundMethodMetrics const> yb::rpc::ProxyBase::metrics<18ul>(unsigned long) const Line | Count | Source | 49 | 33.9M | std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const { | 50 | 33.9M | if (!metrics_) { | 51 | 1.36M | return nullptr; | 52 | 1.36M | } | 53 | 32.6M | auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get()); | 54 | 32.6M | return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]); | 55 | 33.9M | } |
std::__1::shared_ptr<yb::rpc::OutboundMethodMetrics const> yb::rpc::ProxyBase::metrics<6ul>(unsigned long) const Line | Count | Source | 49 | 119k | std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const { | 50 | 119k | if (!metrics_) { | 51 | 0 | return nullptr; | 52 | 0 | } | 53 | 119k | auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get()); | 54 | 119k | return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]); | 55 | 119k | } |
std::__1::shared_ptr<yb::rpc::OutboundMethodMetrics const> yb::rpc::ProxyBase::metrics<14ul>(unsigned long) const Line | Count | Source | 49 | 5.51k | std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const { | 50 | 5.51k | if (!metrics_) { | 51 | 14 | return nullptr; | 52 | 14 | } | 53 | 5.49k | auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get()); | 54 | 5.49k | return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]); | 55 | 5.51k | } |
std::__1::shared_ptr<yb::rpc::OutboundMethodMetrics const> yb::rpc::ProxyBase::metrics<12ul>(unsigned long) const Line | Count | Source | 49 | 27.4M | std::shared_ptr<const OutboundMethodMetrics> metrics(size_t index) const { | 50 | 27.4M | if (!metrics_) { | 51 | 5.08k | return nullptr; | 52 | 5.08k | } | 53 | 27.4M | auto* metrics_impl = static_cast<ProxyMetricsImpl<size>*>(metrics_.get()); | 54 | 27.4M | return std::shared_ptr<const OutboundMethodMetrics>(metrics_, &metrics_impl->value[index]); | 55 | 27.4M | } |
Unexecuted instantiation: std::__1::shared_ptr<yb::rpc::OutboundMethodMetrics const> yb::rpc::ProxyBase::metrics<2ul>(unsigned long) const |
56 | | |
57 | 86.2M | 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 |