Commit Graph

636 Commits

Author SHA1 Message Date
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
Dominic Hamon 78220d6f0d tweak comment wording 2023-08-25 09:58:30 +01:00
Jesse Rosenstock 6dd50bb606 StatisticsMedian: Fix bug
Previously, this could return the wrong result when there
was an even number of elements.

There were two `nth_element` calls.  The second call could
change elements in `[center2, end])`, which was where
`center` pointed.  Therefore, `*center` sometimes had the
wrong value after the second `nth_element` call.

Rewrite to use `max_element` instead of the second call to
`nth_element`.  This avoids modifying the vector.
2023-08-24 16:05:09 +02:00
Jesse Rosenstock 9c65aebb26
perf_counters: Initialize once only when needed (#1656)
* perf_counters: Initialize once only when needed

This works around some performance problems running Android under QEMU.
Calling `pfm_initialize` was very slow, and was called during dynamic
initialization (before `main` or when loaded as a shared library).
This happened whenever benchmark was linked, even if no benchmarks
were run.

Instead, call `pfm_initialize` at most once, and only when one of:
1. `PerfCounters::Initialize` is called
2. `PerfCounters::Create` is called with a non-empty counter list
3. `PerfCounters::IsCounterSupported` is called

The return value of the first `pfm_initialize()` is saved and
returned from all subsequent `PerfCounters::Initialize` calls.

* perf_counters: Make success var const

* InitLibPfmOnce: Inline function
2023-08-24 10:04:09 +01:00
Jesse Rosenstock e73915667c
State: Initialize counters with kAvgIteration in constructor (#1652)
* State: Initialize counters with kAvgIteration in constructor

Previously, `counters` was updated in `PauseTiming()` with
`counters[name] += Counter(measurement, kAvgIteration)`.

The first `counters[name]` call inserts a counter with no flags.

There is no `operator+=` for `Counter`, so the insertion is done
by converting the `Counter` to a `double`, then constructing a
`Counter` to insert from the `double`, which drops the flags.

Pre-insert the `Counter` with the correct flags, then only
update `Counter::value`.

Introduced in 1c64a36 ([perf-counters] Fix pause/resume (#1643)).

* perf_counters_test.cc: Don't divide by iterations

Perf counters are now divided by iterations, so dividing again
in the test is wrong.

* State: Fix shadowed param error

* benchmark.cc: Fix clang-tidy error

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-08-21 15:35:42 +01:00
Jesse Rosenstock 885e9f71d6
benchmark.cc: Fix benchmarks_with_threads condition (#1651)
Change condition for `benchmarks_with_threads` from `benchmark.threads() > 0` to `> 1`.  `threads()` appears to always be `>= 1`.

Introduced in fbc6efa (Refactoring of PerfCounters infrastructure (#1559))
2023-08-17 15:41:17 +01:00
Jesse Rosenstock aa59d40f88
sysinfo.cc: Call getloadavg for Android API >= 29 (#1) (#1649)
Support for `getloadavg` was added in API level 29.
2023-08-14 17:02:42 +01:00
Mircea Trofin 1c64a36c5b
[perf-counters] Fix pause/resume (#1643)
* [perf-counters] Fix pause/resume

Using `state.PauseTiming() / state.ResumeTiming()` was broken.

Thanks [@virajbshah] for the the repro testcase.

* ran clang-format over the whole perf_counters_test.cc

* Remove check that perf counters are 0 on `Pause`, since `Pause`/`Resume`
sequences would cause a non-0 counter value

* both upper and lower bound for the with/without resume counters

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-08-11 12:46:36 +01:00
Devansh Varshney (देवांश वार्ष्णेय) cbecc8ffc7
fix: added benchmark_counters_tabular for file (#1645)
* fix: added benchmark_counters_tabular for file

* fix: only checking the counters_tabular flag
2023-08-11 10:59:53 +01:00
देवांश वार्ष्णेय 02a354f3f3
bug: Inconsistent suffixes console reporter 1009 (#1631)
* removed appendHumanReadable as it was not used anywhere

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-08-01 08:47:09 +01:00
Saran Tunyasuvunakool 71ad1856fd
Fix `-Werror,-Wold-style-cast` build failure on Windows. (#1637)
* Fix `-Werror,-Wold-style-cast` build failure on Windows.

* Fix parentheses.

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-07-31 15:14:34 +01:00
dominic b1c4a752d1
Add tests for Human Readable functionality (#1632)
* Add tests for Human Readable functionality

also fix an issue where the SI/IEC unit wasn't being correctly passed
through.
2023-07-14 13:56:01 +01:00
Pichot 8805bd0c14
pfm: Use a more standard CMake approach for finding libpfm (#1628)
* pfm: Use a more standard CMake approach for finding libpfm

* add myself and sort AUTHORS & CONTRIBUTORS
2023-07-10 17:46:34 +01:00
Chinmay Dalal 43b2917dce
Add more terminals with color support (#1621) 2023-07-04 16:13:55 +01:00
Gary Miguel 1d25c2e3be
remove old-style (C-style) casts (#1614)
Remove old-style (C-style) casts

This is required by the Google C++ style guide:
https://google.github.io/styleguide/cppguide.html#Casting
2023-06-22 01:35:44 +03:00
Chilledheart b323288cba
Fix a typo in regex choice (#1610)
BENCHMARK_HAVE_STD_REGEX is not used but HAVE_STD_REGEX like the other two choices, i.e. HAVE_GNU_POSIX_REGEX and HAVE_POSIX_REGEX.

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-06-19 08:51:48 +01:00
Andrii Dushko b177433f3e
Guard NOMINMAX to prevent redefinition error (#1581) (#1582)
Fixes #1581.
2023-03-31 00:17:14 +03:00
dominic 46d3c84518
Convert uses of `const char*` to `std::string` (#1567)
* Convert uses of const char* to std::string

* fix sanitizer builds

* reformat user guide

* include python bindings

* clang-format
2023-03-14 13:10:27 +00:00
Henrique Bucher 9f7dc386be
Address warnings on NVIDIA nvc++ (#1573)
* Address warnings on NVIDIA nvc++

Types of warnings were being generated:
1. Deprecated warnings - solved by defining the relevant BENCHMARK_*
  macros for nvc++ and adding pragma suppress on a couple of .cc files
2. Setup/TearDown const vs non-const partial override - solved by
   adding non-const version
3. Static but not referenced - added diagnostic suppress for that file

* Modified manually to comply with CD/CI

* Revert partial override

* Suppress warnings from tests if compiler is NVHPC

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-03-13 12:34:12 +00:00
Mike Apodaca f32748c372
[FR] Provide public accessors to benchmark name and arguments #1551 (#1563)
* [FR] Provide public accessors to benchmark name and arguments #1551

* Update AUTHORS and CONTRIBUTORS

* Update benchmark_register.cc

* Fix lint formatting
2023-03-10 12:38:11 +00:00
dominic 060d762d61
use std::string for skip messages (#1571) 2023-03-08 18:57:19 +00:00
Mike Apodaca adb0d3d0bf
[FR] state.SkipWithMessage #963 (#1564)
* Add `SkipWithMessage`

* Added `enum Skipped`

* Fix: error at end of enumerator list

* Fix lint errors

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-03-08 18:24:48 +00:00
Henrique Bucher fbc6efa9b5
Refactoring of PerfCounters infrastructure (#1559)
* Refactoring of PerfCounters infrastructure

The main feature in this pull request is the removal of the static
sharing of PerfCounters and instead creating them at the top
`RunBenchmarks()`  function where all benchmark runners are created. A
single PerfCountersMeasurement object is created and then shared with
all the new BenchmarkRunners objects, one per existing benchmark.

Other features conflated here in this PR are:
- Added BENCHMARK_DONT_OPTIMIZE macro in global scope
- Removal of the `IsValid()` query, being replaced by checking the
  number of remaining counters after validity tests
- Refactoring of all GTests to reflect the changes and new semantics
- extra comments throughout the new code to clarify intent

It was extremely hard to separate all those features in different PRs
as requested since they are so interdependent on each other so I'm just
pushing them altogether and asking for forgiveness.

This PR comes replacing PRs 1555 and 1558 which have been closed.

* Fixed whitespace issue with clang-format

My clang-format insists in deleting this single white space on line 601
while Github's clang format breaks when it is added. I had to disable
format-on-save to check-in this revert change.
I'm using clang 14.0.6.
2023-03-07 10:27:52 +00:00
Henrique Bucher 2d5012275a
Filter performance counter names, not invalidate all (#1554)
* Filter performance counter names, not invalidate all

Currently, the performance counters are validated while they
are being created and one failure returns NoCounters(), ie it
effecitvely invalidates all the counters.

I would like to propose a new behavior: filter instead. If an
invalid name is added to the counter list, or if that particular
counter is not supported on this platform, that counter is dropped
from the list and an error messages is created, while all the
other counters remain active.

This will give testers a peace of mind that if one mistake is made
or if something is changed or removed from libpfm, their entire
test will not be invalidated. This feature gives more tolerance
with respect to versioning.

Another positive is that testers can now input a superset of all
desired counters for all platforms they support and just let
Benchmark drop all those that are not supported, although it will
create quite a lot of noise down the line, in which case perhaps
we should drop silently or make a consolidated, single error line
but this was not implemented in this change set.

* Removed unused helper type.
2023-03-02 14:56:13 +00:00
Henrique Bucher 27c1d8ace9
Implement unlimited number of performance counters (#1552)
* Implement unlimited number of performance counters

Linux performance counters will limit the number of hardware
counters per reading group. For that reason the implementation of
PerfCounters is limited to 3. However if only software counters
are added, there is no reason to limit the counters. For hardware
counters, we create multiple groups and store a vector or leaders
in the PerfCounters object. When reading, there is an extra time
waste by iterating through all the group leaders. However this
should be the same performance as with today. Reading is done by
groups and it had to be heavily adjusted with the logic being
moved to PerfCounterValues. I created a test for x86-64 and took
care of filtering out the events in case it runs in a platform
that does not support those counters - the test will not fail. The
current tests were already failing (ReOpenExistingCounters,
CreateExistingMeasurements and MultiThreaded) on the main branch
and they continue to fail after this implementation - I did not
fix those not to conflate all here.

* Moved the PerfCounterValues::Read() implementation from header to body.

* Added missing implementation of PerfCounters::IsCounterSupported when HAVE_LIBPFM is not defined.

* Changed comments to reflect the implementation

* Removed arg name so it does not generate an error when HAVE_LIBPBM is not defined.

* Made loop counter a const reference for clang-tidy

* Added missig BENCHMARK_EXPORT to PerfCounterValues
2023-03-01 15:30:41 +00:00
Yingwei Zheng 3b19d7222d
Fix CPU frequency estimation on riscv (#1549)
* Fix CPU frequency estimation on riscv

* Cleanup code for CPU frequency estimation

* Fix use before definition of the macro

* Move the platform definitions back

* Fix compilation error on windows

* Remove unused sleep.h and sleep.cc
2023-02-21 11:30:28 +00:00
Jonathon Reinhart 07996a8adc
Add missing parentheses in ParseBenchMinTime() (#1545)
The previous code was triggering a warning in Debug builds where NDEBUG
is not defined and BM_CHECK() is included:

  benchmark/src/benchmark_runner.cc: In function ‘benchmark::internal::BenchTimeType benchmark::internal::ParseBenchMinTime(const std::string&)’:
  benchmark/src/benchmark_runner.cc:212:24: error: suggest parentheses around ‘&&’ within ‘||’ [-Werror=parentheses]
    212 |            (has_suffix && *p_end == 's' || *p_end == '\0'))
        |             ~~~~~~~~~~~^~~~~~~~~~~~~~~~
  benchmark/src/check.h:82:4: note: in definition of macro ‘BM_CHECK’
     82 |   (b ? ::benchmark::internal::GetNullLogInstance()                           \
        |    ^

Add parenthesis around the && expression.

Also fix a spelling error and move the comma in the preceding comment to
improve clarity.

Tested:
- cmake -E make_directory build
- cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Debug ../
- cmake --build "build" --config Debug
- cmake -E chdir "build" ctest --build-config Debug
2023-02-16 18:35:21 +00:00
hamptonm1 84c71faa81
Refactor links which include "master" and change it to "main" (#1540)
* Refactor URL links: remove "master"

* Replace "master" with "main"
2023-02-07 15:10:30 +00:00
Vy Nguyen 6cf7725ea1
Allow specifying number of iterations via --benchmark_min_time. (#1525)
* Allow specifying number of iterations via --benchmark_min_time.

Make the flag accept two new suffixes:
 + <integer>x: number of iterations
 + <floag>s: minimum number of seconds.

This matches the internal benchmark API.

* forgot to change flag type to string

* used tagged union instead of std::variant, which is not available pre C++14

* update decl in benchmark_runner.h too

* fixed errors

* refactor

* backward compat

* typo

* use IterationCount type

* fixed test

* const_cast

* ret type

* remove extra _

* debug

* fixed bug from reporting that caused the new configs not to be included in the final report

* addressed review comments

* restore unnecessary changes in test/BUILD

* fix float comparisons warnings from Release builds

* clang format

* fix visibility warning

* remove misc file

* removed  backup files

* addressed review comments

* fix shorten in warning

* use suffix for existing min_time specs to silent warnings in tests

* fix leaks

* use default min-time value in flag decl for consistency

* removed double kMinTimeDecl from benchmark.h

* dont need to preserve errno

* add death tests

* Add BENCHMARK_EXPORT to hopefully fix missing def errors

* only enable death tests in debug mode because bm_check is no-op in release mode

* guard death tests with additional support-check macros

* Add additional guard to prevent running in Release mode

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-02-07 11:45:18 +00:00
JbR 4c9cee34f2
Fixing issue with ARM64EC and MSVC (#1514)
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-02-06 15:58:14 +00:00
SunBlack cfbc94960f
Fix Clang-Tidy warnings readability-else-after-return (#1528) 2023-01-16 12:28:48 +00:00
Vy Nguyen a3235d7b69
Include the benchmark's family-name in State (#1511)
* Include the benchmark's family-name in State

For compat with internal library, where State::name() returns the benchmark's family name.

* added missing files from prev commit

* fix field-init order error

* added test
2023-01-10 16:48:17 +00:00
SunBlack fe65457e80
Fix typos found by codespell (#1519) 2023-01-10 12:25:32 +00:00
Jessy De Lannoit e67028c510
Fixes incorrect wide string conversion on win32 (#1516)
* fixes incorrect wide string conversion on win32

* removed redundant error checks
2022-12-06 11:51:41 +00:00