Commit Graph

734 Commits

Author SHA1 Message Date
Tejas Anil Nagmote 8b66b54f7e Make --benchmark_list_tests respect --benchmark_format (#2245)
python + Bazel pre-commit checks / pre-commit (push) Has been cancelled
sanitizer / asan.Debug (push) Has been cancelled
clang-format-lint / check-clang-format (push) Has been cancelled
clang-tidy / run-clang-tidy (push) Has been cancelled
doxygen / Build HTML documentation (push) Has been cancelled
build-and-test-min-cmake / macos-latest.min-cmake (push) Has been cancelled
build-and-test-min-cmake / ubuntu-latest.min-cmake (push) Has been cancelled
build-and-test-perfcounters / ubuntu-latest.Debug (push) Has been cancelled
build-and-test-perfcounters / ubuntu-latest.Release (push) Has been cancelled
build-and-test / macos-latest.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.shared.clang++ (push) Has been cancelled
build-and-test / macos-latest.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.shared.g++ (push) Has been cancelled
bazel / bazel.macos-latest (push) Has been cancelled
bazel / bazel.ubuntu-latest (push) Has been cancelled
bazel / bazel.windows-latest (push) Has been cancelled
sanitizer / msan.Debug (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.shared.g++ (push) Has been cancelled
build-and-test / macos-latest.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.static.g++ (push) Has been cancelled
build-and-test / macos-latest.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.shared.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.shared.g++ (push) Has been cancelled
build-and-test / macos-latest.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.static.g++ (push) Has been cancelled
build-and-test / windows-2022.Debug.shared.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2022.Debug.static.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2025.Debug.shared.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2025.Debug.static.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2022.Release.shared.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2022.Release.static.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2025.Release.shared.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2025.Release.static.VS-18-2025 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.UCRT64 (push) Has been cancelled
sanitizer / tsan.Debug (push) Has been cancelled
sanitizer / ubsan.Debug (push) Has been cancelled
sanitizer / asan.RelWithDebInfo (push) Has been cancelled
sanitizer / msan.RelWithDebInfo (push) Has been cancelled
sanitizer / tsan.RelWithDebInfo (push) Has been cancelled
sanitizer / ubsan.RelWithDebInfo (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Rust bindings on macos-latest (push) Has been cancelled
test-bindings / Test Rust bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Rust bindings on windows-latest (push) Has been cancelled
* Make --benchmark_list_tests respect --benchmark_format via reporter List() (#1642)

* Export FindBenchmarksInternal for shared-library test link; fix include order
2026-07-16 09:46:23 +01:00
anish 79d07484f1 fix(linux): prevent infinite re-exec loop under AppArmor (#2239)
* fix(linux): prevent infinite re-exec loop under AppArmor

The `MaybeReenterWithoutASLR()` function in `src/benchmark.cc` caused infinite execv() loops when running benchmarks under AppArmor-enabled LSMs. The existing fix from #1985 only checked whether personality(ADDR_NO_RANDOMIZE) succeeded in the current process before calling execv(). However, some LSMs like AppArmor can silently reset personality flags during the execve() system call transition, even though the flag was successfully set in the parent process.
Additionally, ensure that we actually report that ASLR is still on in case we fail to unset it.

Signed-off-by: anish <anishesg@users.noreply.github.com>
Co-authored-by: anish <anishesg@users.noreply.github.com>
Co-authored-by: Roman Lebedev <lebedev.ri@gmail.com>
2026-07-06 18:23:42 +03:00
Charles Munger c0f58d3b76 Disable allocation zeroing in benchmarks on Android (#2214)
This is particularly problematic because large allocations partially used can get eagerly memset even if they hit the backing allocator, faulting in a ton of pages, so the behavior can diverge substantially from real in-app performance.
2026-06-02 14:01:31 +01:00
Haihan Jiang d6303b29ba Skip errored runs when computing repetition statistics (#2199) 2026-05-26 21:39:48 +03:00
Haihan Jiang 926a850aa4 Fix pkg-config paths for absolute install dirs (#2198)
The general practice for `.pc` is to avoid absolute paths
and use `${prefix}` variables whenever possible.
2026-05-25 23:36:50 +03:00
Kiwi 266b9b6797 Add libpfm to pkg-config Libs.private when libpfm is enabled (#2194)
The private link library derivation skips CMake targets, so the PFM::libpfm imported target was never translated into linker flags. Static consumers using pkg-config then fail to resolve pfm_* symbols. Resolve imported targets through their IMPORTED_LOCATION and emit the corresponding -L/-l flags alongside the other private libraries.
2026-05-22 23:10:42 +03:00
Ash Vardanian 25a64324f0 Add WASI compatibility (#2144)
* Detect non-Emscripten WASI builds
* Guard clocks & system APIs

google#1774

Co-authored-by: Roman Lebedev <lebedev.ri@gmail.com>
2026-03-12 10:28:36 +00:00
aokblast a51e54b4fd Fix CMake detection on pthread_affinity test on FreeBSD (#2146)
* Fix cmake detection on pthread_affinity test on FreeBSD

In FreeBSD, non posix thread functions locate in the pthread_np.h. We
check the platform and include the correct header.
Also, pthread related features in some platforms require link to special
library. We append Threads target to BENCHMARK_CXX_LIBRARIES so that it
can be added by cxx_feature_check.

* fixup! Fix cmake detection on pthread_affinity test on FreeBSD

---------

Co-authored-by: Roman Lebedev <lebedev.ri@gmail.com>
2026-03-11 21:50:21 +03:00
dominic fae322baa7 refactor ToExponentAndMantissa to use StrFormat instead of std::stringstream (#2138)
* perf: refactor ToExponentAndMantissa to use StrFormat instead of std::stringstream

* return pair instead of using output parameters

* Bump astral-sh/setup-uv from 7.3.0 to 7.3.1 (#2136)

Bumps [astral-sh/setup-uv](https://github.com/astral-sh/setup-uv) from 7.3.0 to 7.3.1.
- [Release notes](https://github.com/astral-sh/setup-uv/releases)
- [Commits](https://github.com/astral-sh/setup-uv/compare/eac588ad8def6316056a12d4907a9d4d84ff7a3b...5a095e7a2014a4212f075830d4f7277575a9d098)

---
updated-dependencies:
- dependency-name: astral-sh/setup-uv
  dependency-version: 7.3.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>

* lambda for mantissa formatting

* structured bindings and clearer code structure

* multiple fixes to avoid Windows x64 crashes (#2139)

* 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

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-05 10:53:11 +00:00
dominic 6daf2dff6f Refactor/modularize headers (#2140)
* Split the benchmark monolithic header

* src uses modular headers

* updated tests to use split headers

* clang-format

* clang-format mistake

* fix exports

* suppress warnings on msvc

* fixing double pops and some more missing exports
2026-03-04 09:53:50 +00:00
dominic b8ea42b2de multiple fixes to avoid Windows x64 crashes (#2139)
* 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
2026-03-04 08:33:14 +00:00
Sergey 559b7cc1ae Fix error: format string is not a string literal (#2126) (#2126)
For some reasons, `std::string StrFormat(const char* format, ...)` was declared
with castom format attributes in conditions. The project wide macro
`PRINTF_FORMAT_STRING_FUNC` must be used.
2026-02-13 13:32:08 +00:00
Peter Collingbourne 84732c8bb2 Replicate generic hardware events on all CPU PMUs (#2123)
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.
2026-02-11 10:07:17 +00:00
Dominic Hamon 5c55f5d4f4 clang tidy warnings 2026-01-20 10:37:18 +00:00
Jesse Rosenstock 90ebbdedf0 Make the Benchmark class public (#2101)
Move ::benchmark::internal::Benchmark to ::benchmark::Benchmark.

It's a bit odd that the documented way to pass arguments to a
benchmark is with `benchmark::internal::Benchmark`.  Make this
public instead.

https://github.com/google/benchmark/blob/v1.9.4/docs/user_guide.md#passing-arguments

https://raw.githubusercontent.com/google/benchmark/refs/tags/v1.9.4/docs/user_guide.md#:~:text=void%20CustomArguments(benchmark%3A%3A-,internal%3A%3ABenchmark,-*%20b)%20%7B%0A%20%20for%20(int

Keep ::benchmark::internal::Benchmark as a deprecated forwarding alias.
Uses of Benchmark in the internal namespace need to explicitly use
::benchmark::Benchmark to avoid the deprecation warning.
2026-01-14 21:04:17 +03:00
Frank Rosner 3e7dac665b #2080: Fix rate and thread rate counter aggregates (#2081)
* Update counter.cc

* User counters: normalize time by thread count

Fixes https://github.com/google/benchmark/issues/2080

* docs

---------

Co-authored-by: Roman Lebedev <lebedev.ri@gmail.com>
2025-12-10 21:38:32 +03:00
David Benjamin 009f05c242 Make the build work with -Wformat=2 (#2088)
* Make the build work with -Wformat=2

The -Wformat=2 macro requires every format string either be a string
literal, or a parameter that was tagged with the format attribute. The
upshot is that it expects every printf function to be marked, or you get
warnings like this:

    src/console_reporter.cc:104:23: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
      104 |   out << FormatString(fmt, args);
          |                       ^~~

Marking such things is generally worthwhile since it turns on
error-checking within the library, so fill in the missing ones.

Tested with:

    bazelisk build --copt=-Werror --copt=-Wformat=2 :all

* Add -Wformat=2 to catch regressions
2025-12-08 15:04:32 +00:00
Nico Weber 188e827899 Add missing type_traits include to benchmark_register.h (#2076)
The file uses std::is_signed, which is in <type_traits>.

Without this, this file won't build after https://llvm.org/PR168334
2025-11-21 05:32:14 +03:00
wieDasDing 9458f54b9a Take a closure for benchmark configuration (#2073)
It turns out it is useful when a benchmark is generated on the fly
before the enumeration on benchmark registration.

There is a use case in which benchmarks shall be built from
configuration flags.
Without captures, it is actually hard to pass additional data.

Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
2025-11-20 17:48:56 +00:00
Edge-Seven f87f080fb9 Fix typos in some files (#2070)
Co-authored-by: khanhkhanhlele <namkhanh20xx@gmail.com>
2025-11-17 11:26:56 +00:00
wieDasDing 8498a2a039 Fix warnings from Clang (#2062)
* 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>
2025-10-23 11:58:38 +03:00
Cole Sturza d029e781f6 fix: add missing override key word to ThreadRunnerDefault::RunThreads in benchmark_runner.cc (#2060)
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2025-10-16 11:16:38 +01:00
Dominic Hamon 8afba0b13a remove done todo 2025-09-29 16:51:00 +01:00
Roman Lebedev b2959a733d JSON reporter: make int dumping always happen in C locale (#2040)
The test fails without the fix.

Fixes https://github.com/google/benchmark/issues/2039
2025-09-15 09:53:26 +01:00
Dr. Rita Garcia 7697796fe5 2011: Installing contents from benchmark's tools/ subdirectory. (#2016)
* 2011: Installing contents from benchmark's tools/ subdirectory.

* Incorporating feedback from the PR

* Per PR feedback, removing guards to when setting CMAKE_INSTALL_PYTOOLSDIR
2025-08-13 19:05:05 +03:00
Daniel Paoliello 12ff2c2583 Fix build when targetting Arm64EC using Clang (#2012) 2025-07-31 11:40:52 +03:00
Max 053b748344 Update sysinfo.cc to fix compilation on windows (#2008)
Fixes #2007
2025-07-07 15:17:56 +03:00
Tomasetti Romin f30ba8b993 core(perf): use string move constructor for AddCustomContext (#2005)
Signed-off-by: romintomasetti <romin.tomasetti@gmail.com>
2025-06-27 18:18:26 +03:00
Shashank Thakur d9ed709886 Refactor: derive pkg-config info to link static libraries (#1998) 2025-06-12 10:00:58 +01:00
Shashank Thakur 1b721bbeff Fix bug: link Shlwapi in Libs.private for Windows (#1996)
* link Shlwapi in Libs.private for Windows

* Add self as contributor
2025-06-06 15:15:56 +01:00
Xiaochuan Ye 3231850f55 fix: enable running in WebAssembly without filesystem (#1956)
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2025-05-19 16:36:32 +01:00
Paweł Bylica 4995099c4f Fix MaybeReenterWithoutASLR() in docker (#1985)
In some docker configurations the `personality()` function may return
inconsistent results. Double check if the persona has been updated
before reentering, otherwise we risk infinite loop.

Fixes https://github.com/google/benchmark/issues/1984.
2025-05-16 22:15:37 +03:00
Roman Lebedev f921cfb4af MaybeReenterWithoutASLR(): be more cautious about argument types (#1983)
It seems, on android the argument is narrower than on linux.
Let's try to support that while not introducing any explicit lossy casts.

Fixes https://github.com/google/benchmark/issues/1982
2025-05-12 11:10:05 +01:00
Roman Lebedev f02794a8bd Automatic ASLR disablement (#1978)
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
2025-05-01 17:34:09 +01:00
Roman Lebedev bc0989adee Detect and report ASLR status (#1977)
* Detect and report ASLR status

Theoretically, we could just disable ASLR in `main()`,
but that seems to be disallowed by default
by some other security features.

Refs. https://github.com/google/benchmark/issues/461

* Add a note about ASLR on other OS.
2025-05-01 17:32:16 +03:00
Roman Lebedev b616354a76 Improve user UX on empty benchmarks (#1976)
Fixes https://github.com/google/benchmark/issues/1962
2025-05-01 13:46:23 +01:00
mark-horvath-arm 0e08459200 Fix error handling of getloadavg (#1974)
getloadavg returns with -1 if cannot obtain load average, but the
current source casts the return value to size_t right away. The cast
result for such a case is probably maximum unsigned long int, so the
resizing of the res vector is certainly going to fail.

This change keeps the original return type of getloadavg and casts it
just before the resizing of the res vector.
2025-04-29 20:17:11 +03:00
krzikalla 0da57b85cf Threading api refactor (#1955)
Refactor the multi-threading api to support
using custom user-provided thread factory
instead of always spawning POSIX Threads.
2025-03-29 10:49:25 +03:00
krzikalla 2918a094b0 Refactor threading run (#1961)
* ThreadManager::WaitForAllThreads removed

* WaitForAllThreads was only called either in single threaded
  environments or just before all threads are joined anyway. As this
  doesn't add a useful synchronization point, it's removed.

* Formatting issue

* Thread Sanitizer satisfied

* More formatting issues
2025-03-27 18:10:05 +03:00
EfesX 5a4c459548 fix memory manager result bug (#1941)
* 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
2025-03-12 10:15:28 +00:00
Alfred Wingate 571c235e1e Install FindPFM.cmake for bencmarkConfig.cmake (#1942)
There is no upstream PFM cmake package config file to use, so this has
to be installed for the benchmark cmake package config file to work.

Bug: https://bugs.gentoo.org/950573
See-Also: c2146397ac

Signed-off-by: Alfred Wingate <parona@protonmail.com>
2025-03-05 08:43:48 +00:00
EfesX ff5c94d860 change setup and teardown callback type (#1934)
Change type of callbacks to take `std::function`
2025-02-20 16:16:32 +03:00
Dillon 8d4fdd6e6e Fix build errors on QuRT (Hexagon) (#1938) 2025-02-19 01:57:34 +03:00
dominic 951429282a [clang-tidy] resolve some global clang-tidy issues (#1933)
* [clang-tidy] resolve some global clang-tidy issues

* more nolint and some global fixes
2025-02-18 10:07:57 +00:00
dominic 57efbfb3a0 use smart pointers (#1935)
* use smart pointers
* use vectors
* size_t
2025-02-18 09:59:27 +00:00
dominic adbda82db3 [clang-tidy] autofix readability issues (#1931)
* [clang-tidy] autofix readability issues

* more modern clang format
2025-02-12 19:40:49 +00:00
dominic 2d4c8dd21a [clang-tidy] autofix cppcoreguidelines (#1932)
* [clang-tidy] autofix cppcoreguidelines

* better than automation maybe
2025-02-12 19:32:45 +00:00
dominic f8db7f6c07 [clang-tidy] fix missing braces (#1928)
* [clang-tidy] fix missing braces
2025-02-11 23:56:06 +00:00
dominic c68e308b4f [clang-tidy] fix warning about decaying array to pointer (#1926)
* [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
2025-02-11 23:15:20 +00:00
dominic 05c5930d96 [clang-tidy] use unique_ptr for benchmark registration (#1927)
* use unique_ptr for benchmark registration
2025-02-11 21:10:34 +00:00