• 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 "src/core/lib/event_engine/default_event_engine.h"
19 #include "src/core/lib/promise/party.h"
20 #include "src/core/lib/resource_quota/arena.h"
21 
22 namespace grpc_core {
23 namespace {
24 
BM_PartyCreate(benchmark::State & state)25 void BM_PartyCreate(benchmark::State& state) {
26   auto arena = SimpleArenaAllocator()->MakeArena();
27   arena->SetContext(
28       grpc_event_engine::experimental::GetDefaultEventEngine().get());
29   for (auto _ : state) {
30     Party::Make(arena);
31   }
32 }
33 BENCHMARK(BM_PartyCreate);
34 
BM_AddParticipant(benchmark::State & state)35 void BM_AddParticipant(benchmark::State& state) {
36   auto arena = SimpleArenaAllocator()->MakeArena();
37   arena->SetContext(
38       grpc_event_engine::experimental::GetDefaultEventEngine().get());
39   auto party = Party::Make(arena);
40   for (auto _ : state) {
41     party->Spawn("participant", []() { return Success{}; }, [](StatusFlag) {});
42   }
43 }
44 BENCHMARK(BM_AddParticipant);
45 
BM_WakeupParticipant(benchmark::State & state)46 void BM_WakeupParticipant(benchmark::State& state) {
47   auto arena = SimpleArenaAllocator()->MakeArena();
48   arena->SetContext(
49       grpc_event_engine::experimental::GetDefaultEventEngine().get());
50   auto party = Party::Make(arena);
51   party->Spawn(
52       "driver",
53       [&state, w = IntraActivityWaiter()]() mutable -> Poll<StatusFlag> {
54         w.pending();
55         if (state.KeepRunning()) {
56           w.Wake();
57           return Pending{};
58         }
59         return Success{};
60       },
61       [party](StatusFlag) {});
62 }
63 BENCHMARK(BM_WakeupParticipant);
64 
65 }  // namespace
66 }  // namespace grpc_core
67 
68 // Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
69 // and others do not. This allows us to support both modes.
70 namespace benchmark {
RunTheBenchmarksNamespaced()71 void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
72 }  // namespace benchmark
73 
main(int argc,char ** argv)74 int main(int argc, char** argv) {
75   ::benchmark::Initialize(&argc, argv);
76   grpc_init();
77   {
78     auto ee = grpc_event_engine::experimental::GetDefaultEventEngine();
79     benchmark::RunTheBenchmarksNamespaced();
80   }
81   grpc_shutdown();
82   return 0;
83 }
84