bm_channel.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 
19 /* Benchmark channel */
20 
21 #include <benchmark/benchmark.h>
22 
23 #include <grpc/grpc.h>
24 #include <grpc/grpc_security.h>
25 
29 
31  public:
34  if (channel_) {
36  }
37  }
38  virtual void Init() = 0;
39 
40  protected:
41  grpc_channel* channel_ = nullptr;
42 };
43 
45  public:
47  void Init() override {
49  channel_ = grpc_channel_create("localhost:1234", creds, nullptr);
51  }
52 };
53 
55  public:
57  void Init() override {
59  "localhost:1234", GRPC_STATUS_UNAUTHENTICATED, "blah");
60  }
61 };
62 
63 template <class Fixture>
65  // In order to test if channel creation time is affected by the number of
66  // already existing channels, we create some initial channels here.
67  Fixture initial_channels[512];
68  for (int i = 0; i < state.range(0); i++) {
69  initial_channels[i].Init();
70  }
71  for (auto _ : state) {
73  channel.Init();
74  }
75 }
77  ->Range(0, 512);
78 ;
80  ->Range(0, 512);
81 ;
82 
83 // Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
84 // and others do not. This allows us to support both modes.
85 namespace benchmark {
87 } // namespace benchmark
88 
89 int main(int argc, char** argv) {
91  LibraryInitializer libInit;
92  ::benchmark::Initialize(&argc, argv);
93  grpc::testing::InitTest(&argc, &argv, false);
95  return 0;
96 }
grpc::testing::InitTest
void InitTest(int *argc, char ***argv, bool remove_flags)
Definition: test_config_cc.cc:28
Fixture
Definition: bm_call_create.cc:359
benchmark
Definition: bm_alarm.cc:55
generate.env
env
Definition: generate.py:37
GRPC_STATUS_UNAUTHENTICATED
@ GRPC_STATUS_UNAUTHENTICATED
Definition: include/grpc/impl/codegen/status.h:72
grpc_lame_client_channel_create
GRPCAPI grpc_channel * grpc_lame_client_channel_create(const char *target, grpc_status_code error_code, const char *error_message)
Definition: lame_client.cc:131
LameChannelFixture::Init
void Init() override
Definition: bm_channel.cc:57
benchmark::RunTheBenchmarksNamespaced
void RunTheBenchmarksNamespaced()
Definition: bm_alarm.cc:56
grpc_security.h
benchmark::RunSpecifiedBenchmarks
size_t RunSpecifiedBenchmarks()
Definition: benchmark/src/benchmark.cc:437
LameChannelFixture
Definition: bm_channel.cc:54
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
InsecureChannelFixture::Init
void Init() override
Definition: bm_channel.cc:47
BENCHMARK_TEMPLATE
#define BENCHMARK_TEMPLATE(n, a)
Definition: benchmark/include/benchmark/benchmark.h:1231
grpc.h
gmock_output_test._
_
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
grpc_insecure_credentials_create
GRPCAPI grpc_channel_credentials * grpc_insecure_credentials_create()
Definition: core/lib/security/credentials/insecure/insecure_credentials.cc:64
benchmark::Initialize
void Initialize(int *argc, char **argv)
Definition: benchmark/src/benchmark.cc:602
BM_InsecureChannelCreateDestroy
static void BM_InsecureChannelCreateDestroy(benchmark::State &state)
Definition: bm_channel.cc:64
helpers.h
InsecureChannelFixture::InsecureChannelFixture
InsecureChannelFixture()
Definition: bm_channel.cc:46
ChannelDestroyerFixture
Definition: bm_channel.cc:30
ChannelDestroyerFixture::~ChannelDestroyerFixture
virtual ~ChannelDestroyerFixture()
Definition: bm_channel.cc:33
LibraryInitializer
Definition: helpers.h:33
ChannelDestroyerFixture::ChannelDestroyerFixture
ChannelDestroyerFixture()
Definition: bm_channel.cc:32
test_config.h
grpc_channel_credentials_release
GRPCAPI void grpc_channel_credentials_release(grpc_channel_credentials *creds)
Definition: credentials.cc:36
grpc_channel_create
GRPCAPI grpc_channel * grpc_channel_create(const char *target, grpc_channel_credentials *creds, const grpc_channel_args *args)
Definition: chttp2_connector.cc:366
benchmark::State
Definition: benchmark/include/benchmark/benchmark.h:503
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
grpc_channel_destroy
GRPCAPI void grpc_channel_destroy(grpc_channel *channel)
Definition: channel.cc:437
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
test_config.h
grpc_channel
struct grpc_channel grpc_channel
Definition: grpc_types.h:62
ChannelDestroyerFixture::channel_
grpc_channel * channel_
Definition: bm_channel.cc:41
ChannelDestroyerFixture::Init
virtual void Init()=0
LameChannelFixture::LameChannelFixture
LameChannelFixture()
Definition: bm_channel.cc:56
InsecureChannelFixture
Definition: bm_channel.cc:44
grpc_channel_credentials
Definition: src/core/lib/security/credentials/credentials.h:96
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
main
int main(int argc, char **argv)
Definition: bm_channel.cc:89


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:48