helpers.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 
21 #include <string.h>
22 
25 
27  GPR_ASSERT(g_libraryInitializer == nullptr);
28  g_libraryInitializer = this;
29 
31  init_lib_.init();
32 }
33 
35  g_libraryInitializer = nullptr;
37 }
38 
40  GPR_ASSERT(g_libraryInitializer != nullptr);
41  return *g_libraryInitializer;
42 }
43 
45  std::ostringstream out;
46  for (const auto& l : labels_) {
47  out << l << ' ';
48  }
50  std::string label = out.str();
51  if (label.length() && label[0] == ' ') {
52  label = label.substr(1);
53  }
54  state.SetLabel(label.c_str());
55 }
56 
58  labels_.push_back(label);
59 }
60 
62  // Use the parameters to avoid unused-parameter warnings depending on the
63  // #define's present
64  (void)out;
65  (void)state;
66 #ifdef GRPC_COLLECT_STATS
67  grpc_stats_data stats_end;
68  grpc_stats_collect(&stats_end);
70  grpc_stats_diff(&stats_end, &stats_begin_, &stats);
71  for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) {
72  out << " " << grpc_stats_counter_name[i] << "/iter:"
73  << (static_cast<double>(stats.counters[i]) /
74  static_cast<double>(state.iterations()));
75  }
76  for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) {
77  out << " " << grpc_stats_histogram_name[i] << "-median:"
79  << " " << grpc_stats_histogram_name[i] << "-99p:"
81  }
82 #endif
83 #ifdef GPR_LOW_LEVEL_COUNTERS
84  out << " locks/iter:"
85  << ((double)(gpr_atm_no_barrier_load(&gpr_mu_locks) -
86  mu_locks_at_start_) /
87  (double)state.iterations())
88  << " atm_cas/iter:"
89  << ((double)(gpr_atm_no_barrier_load(&gpr_counter_atm_cas) -
90  atm_cas_at_start_) /
91  (double)state.iterations())
92  << " atm_add/iter:"
93  << ((double)(gpr_atm_no_barrier_load(&gpr_counter_atm_add) -
94  atm_add_at_start_) /
95  (double)state.iterations())
96  << " nows/iter:"
97  << ((double)(gpr_atm_no_barrier_load(&gpr_now_call_count) -
98  now_calls_at_start_) /
99  (double)state.iterations());
100 #endif
101 }
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
gpr_atm_no_barrier_load
#define gpr_atm_no_barrier_load(p)
Definition: impl/codegen/atm_gcc_atomic.h:53
grpc::internal::GrpcLibraryInitializer::summon
int summon()
Definition: grpcpp/impl/grpc_library.h:54
GRPC_STATS_HISTOGRAM_COUNT
@ GRPC_STATS_HISTOGRAM_COUNT
Definition: stats_data.h:142
string.h
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
TrackCounters::Finish
virtual void Finish(benchmark::State &state)
Definition: helpers.cc:44
grpc_stats_counter_name
const char * grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT]
Definition: stats_data.cc:30
TrackCounters::labels_
std::vector< std::string > labels_
Definition: helpers.h:61
g_libraryInitializer
static LibraryInitializer * g_libraryInitializer
Definition: helpers.cc:24
grpc::internal::GrpcLibraryInitializer
Instantiating this class ensures the proper initialization of gRPC.
Definition: grpcpp/impl/grpc_library.h:39
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
gen_synthetic_protos.label
label
Definition: gen_synthetic_protos.py:102
LibraryInitializer::~LibraryInitializer
~LibraryInitializer()
Definition: helpers.cc:34
gen_stats_data.stats
list stats
Definition: gen_stats_data.py:58
g_gli_initializer
static grpc::internal::GrpcLibraryInitializer g_gli_initializer
Definition: helpers.cc:23
TrackCounters::stats_begin_
grpc_stats_data stats_begin_
Definition: helpers.h:60
grpc_stats_collect
void grpc_stats_collect(grpc_stats_data *output)
Definition: stats.cc:48
helpers.h
grpc_stats_histogram_name
const char * grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT]
Definition: stats_data.cc:254
LibraryInitializer::LibraryInitializer
LibraryInitializer()
Definition: helpers.cc:26
LibraryInitializer
Definition: helpers.h:33
TrackCounters::AddLabel
virtual void AddLabel(const std::string &label)
Definition: helpers.cc:57
benchmark::State
Definition: benchmark/include/benchmark/benchmark.h:503
grpc_stats_data
Definition: src/core/lib/debug/stats.h:33
grpc_stats_histograms
grpc_stats_histograms
Definition: stats_data.h:128
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
grpc_stats_histo_percentile
double grpc_stats_histo_percentile(const grpc_stats_data *stats, grpc_stats_histograms histogram, double percentile)
Definition: stats.cc:136
grpc::internal::GrpcLibrary::init
void init() override
Definition: grpcpp/impl/grpc_library.h:34
grpc::internal::GrpcLibrary::shutdown
void shutdown() override
Definition: grpcpp/impl/grpc_library.h:35
grpc_stats_diff
void grpc_stats_diff(const grpc_stats_data *b, const grpc_stats_data *a, grpc_stats_data *c)
Definition: stats.cc:62
LibraryInitializer::init_lib_
grpc::internal::GrpcLibrary init_lib_
Definition: helpers.h:41
GRPC_STATS_COUNTER_COUNT
@ GRPC_STATS_COUNTER_COUNT
Definition: stats_data.h:124
LibraryInitializer::get
static LibraryInitializer & get()
Definition: helpers.cc:39
run_grpclb_interop_tests.l
dictionary l
Definition: run_grpclb_interop_tests.py:410
TrackCounters::AddToLabel
virtual void AddToLabel(std::ostream &out, benchmark::State &state)
Definition: helpers.cc:61
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:12