GRPC Core  18.0.0
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 <grpc/support/atm.h>
25 
26 #include "absl/container/inlined_vector.h"
27 
31 
32 namespace grpc_core {
33 
34 class GrpcLbClientStats : public RefCounted<GrpcLbClientStats> {
35  public:
36  struct DropTokenCount {
38  int64_t count;
39 
41  : token(std::move(token)), count(count) {}
42  };
43 
44  typedef absl::InlinedVector<DropTokenCount, 10> DroppedCallCounts;
45 
46  void AddCallStarted();
47  void AddCallFinished(bool finished_with_client_failed_to_send,
48  bool finished_known_received);
49 
50  void AddCallDropped(const char* token);
51 
52  void Get(int64_t* num_calls_started, int64_t* num_calls_finished,
53  int64_t* num_calls_finished_with_client_failed_to_send,
54  int64_t* num_calls_finished_known_received,
55  std::unique_ptr<DroppedCallCounts>* drop_token_counts);
56 
57  // A destruction function to use as the user_data key when attaching
58  // client stats to a grpc_mdelem.
59  static void Destroy(void* arg) {
60  static_cast<GrpcLbClientStats*>(arg)->Unref();
61  }
62 
63  private:
64  gpr_atm num_calls_started_ = 0;
65  gpr_atm num_calls_finished_ = 0;
66  gpr_atm num_calls_finished_with_client_failed_to_send_ = 0;
67  gpr_atm num_calls_finished_known_received_ = 0;
68  Mutex drop_count_mu_; // Guards drop_token_counts_.
69  std::unique_ptr<DroppedCallCounts> drop_token_counts_
70  ABSL_GUARDED_BY(drop_count_mu_);
71 };
72 
73 } // namespace grpc_core
74 
75 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_CLIENT_STATS_H \
76  */
Definition: grpclb_client_stats.h:34
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:78
void AddCallStarted()
Definition: grpclb_client_stats.cc:34
absl::InlinedVector< DropTokenCount, 10 > DroppedCallCounts
Definition: grpclb_client_stats.h:44
static void Destroy(void *arg)
Definition: grpclb_client_stats.h:59
void AddCallDropped(const char *token)
Definition: grpclb_client_stats.cc:50
void AddCallFinished(bool finished_with_client_failed_to_send, bool finished_known_received)
Definition: grpclb_client_stats.cc:38
Definition: sync.h:59
Definition: ref_counted.h:282
void Unref()
Definition: ref_counted.h:302
intptr_t gpr_atm
Definition: atm_gcc_atomic.h:30
Round Robin Policy.
Definition: backend_metric.cc:26
std::unique_ptr< T, DefaultDeleteChar > UniquePtr
Definition: memory.h:47
Definition: grpclb_client_stats.h:36
int64_t count
Definition: grpclb_client_stats.h:38
grpc_core::UniquePtr< char > token
Definition: grpclb_client_stats.h:37
DropTokenCount(grpc_core::UniquePtr< char > token, int64_t count)
Definition: grpclb_client_stats.h:40