Commit Graph

669 Commits

Author SHA1 Message Date
dominic 62a321d6dc
update standard to C++17 per C++ build support (#1875)
* update standard to C++17 per C++ build support

* disable deadcode checks from clang-tidy

* fix redundant definition of constexpr
2024-11-13 13:06:48 +00:00
Richard Cole 4e3f2d8b67
[#1487] ensure that when printing color text the background color of the terminal on windows is preserved (#1865)
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2024-10-24 12:31:06 +01:00
xdje42 ffc727a859
Verify RegisterProfilerManager doesn't overwrite an existing registration (#1837)
* 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>
2024-10-24 10:22:58 +01:00
Devon Loehr 24e0bd827a
Add enum value from newest Windows SDK (#1859)
* Add enum value from newest Windows SDK

Windows SDK version 10.0.26100.0 adds a cache type value, `CacheUnknown`. This adds a case for that type to `sysinfo.cc`, which will otherwise complain about the switch statement being non-exhaustive when building with the new SDK.

Since the value doesn't exist in prior SDK versions, we only add the case conditionally. The condition can be removed if we ever decide to bump up the required SDK version.

* Fix SDK version macro

Make sure the version macro we're using for the SDK is properly indicative of version 10.0.26100.0. Also fix formatting complains from the linter.

* Add space to satisfy formatter

Formatter insists on two space before a comment after a macro...

* Change preprocessor condition

Try detecting the current SDK version in a slightly different way.

* Replace NTDDI_WIN11_GE with its value

Undefined constants are treated as 0 by the preprocessor, which causes the check to trivially return true for previous SDK versions. Replace the constant with its value (from the newest SDK version) instead,
2024-10-02 09:40:03 +01:00
dominic 72ecc4ea67
Added the functionality for a dry run benchmark called through the cli argument --benchmark_dry_run. (#1851)
* Added benchmark_dry_run boolean flag to command line options

* Dry run logic to exit early and override iterations, repetitions, min time, min warmup time

* Changeddry run override logic structure and added dry run to context

---------

Co-authored-by: Shaan <shaanmistry03@gmail.com>
Co-authored-by: Shaan Mistry <49106143+Shaan-Mistry@users.noreply.github.com>
2024-09-12 15:50:52 +01:00
Igor Zhukov c19cfee61e
Fix C4459: Rename a function parameter `profiler_manager` to avoid hiding the global declaration. (#1839)
* Fix C4459: Rename a function parameter `profiler_manager` to avoid hiding the global declaration.

* Treat warnings as errors for MSVC

* disable one warning for MSVC
2024-08-19 06:39:37 +03:00
dominic a008bf82f4
Ensure reported Time is walltime by removing spurious scaling by threads (#1836)
* change the default to not scale
2024-08-13 18:12:02 +01:00
Ikko Eltociear Ashimine b884717437
chore: update perf_counters.cc (#1831)
peformance -> performance
2024-08-05 10:05:40 +01:00
xdje42 ebb5e3922d
Move ProfilerManager Start/Stop routines closer to actual benchmark #1807 (#1818)
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.
  }
2024-08-01 08:42:41 +01:00
dominic 378fe693a1
Use log2 now that NDK requires at least API 21 which includes it. (#1822)
Fixes #1820
2024-07-24 14:25:32 +01:00
Devon Loehr fa236ed6e6
Suppress invalid-offsetof warning for clang (#1821)
For several compilers, `benchmark.cc` suppresses a warning regarding its use of `offsetof`. This merely extends that suppression to cover clang as well.
2024-07-24 13:12:04 +01:00
Dominic Hamon ad2b1c9ed1 clang format yet again 2024-07-17 16:49:12 +01:00
Dominic Hamon 44507bc91f another reversal of something that breaks on wasm 2024-07-17 16:39:15 +01:00
Dominic Hamon 99410f400c clang-format fixes 2024-07-17 13:25:16 +01:00
Dominic Hamon a73c039b1d roll back fatal error that breaks some platform (wasm) expectations 2024-07-17 13:18:38 +01:00
Dominic Hamon 65668db273 revert perf counters change until we can do the full version 2024-07-16 17:45:30 +01:00
xdje42 7c8ed6b082
[FR] Add API to provide custom profilers #1807 (#1809)
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>
2024-07-16 09:56:40 +01:00
dominic 38df9daf48
add PERF_FORMAT_TOTAL_TIME_{ENABLED,RUNNING} to support multiplexing (#1814) 2024-07-12 10:28:16 +01:00
Chris Cotter 71f4218c1a
Add -lkstat to the .pc for Solaris (#1801)
* Add -lkstat to the .pc for Solaris

This fixes linking for projects that rely on pkg-config to generate the
link line on Solaris.

Test plan: Built the project locally on Solaris and verified -kstat
appears in the .pc file

```
$ cat lib/pkgconfig/benchmark.pc  | grep Libs.private
Libs.private: -lpthread -lkstat
```

* Use BENCHMARK_PRIVATE_LINK_LIBRARIES
2024-07-03 21:16:43 +03:00
Khem Raj 8e1823d6f5
cycleclock: Fix type conversion to match function return type on riscv64 (#1802)
Fixes builds with clang

src/cycleclock.h:213:10: error: implicit conversion changes signedness: 'uint64_t' (aka 'unsigned long') to 'int64_t' (aka 'long') [-Werror,-Wsign-conversion]
     213 |   return cycles;
         |   ~~~~~~ ^~~~~~
   1 error generated.
2024-06-11 13:37:35 +01:00
Khem Raj 7f0e99af54
cycleclock: Fix type conversion to match function return type (#1794)
fixes build with clang19

src/cycleclock.h:208:52: error: implicit conversion changes signedness: 'uint64_t' (aka 'unsigned long long') to 'int64_t' (aka 'long long') [-Werror,-Wsign-conversion]
  208 |   return (static_cast<uint64_t>(cycles_hi1) << 32) | cycles_lo;
      |   ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
1 error generated.
2024-05-29 06:14:54 +03:00
Steven Johnson 7f992a553d
Improve compatibility with Hexagon hardware (#1785)
The customization done via BENCHMARK_OS_QURT works just fine with the Hexagon simulator, but on at least some Hexagon hardware, both `qurt_timer_get_ticks()` and `std::chrono::now()` are broken and always return 0. This fixes the former by using the better-supported (and essentially identical `qurt_sysclock_get_hw_ticks()` call, and the latter by reading a 19.2MHz hardware counter (per suggestion from Qualcomm). Local testing seems to indicate these changes are just as robust under the simulator as before.
2024-05-23 20:08:54 +03:00
David Seifert c0105603f6
Add `benchmark_main.pc` to link `main()` containing library (#1779)
This is similar to the addition in 8604c4adac (diff-eb8e49bdf5e9aafb996777a4f4302ad1efd281222bf3202eb9b77ce47496c345)
that added pkg-config support in GTest. Without this, users
need to manually find the library containing `main()`.
2024-04-14 19:05:36 +03:00
dhairya d6ce145287
Refactor: Return frequency as double (#1782)
Adjusted the GetSysctl call in sysinfo.cc to ensure the frequency
value is returned as a double rather than an integer. This helps
maintain consistency and clarity in the codebase.
2024-04-13 00:22:31 +03:00
Fanbo Meng 70916cbf71
Remove COMPILER_IBMXL macro for z/OS (#1777)
COMPILER_IBMXL identifies the Clang based IBM XL compiler (xlclang) on z/OS. This compiler is obsolete and replaced by the Open XL compiler, so the macro is no longer needed and the existing code would lead to incorrect asm syntax for Open XL.
2024-04-03 10:26:33 +01:00
Vasyl Zubko f3ec7b8820
Fix OpenBSD build (#1772) 2024-03-24 22:17:34 +03:00
PhilipDeegan d5c55e8c42
allow BENCHMARK_VERSION to be undefined (#1769) 2024-03-21 15:29:38 +03:00
Afanasyev Ivan ad7c3ff18b
Fix implicit conversion changes signess warning in perf_counters.cc (#1765)
`read_bytes` is `ssize_t` (and we know it's non-negative),
we need to explicitly cast it to `size_t`.
2024-03-09 15:35:18 +03:00
dominic c64b144f42
mitigate clang build warnings -Wconversion (#1763)
* mitigate clang build warnings -Wconversion

* ensure we have warnings set everywhere and fix some
2024-03-07 12:19:56 +00:00
Tiago Freire 654d8d6cf3
Fixed LTO issue on no discard variable (#1761)
Improve `UseCharPointer()` (thus, `DoNotOptimize()`) under MSVC LTO,
make it actually escape the pointer and prevent it from being optimized away.
2024-03-06 15:50:45 +03:00
Roman Lebedev 3d85343d65
Rewrite complexity_test to use (hardcoded) manual time (#1757)
* 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.
2024-02-19 15:22:35 +00:00
Sam James 7f7c96a264
sysinfo.cc: Always abort on GetNumCPUs failure (#1756)
Defines a wrapper function, CheckNumCPUs, which enforces that GetNumCPUs
never returns fewer than one CPU.  There is no reasonable way to
continue if we are unable to identify the number of CPUs.

Signed-off-by: Sam James <sam@gentoo.org>
2024-02-14 20:19:46 +03:00
Sam James 385033bd11
CycleClock: Add support for Alpha architecture (#1753)
* 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
2024-02-14 00:04:44 +03:00
Matthias Liedtke b7ad5e0497
fix typo in GetBenchmarkVersion() (#1755) 2024-02-12 16:56:58 +00:00
dominic 30a37e1b0b
set library version in bazel (#1746)
* set library version in bazel
2024-01-29 13:48:04 +00:00
Roman Lebedev 17bc235ab3
Output library / schema versions in JSON context block (#1742)
* CMake: `get_git_version()`: just use `--dirty` flag of `git describe`

* CMake: move version normalization out of `get_git_version()`

Mainly, i want `get_git_version()` to return true version,
not something sanitized.

* JSON reporter: store library version and schema version in `context`

* Tools: discard inputs with unexpected `json_schema_version`

* Extract version string into `GetBenchmarkVersiom()`

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2024-01-29 13:15:43 +00:00
Aleksey 3d293cd67a
Fix C-style typecasting in QNX-specific code (#1739)
C-style typecasting breaks the build due to `-Werror=old-style-cast` which should remain in place.
2024-01-16 12:28:04 +00:00
Benny Tordrup 54e4327190
Issue 1734: Streams not flushed if not running actual benchmarks (#1735)
Consistently flush Out and Err streams, otherwise they might not get flushed
and the output lost when using custom streams.

Fixes #1734.
2024-01-09 17:59:10 +03:00
Benny Tordrup e61e332df9
Issue1731 created console does not receive output (#1732)
* Instead of directly comparing std::cout and GetOutputStream(), the underlying buffers are retreived via rdbuf(), and then compared.

* Instead of fflush(stdout), call out.flush().
Use out << FormatString() instead of vprintf

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2024-01-05 14:08:28 +00:00
Abhina Sree e3824e7503
fix per-thread timing error on z/OS (#1719)
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2024-01-04 11:07:01 +00:00
aurel32 99bdb2127d
CycleClock: use RDTIME instead of RDCYCLE on RISC-V (#1727)
Starting with Linux 6.6 [1], RDCYCLE is a privileged instruction on
RISC-V and can't be used directly from userland. There is a sysctl
option to change that as a transition period, but it will eventually
disappear.

Use RDTIME instead, which while less accurate has the advantage of being
synchronized between CPU (and thus monotonic) and of constant frequency.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cc4c07c89aada16229084eeb93895c95b7eabaa3

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2024-01-04 09:16:40 +00:00
Afanasyev Ivan 2d2e07e3c5
Fix division by zero for low frequency timers for CV statistics (#1724) 2024-01-03 12:40:59 +00:00
Abhina Sree 7b52bf7346
define HOST_NAME_MAX for z/oS (#1717) 2023-12-20 17:18:37 +00:00
Roman Lebedev 50560985db
[NFC] `complexity_n` is not of `IterationCount` type (#1709)
There is no bug here, but it gave me a scare the other day.
It is not incorrect to use `IterationCount` here,
since it's just an `int64_t` either way,
but it's wildly confusing. Let's not do that.

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-12-07 10:40:56 +00:00
Anjan Roy 93a96a26a6
Add missing `\n` character at end of error log string (#1700)
Closes https://github.com/google/benchmark/issues/1699

Signed-off-by: Anjan Roy <hello@itzmeanjan.in>
2023-11-13 17:39:32 +00:00
Tiago Freire a543fcd410
Fixed compiler warnings (#1697)
* fixed warnings
used proper math functions

* ran clang format

* used a more up-to-date clang-format

* space twedling

* reveretd CMakeLists.txt
2023-11-10 10:09:50 +00:00
Andreas Abel f30c99a7c8
Increase the kMaxIterations limit (#1668)
* Increase the kMaxIterations limit

This fixes #1663. Note that as a result of this change, the columns in the console output can become misaligned if the actual iteration count is too high. This will be dealt with in a separate commit.

* Fix failing test on Windows

* Fix formatting

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-10-17 17:13:59 +01:00
Dominic Hamon 365bf7602b fix format in src/sysinfo 2023-10-17 16:50:22 +01:00
Ming Zero ea3c3f983b
Fix building on MinGW: default `WINVER` is too old (#1681)
MinGW defaults `WINVER` to something very old,
while benchmark requires features gated by `WINVER = 0x0600`,
so manually set update to that.
2023-10-16 18:19:17 +03:00
Andreas Abel 7736df0304
Make json and csv output consistent. (#1662)
* Make json and csv output consistent.

Currently, the --benchmark_format=csv option does not output the correct value for the cv statistics. Also, the json output should not contain a time unit for the cv statistics.

* fix formatting

* undo json change

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-09-26 13:43:23 +01:00