stacktrace_benchmark.cc
Go to the documentation of this file.
1 // Copyright 2022 The Abseil 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 // https://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 "absl/base/attributes.h"
16 #include "absl/base/config.h"
17 #include "absl/base/optimization.h"
18 #include "absl/debugging/stacktrace.h"
19 #include "benchmark/benchmark.h"
20 
21 namespace absl {
23 namespace {
24 
25 static constexpr int kMaxStackDepth = 100;
26 static constexpr int kCacheSize = (1 << 16);
28 
30  if (x <= 0) {
31  // Touch a significant amount of memory so that the stack is likely to be
32  // not cached in the L1 cache.
33  state.PauseTiming();
34  int* arr = new int[kCacheSize];
35  for (int i = 0; i < kCacheSize; ++i) benchmark::DoNotOptimize(arr[i] = 100);
36  delete[] arr;
37  state.ResumeTiming();
39  return;
40  }
42  func(state, --x, depth);
43 }
44 
46  int depth = state.range(0);
47  for (auto s : state) {
48  func(state, depth, depth);
49  }
50 }
51 
52 BENCHMARK(BM_GetStackTrace)->DenseRange(10, kMaxStackDepth, 10);
53 } // namespace
55 } // namespace absl
absl::GetStackTrace
ABSL_ATTRIBUTE_NOINLINE ABSL_ATTRIBUTE_NO_TAIL_CALL int GetStackTrace(void **result, int max_depth, int skip_count)
Definition: abseil-cpp/absl/debugging/stacktrace.cc:101
absl::ABSL_NAMESPACE_BEGIN::kCacheSize
static constexpr int kCacheSize
Definition: stacktrace_benchmark.cc:26
benchmark::DoNotOptimize
BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const &value)
Definition: benchmark/include/benchmark/benchmark.h:375
absl::FormatConversionChar::s
@ s
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
ABSL_ATTRIBUTE_NOINLINE
#define ABSL_ATTRIBUTE_NOINLINE
Definition: abseil-cpp/absl/base/attributes.h:112
absl::ABSL_NAMESPACE_BEGIN::BM_GetStackTrace
void BM_GetStackTrace(benchmark::State &state)
Definition: stacktrace_benchmark.cc:45
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
absl::ABSL_NAMESPACE_BEGIN::pcs
void * pcs[kMaxStackDepth]
Definition: stacktrace_benchmark.cc:27
ABSL_BLOCK_TAIL_CALL_OPTIMIZATION
#define ABSL_BLOCK_TAIL_CALL_OPTIMIZATION()
Definition: abseil-cpp/absl/base/optimization.h:55
func
const EVP_CIPHER *(* func)(void)
Definition: cipher_extra.c:73
benchmark::State
Definition: benchmark/include/benchmark/benchmark.h:503
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
absl::ABSL_NAMESPACE_BEGIN::kMaxStackDepth
static constexpr int kMaxStackDepth
Definition: stacktrace_benchmark.cc:25
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
absl::ABSL_NAMESPACE_BEGIN::BENCHMARK
BENCHMARK(BM_GetStackTrace) -> DenseRange(10, kMaxStackDepth, 10)
mkowners.depth
depth
Definition: mkowners.py:114
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:22