• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <benchmark/benchmark.h>
16 #include <grpc/grpc.h>
17 
18 #include <memory>
19 
20 #include "absl/memory/memory.h"
21 #include "absl/strings/string_view.h"
22 #include "src/core/ext/transport/inproc/inproc_transport.h"
23 #include "src/core/lib/address_utils/parse_address.h"
24 #include "test/core/transport/call_spine_benchmarks.h"
25 
26 namespace grpc_core {
27 namespace {
28 
29 const Slice kTestPath = Slice::FromExternalString("/foo/bar");
30 
31 class InprocTraits {
32  public:
MakeTransport()33   BenchmarkTransport MakeTransport() {
34     auto channel_args = CoreConfiguration::Get()
35                             .channel_args_preconditioning()
36                             .PreconditionChannelArgs(nullptr);
37     auto t = MakeInProcessTransportPair(channel_args);
38     return {OrphanablePtr<ClientTransport>(
39                 DownCast<ClientTransport*>(t.first.release())),
40             OrphanablePtr<ServerTransport>(
41                 DownCast<ServerTransport*>(t.second.release()))};
42   }
43 
MakeClientInitialMetadata()44   ClientMetadataHandle MakeClientInitialMetadata() {
45     auto md = Arena::MakePooledForOverwrite<ClientMetadata>();
46     md->Set(HttpPathMetadata(), kTestPath.Copy());
47     return md;
48   }
49 
MakeServerInitialMetadata()50   ServerMetadataHandle MakeServerInitialMetadata() {
51     return Arena::MakePooledForOverwrite<ServerMetadata>();
52   }
53 
MakePayload()54   MessageHandle MakePayload() { return Arena::MakePooled<Message>(); }
55 
MakeServerTrailingMetadata()56   ServerMetadataHandle MakeServerTrailingMetadata() {
57     auto md = Arena::MakePooledForOverwrite<ServerMetadata>();
58     return md;
59   }
60 };
61 GRPC_CALL_SPINE_BENCHMARK(TransportFixture<InprocTraits>);
62 
63 }  // namespace
64 }  // namespace grpc_core
65 
66 // Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
67 // and others do not. This allows us to support both modes.
68 namespace benchmark {
RunTheBenchmarksNamespaced()69 void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
70 }  // namespace benchmark
71 
main(int argc,char ** argv)72 int main(int argc, char** argv) {
73   ::benchmark::Initialize(&argc, argv);
74   grpc_init();
75   {
76     auto ee = grpc_event_engine::experimental::GetDefaultEventEngine();
77     benchmark::RunTheBenchmarksNamespaced();
78   }
79   grpc_shutdown();
80   return 0;
81 }
82