bm_arena.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 arenas */
20 
21 #include <benchmark/benchmark.h>
22 
28 
29 using grpc_core::Arena;
30 
32  grpc_core::ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator(
33  "test"));
34 
36  for (auto _ : state) {
37  Arena::Create(state.range(0), g_memory_allocator)->Destroy();
38  }
39 }
40 BENCHMARK(BM_Arena_NoOp)->Range(1, 1024 * 1024);
41 
43  Arena* a = Arena::Create(state.range(0), g_memory_allocator);
44  const size_t realloc_after =
45  1024 * 1024 * 1024 / ((state.range(1) + 15) & 0xffffff0u);
46  while (state.KeepRunning()) {
47  a->Alloc(state.range(1));
48  // periodically recreate arena to avoid OOM
49  if (state.iterations() % realloc_after == 0) {
50  a->Destroy();
51  a = Arena::Create(state.range(0), g_memory_allocator);
52  }
53  }
54  a->Destroy();
55 }
56 BENCHMARK(BM_Arena_ManyAlloc)->Ranges({{1, 1024 * 1024}, {1, 32 * 1024}});
57 
59  for (auto _ : state) {
60  Arena* a = Arena::Create(state.range(0), g_memory_allocator);
61  for (int i = 0; i < state.range(1); i++) {
62  a->Alloc(state.range(2));
63  }
64  a->Destroy();
65  }
66 }
67 BENCHMARK(BM_Arena_Batch)->Ranges({{1, 64 * 1024}, {1, 64}, {1, 1024}});
68 
69 // Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
70 // and others do not. This allows us to support both modes.
71 namespace benchmark {
73 } // namespace benchmark
74 
75 int main(int argc, char** argv) {
77  ::benchmark::Initialize(&argc, argv);
78  grpc::testing::InitTest(&argc, &argv, false);
80  return 0;
81 }
grpc::testing::InitTest
void InitTest(int *argc, char ***argv, bool remove_flags)
Definition: test_config_cc.cc:28
Arena
struct Arena Arena
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/arena.h:189
benchmark
Definition: bm_alarm.cc:55
generate.env
env
Definition: generate.py:37
grpc_event_engine::experimental::MemoryAllocator
Definition: memory_allocator.h:35
arena.h
benchmark::RunTheBenchmarksNamespaced
void RunTheBenchmarksNamespaced()
Definition: bm_alarm.cc:56
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
grpc_core::Arena
Definition: src/core/lib/resource_quota/arena.h:45
BENCHMARK
BENCHMARK(BM_Arena_NoOp) -> Range(1, 1024 *1024)
benchmark::RunSpecifiedBenchmarks
size_t RunSpecifiedBenchmarks()
Definition: benchmark/src/benchmark.cc:437
main
int main(int argc, char **argv)
Definition: bm_arena.cc:75
gmock_output_test._
_
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
grpc_core::ResourceQuota::Default
static ResourceQuotaRefPtr Default()
Definition: resource_quota.cc:27
benchmark::Initialize
void Initialize(int *argc, char **argv)
Definition: benchmark/src/benchmark.cc:602
helpers.h
g_memory_allocator
static auto * g_memory_allocator
Definition: bm_arena.cc:31
resource_quota.h
test_config.h
BM_Arena_Batch
static void BM_Arena_Batch(benchmark::State &state)
Definition: bm_arena.cc:58
BM_Arena_ManyAlloc
static void BM_Arena_ManyAlloc(benchmark::State &state)
Definition: bm_arena.cc:42
benchmark::State
Definition: benchmark/include/benchmark/benchmark.h:503
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
test_config.h
BM_Arena_NoOp
static void BM_Arena_NoOp(benchmark::State &state)
Definition: bm_arena.cc:35
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


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