Change the static std::mt19937 and std::uniform_int_distribution to thread_local in the do_work helper function to prevent data races when the benchmark is run with multiple threads.
Resolves ubsan/test failure
RunMemoryManager() opened the MemoryManager window before allocating the
ThreadManager and running the per-benchmark Setup(), and closed it after
Teardown(). Everything the library and the fixture allocate around the
benchmark was therefore attributed to the benchmark itself, so an exact
allocation count was impossible to obtain.
Move Start()/Stop() to bracket only RunInThread(), which is the same region
the timers cover. Setup()/Teardown() already run outside the timed region, so
this makes the memory window consistent with the time window.
Add memory_manager_ordering_gtest, which registers a MemoryManager that
records whether the window is open and asserts the fixture callbacks never
observe it as open. It fails on the previous ordering ("Teardown ran inside
the MemoryManager Start/Stop window") and passes with this change.
* Make --benchmark_list_tests respect --benchmark_format via reporter List() (#1642)
* Export FindBenchmarksInternal for shared-library test link; fix include order
* add Rust bindings
* clang-format
* pre-commit fix
* windows static builds
* Rust prefers MD on windows
* check in lock file to avoid source poisoning
* use a rust crate name that isn't taken
* add CMake target for running Rust binding tests and integrate into CI
* complete crate rename
* enable test dependency downloads in Rust bindings CI
* Add myself to AUTHORS and CONTRIBUTORS
* Improve accuracy of locale support check
It's much easier to list the two platforms libstdc++ does support
locale manipulation on than to try to exhaustively list the myriad
platforms where it does not.
* fix: cast size_t widths to int for variadic printer to avoid Windows x64 crashes
* extend minimum time as Windows can have a coarse timer
* vsnprintf can consume va_list so we need to copy it to avoid UB
* extend longer test runtime to other problematic tests
* Add BENCHMARK_NAMED macro for named benchmarks without lambda
Closes#2128. BENCHMARK_CAPTURE creates a lambda even when no arguments
are captured, causing compiler/linker scalability issues with thousands
of benchmarks. BENCHMARK_NAMED provides the same func/name format but
passes the function pointer directly (no lambda), consistent with the
existing BENCHMARK macro.
* Move BENCHMARK_NAMED test to register_benchmark_test with name assertions
* Add Benjamin King to AUTHORS and CONTRIBUTORS
* Fix clang-format: remove trailing spaces from BENCHMARK_NAMED macro
* Fix clang-format: remove extra blank line left after test removal
---------
Co-authored-by: Roman Lebedev <lebedev.ri@gmail.com>
On systems with more than one PMU for the CPUs (e.g. Apple M series SOCs),
generic hardware events are only created for an arbitrary PMU. Usually
this is the big cluster's PMU, which can cause inaccuracies when the
process is scheduled onto a little core. To fix this, teach PerfCounters
to register generic hardware events on all CPU PMUs.
CPU PMUs are identified using the same method as perf.
* Fix warnings from Clang
This patch addresses a few issues:
- Wformat-nonliteral from colour printing functions
- Wmissing-prototypes from a few internal functions
Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
* Wrap tests in anonymous namespaces
Technically tests should be using internal linkage.
Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
---------
Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
* Adding explicit cast to aid in template argument deduction.
The `BENCHMARK(my_func)` macro needs to register the function my_func
so the library can run it. It uses `std::make_unique` to create an
object that stores metadata about the benchmark, including its name
("my_func") and a pointer to the function itself (my_func).
The specific constructor being called via `std::make_unique` is for
`benchmark::internal::FunctionBenchmark`.
When a benchmark function name is overloaded, the compiler can't
determine which function is being referred to until the call is made
with specific arguments, or enough context is provided.
The addition of a `static_cast` to the expected `Function*` type
resolves any ambiguity as the compiler is forced to pick the one with
the matching signature.
* clang-format
* add a test
* clang-format again
While ASLR is a useful security hardening feature,
it introduces unreproducible noise into benchmarks,
and we really really really don't want any noise,
especially easily avoidable one.
Unless prevented by some other security hardening,
we can disable ASLR for the current process,
and restart it, thus eliminating this noise.
Fixes https://github.com/google/benchmark/issues/461
* `CMakeLists.txt`: drop hopefully obsolete code
* README.md: update
* Unbreak `BENCHMARK_HAS_CXX11` macro
835365f99a stopped defining it,
but didn't un-conditionalize the code guarded under it...
* Drop `BENCHMARK_HAS_NO_VARIADIC_REGISTER_BENCHMARK`
We no longer support such an old gcc version
* `docs/user_guide.md`: proofread
* Add a test to ensure that `benchmark.h` remains C++14 header
* Revert `[[maybe_unused]]` changes - it requires C++17
* Also support C++11 standard for using the library
I don't think we want to support C++03 though,
but i suppose C++11 is palatable, at least right now.
* fix memory manager result bug
* change is_valid to memory_iterations
* fix test
* some fixes
* fix test
...for msvc
* fix test
* fix test
add the correct explicitly casts
* fix msvc failure
* some fixes
* remove unnecessary include
* [clang-tidy] fix warning about decaying array to pointer
* fix a different warning (old style cast)
* use string_view instead of old-style const char* strings
* ensure bazel windows is using c++17
* learn to use bazel
* and tests
* precommit fix
* more string_view creation and casting
* format
* format
* [clang-tidy] use unique_ptr for benchmark registration (#1927)
* use unique_ptr for benchmark registration
* remove cxx03 test, fully unblocking c++1X development
* remove unnecessary macros
* pre-commit
* remove opt-in analyzer warnings from clang-tidy
* revert some changes, flush streams
* replace abort with exit(1) to call atexit and dtors
* remove more endl and put in explicit flush
Run the external profiler the same number of iterations as the
benchmark was run normally.
This makes, for example, a trace collected via ProfilerManager
consistent with collected PMU data.
* Verify RegisterProfilerManager doesn't overwrite an existing registration
Tested:
Add a second registration to test/profiler_manager_test.cc and
verify the test crashes as expected.
* Verify RegisterProfilerManager doesn't overwrite an existing registration
Tested:
Configure with:
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on
Then run:
ctest -R profiler_manager_gtest
Before change test fails (expected), after change test passes (expected)
---------
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
Previously, the Start/Stop routines were called before the benchmark function
was called and after it returned. However, what we really want is for them
to be called within the core of the benchmark:
for (auto _ : state) {
// This is what we want traced, not the entire BM_foo function.
}
This API is akin to the MemoryManager API and lets tools provide
their own profiler which is wrapped in the same way MemoryManager is
wrapped. Namely, the profiler provides Start/Stop methods that are called
at the start/end of running the benchmark in a separate pass.
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
* Rewrite complexity_test to use (hardcoded) manual time
This test is fundamentally flaky, because it tried to read tea leafs,
and is inherently misbehaving in CI environments,
since there are unmitigated sources of noise.
That being said, the computed Big-O also depends on the `--benchmark_min_time=`
Fixes https://github.com/google/benchmark/issues/272
* Correctly compute Big-O for manual timings. Fixes#1758.
* complexity_test: do more stuff in empty loop
* Make all empty loops be a bit longer empty
Looks like on windows, some of these tests still fail,
i guess clock precision is too small.
* Add support for Alpha architecture
As documented, the real cycle counter is unsafe to use here, because it
is a 32-bit integer which wraps every ~4s. Use gettimeofday instead,
which has a limitation of a low-precision real-time-clock (~1ms), but no
wrapping. Passes test suite.
Support parsing /proc/cpuinfo on Alpha
tabular_test: add a missing DoNotOptimize call