grpclb_client_stats.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2017 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_CLIENT_STATS_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_CLIENT_STATS_H
21 
23 
24 #include <stdint.h>
25 
26 #include <memory>
27 #include <utility>
28 
29 #include "absl/base/thread_annotations.h"
30 #include "absl/container/inlined_vector.h"
31 
32 #include <grpc/support/atm.h>
33 
37 
38 namespace grpc_core {
39 
40 class GrpcLbClientStats : public RefCounted<GrpcLbClientStats> {
41  public:
42  struct DropTokenCount {
45 
47  : token(std::move(token)), count(count) {}
48  };
49 
51 
52  void AddCallStarted();
53  void AddCallFinished(bool finished_with_client_failed_to_send,
54  bool finished_known_received);
55 
56  void AddCallDropped(const char* token);
57 
61  std::unique_ptr<DroppedCallCounts>* drop_token_counts);
62 
63  // A destruction function to use as the user_data key when attaching
64  // client stats to a grpc_mdelem.
65  static void Destroy(void* arg) {
66  static_cast<GrpcLbClientStats*>(arg)->Unref();
67  }
68 
69  private:
74  Mutex drop_count_mu_; // Guards drop_token_counts_.
75  std::unique_ptr<DroppedCallCounts> drop_token_counts_
77 };
78 
79 } // namespace grpc_core
80 
81 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_CLIENT_STATS_H \
82  */
grpc_core::GrpcLbClientStats::AddCallFinished
void AddCallFinished(bool finished_with_client_failed_to_send, bool finished_known_received)
Definition: grpclb_client_stats.cc:38
grpc_core::GrpcLbClientStats::ABSL_GUARDED_BY
std::unique_ptr< DroppedCallCounts > drop_token_counts_ ABSL_GUARDED_BY(drop_count_mu_)
grpc_core::GrpcLbClientStats::DropTokenCount::count
int64_t count
Definition: grpclb_client_stats.h:44
grpc_core::GrpcLbClientStats
Definition: grpclb_client_stats.h:40
grpc_core::GrpcLbClientStats::AddCallStarted
void AddCallStarted()
Definition: grpclb_client_stats.cc:34
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::GrpcLbClientStats::DropTokenCount::token
UniquePtr< char > token
Definition: grpclb_client_stats.h:43
num_calls_started
size_t num_calls_started
Definition: grpclb_end2end_test.cc:157
num_calls_finished
size_t num_calls_finished
Definition: grpclb_end2end_test.cc:158
grpc_core::GrpcLbClientStats::Get
void Get(int64_t *num_calls_started, int64_t *num_calls_finished, int64_t *num_calls_finished_with_client_failed_to_send, int64_t *num_calls_finished_known_received, std::unique_ptr< DroppedCallCounts > *drop_token_counts)
Definition: grpclb_client_stats.cc:77
memory.h
grpc_core::RefCounted< GrpcLbClientStats >::Unref
void Unref()
Definition: ref_counted.h:302
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
grpc_core::GrpcLbClientStats::AddCallDropped
void AddCallDropped(const char *token)
Definition: grpclb_client_stats.cc:50
grpc_core::GrpcLbClientStats::num_calls_started_
gpr_atm num_calls_started_
Definition: grpclb_client_stats.h:70
grpc_core::GrpcLbClientStats::num_calls_finished_known_received_
gpr_atm num_calls_finished_known_received_
Definition: grpclb_client_stats.h:73
arg
Definition: cmdline.cc:40
grpc_core::GrpcLbClientStats::drop_count_mu_
Mutex drop_count_mu_
Definition: grpclb_client_stats.h:74
grpc_core::RefCounted
Definition: ref_counted.h:280
grpc_core::UniquePtr
std::unique_ptr< T, DefaultDeleteChar > UniquePtr
Definition: src/core/lib/gprpp/memory.h:43
grpc_core::GrpcLbClientStats::Destroy
static void Destroy(void *arg)
Definition: grpclb_client_stats.h:65
stdint.h
grpc_core::GrpcLbClientStats::DropTokenCount
Definition: grpclb_client_stats.h:42
gpr_atm
intptr_t gpr_atm
Definition: impl/codegen/atm_gcc_atomic.h:32
grpc_core::Mutex
Definition: src/core/lib/gprpp/sync.h:61
grpc_core::GrpcLbClientStats::num_calls_finished_
gpr_atm num_calls_finished_
Definition: grpclb_client_stats.h:71
grpc_core::GrpcLbClientStats::num_calls_finished_with_client_failed_to_send_
gpr_atm num_calls_finished_with_client_failed_to_send_
Definition: grpclb_client_stats.h:72
ref_counted.h
num_calls_finished_known_received
size_t num_calls_finished_known_received
Definition: grpclb_end2end_test.cc:160
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
grpc_core::GrpcLbClientStats::DropTokenCount::DropTokenCount
DropTokenCount(UniquePtr< char > token, int64_t count)
Definition: grpclb_client_stats.h:46
arg
struct arg arg
grpc_core::GrpcLbClientStats::DroppedCallCounts
absl::InlinedVector< DropTokenCount, 10 > DroppedCallCounts
Definition: grpclb_client_stats.h:50
drop_token_counts
std::map< std::string, size_t > drop_token_counts
Definition: grpclb_end2end_test.cc:161
atm.h
absl::InlinedVector
Definition: abseil-cpp/absl/container/inlined_vector.h:69
num_calls_finished_with_client_failed_to_send
size_t num_calls_finished_with_client_failed_to_send
Definition: grpclb_end2end_test.cc:159
sync.h
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:45