3 * Copyright 2017 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
22 #include <grpc/support/port_platform.h>
24 #include <grpc/support/atm.h>
26 #include "src/core/lib/gprpp/inlined_vector.h"
27 #include "src/core/lib/gprpp/memory.h"
28 #include "src/core/lib/gprpp/ref_counted.h"
29 #include "src/core/lib/gprpp/sync.h"
33 class GrpcLbClientStats : public RefCounted<GrpcLbClientStats> {
35 struct DropTokenCount {
36 UniquePtr<char> token;
39 DropTokenCount(UniquePtr<char> token, int64_t count)
40 : token(std::move(token)), count(count) {}
43 typedef InlinedVector<DropTokenCount, 10> DroppedCallCounts;
45 void AddCallStarted();
46 void AddCallFinished(bool finished_with_client_failed_to_send,
47 bool finished_known_received);
49 void AddCallDropped(const char* token);
51 void Get(int64_t* num_calls_started, int64_t* num_calls_finished,
52 int64_t* num_calls_finished_with_client_failed_to_send,
53 int64_t* num_calls_finished_known_received,
54 UniquePtr<DroppedCallCounts>* drop_token_counts);
56 // A destruction function to use as the user_data key when attaching
57 // client stats to a grpc_mdelem.
58 static void Destroy(void* arg) {
59 static_cast<GrpcLbClientStats*>(arg)->Unref();
63 gpr_atm num_calls_started_ = 0;
64 gpr_atm num_calls_finished_ = 0;
65 gpr_atm num_calls_finished_with_client_failed_to_send_ = 0;
66 gpr_atm num_calls_finished_known_received_ = 0;
67 Mutex drop_count_mu_; // Guards drop_token_counts_.
68 UniquePtr<DroppedCallCounts> drop_token_counts_;
71 } // namespace grpc_core
73 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_CLIENT_STATS_H \