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 22 #include <grpc/support/port_platform.h> 23 24 #include <grpc/support/atm.h> 25 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 30 namespace grpc_core { 31 32 class GrpcLbClientStats : public RefCounted<GrpcLbClientStats> { 33 public: 34 struct DropTokenCount { 35 UniquePtr<char> token; 36 int64_t count; 37 DropTokenCountDropTokenCount38 DropTokenCount(UniquePtr<char> token, int64_t count) 39 : token(std::move(token)), count(count) {} 40 }; 41 42 typedef InlinedVector<DropTokenCount, 10> DroppedCallCounts; 43 GrpcLbClientStats()44 GrpcLbClientStats() {} 45 46 void AddCallStarted(); 47 void AddCallFinished(bool finished_with_client_failed_to_send, 48 bool finished_known_received); 49 50 // This method is not thread-safe; caller must synchronize. 51 void AddCallDroppedLocked(char* token); 52 53 // This method is not thread-safe; caller must synchronize. 54 void GetLocked(int64_t* num_calls_started, int64_t* num_calls_finished, 55 int64_t* num_calls_finished_with_client_failed_to_send, 56 int64_t* num_calls_finished_known_received, 57 UniquePtr<DroppedCallCounts>* drop_token_counts); 58 59 private: 60 // This field must only be accessed via *_locked() methods. 61 UniquePtr<DroppedCallCounts> drop_token_counts_; 62 // These fields may be accessed from multiple threads at a time. 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 }; 68 69 } // namespace grpc_core 70 71 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_CLIENT_STATS_H \ 72 */ 73