grpclb_client_stats.cc
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 
20 
22 
23 #include <string.h>
24 
25 #include "absl/memory/memory.h"
26 
27 #include <grpc/support/atm.h>
29 
31 
32 namespace grpc_core {
33 
36 }
37 
39  bool finished_with_client_failed_to_send, bool finished_known_received) {
41  if (finished_with_client_failed_to_send) {
43  (gpr_atm)1);
44  }
45  if (finished_known_received) {
47  }
48 }
49 
50 void GrpcLbClientStats::AddCallDropped(const char* token) {
51  // Increment num_calls_started and num_calls_finished.
54  // Record the drop.
56  if (drop_token_counts_ == nullptr) {
57  drop_token_counts_ = absl::make_unique<DroppedCallCounts>();
58  }
59  for (size_t i = 0; i < drop_token_counts_->size(); ++i) {
60  if (strcmp((*drop_token_counts_)[i].token.get(), token) == 0) {
61  ++(*drop_token_counts_)[i].count;
62  return;
63  }
64  }
65  // Not found, so add a new entry.
66  drop_token_counts_->emplace_back(UniquePtr<char>(gpr_strdup(token)), 1);
67 }
68 
69 namespace {
70 
71 void AtomicGetAndResetCounter(int64_t* value, gpr_atm* counter) {
72  *value = static_cast<int64_t>(gpr_atm_full_xchg(counter, (gpr_atm)0));
73 }
74 
75 } // namespace
76 
81  std::unique_ptr<DroppedCallCounts>* drop_token_counts) {
82  AtomicGetAndResetCounter(num_calls_started, &num_calls_started_);
83  AtomicGetAndResetCounter(num_calls_finished, &num_calls_finished_);
84  AtomicGetAndResetCounter(num_calls_finished_with_client_failed_to_send,
86  AtomicGetAndResetCounter(num_calls_finished_known_received,
89  *drop_token_counts = std::move(drop_token_counts_);
90 }
91 
92 } // namespace grpc_core
grpc_core::GrpcLbClientStats::AddCallFinished
void AddCallFinished(bool finished_with_client_failed_to_send, bool finished_known_received)
Definition: grpclb_client_stats.cc:38
gpr_atm_full_fetch_add
#define gpr_atm_full_fetch_add(p, delta)
Definition: impl/codegen/atm_gcc_atomic.h:62
grpc_core::GrpcLbClientStats::AddCallStarted
void AddCallStarted()
Definition: grpclb_client_stats.cc:34
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::MutexLock
Definition: src/core/lib/gprpp/sync.h:88
string.h
num_calls_started
size_t num_calls_started
Definition: grpclb_end2end_test.cc:157
gpr_atm_full_xchg
#define gpr_atm_full_xchg(p, n)
Definition: impl/codegen/atm_gcc_atomic.h:86
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
string_util.h
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
counter
static int counter
Definition: abseil-cpp/absl/flags/reflection_test.cc:131
grpc_core::GrpcLbClientStats::drop_count_mu_
Mutex drop_count_mu_
Definition: grpclb_client_stats.h:74
grpc_core::UniquePtr
std::unique_ptr< T, DefaultDeleteChar > UniquePtr
Definition: src/core/lib/gprpp/memory.h:43
grpclb_client_stats.h
value
const char * value
Definition: hpack_parser_table.cc:165
gpr_atm
intptr_t gpr_atm
Definition: impl/codegen/atm_gcc_atomic.h:32
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
num_calls_finished_known_received
size_t num_calls_finished_known_received
Definition: grpclb_end2end_test.cc:160
drop_token_counts
std::map< std::string, size_t > drop_token_counts
Definition: grpclb_end2end_test.cc:161
gpr_strdup
GPRAPI char * gpr_strdup(const char *src)
Definition: string.cc:39
atm.h
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
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
port_platform.h


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