cb66c5d68e
build-and-test / ubuntu-24.04-arm.Debug.static.clang++ (push) Waiting to run
build-and-test / macos-latest.Debug.shared.g++ (push) Waiting to run
build-and-test / macos-latest.Debug.static.g++ (push) Waiting to run
build-and-test / ubuntu-22.04.Debug.static.g++ (push) Waiting to run
build-and-test / ubuntu-24.04.Debug.static.g++ (push) Waiting to run
bazel / bazel.macos-latest (push) Waiting to run
bazel / bazel.windows-latest (push) Waiting to run
build-and-test-min-cmake / macos-latest.min-cmake (push) Waiting to run
build-and-test / macos-latest.Debug.shared.clang++ (push) Waiting to run
build-and-test / ubuntu-22.04.Debug.shared.clang++ (push) Waiting to run
build-and-test / ubuntu-24.04.Debug.shared.clang++ (push) Waiting to run
build-and-test / ubuntu-24.04-arm.Debug.shared.clang++ (push) Waiting to run
build-and-test / macos-latest.Debug.static.clang++ (push) Waiting to run
build-and-test / ubuntu-22.04.Debug.static.clang++ (push) Waiting to run
build-and-test / ubuntu-24.04.Debug.static.clang++ (push) Waiting to run
build-and-test / ubuntu-22.04.Debug.shared.g++ (push) Waiting to run
build-and-test / ubuntu-24.04.Debug.shared.g++ (push) Waiting to run
build-and-test / ubuntu-24.04-arm.Debug.shared.g++ (push) Waiting to run
build-and-test / ubuntu-24.04-arm.Debug.static.g++ (push) Waiting to run
build-and-test / macos-latest.Release.shared.clang++ (push) Waiting to run
build-and-test / ubuntu-22.04.Release.shared.clang++ (push) Waiting to run
build-and-test / ubuntu-24.04.Release.shared.clang++ (push) Waiting to run
build-and-test / ubuntu-24.04-arm.Release.shared.clang++ (push) Waiting to run
build-and-test / macos-latest.Release.static.clang++ (push) Waiting to run
build-and-test / ubuntu-22.04.Release.static.clang++ (push) Waiting to run
build-and-test / ubuntu-24.04.Release.static.clang++ (push) Waiting to run
build-and-test / ubuntu-24.04-arm.Release.static.clang++ (push) Waiting to run
build-and-test / macos-latest.Release.shared.g++ (push) Waiting to run
build-and-test / ubuntu-22.04.Release.shared.g++ (push) Waiting to run
build-and-test / ubuntu-24.04.Release.shared.g++ (push) Waiting to run
build-and-test / ubuntu-24.04-arm.Release.shared.g++ (push) Waiting to run
build-and-test / macos-latest.Release.static.g++ (push) Waiting to run
build-and-test / ubuntu-22.04.Release.static.g++ (push) Waiting to run
build-and-test / ubuntu-24.04.Release.static.g++ (push) Waiting to run
build-and-test / ubuntu-24.04-arm.Release.static.g++ (push) Waiting to run
build-and-test / windows-2022.Debug.shared.VS-17-2022 (push) Waiting to run
build-and-test / windows-2022.Debug.static.VS-17-2022 (push) Waiting to run
build-and-test / windows-2025.Debug.shared.VS-18-2025 (push) Waiting to run
build-and-test / windows-2025.Debug.static.VS-18-2025 (push) Waiting to run
build-and-test / windows-2022.Release.shared.VS-17-2022 (push) Waiting to run
build-and-test / windows-2022.Release.static.VS-17-2022 (push) Waiting to run
build-and-test / windows-2025.Release.shared.VS-18-2025 (push) Waiting to run
build-and-test / windows-2025.Release.static.VS-18-2025 (push) Waiting to run
build-and-test / windows-latest.Debug.shared.CLANG64 (push) Waiting to run
build-and-test / windows-latest.Debug.shared.MINGW64 (push) Waiting to run
build-and-test / windows-latest.Debug.shared.UCRT64 (push) Waiting to run
build-and-test / windows-latest.Debug.static.CLANG64 (push) Waiting to run
build-and-test / windows-latest.Debug.static.MINGW64 (push) Waiting to run
build-and-test / windows-latest.Debug.static.UCRT64 (push) Waiting to run
build-and-test / windows-latest.Release.shared.CLANG64 (push) Waiting to run
build-and-test / windows-latest.Release.shared.MINGW64 (push) Waiting to run
build-and-test / windows-latest.Release.shared.UCRT64 (push) Waiting to run
build-and-test / windows-latest.Release.static.CLANG64 (push) Waiting to run
build-and-test / windows-latest.Release.static.MINGW64 (push) Waiting to run
build-and-test / windows-latest.Release.static.UCRT64 (push) Waiting to run
test-bindings / Test Python 3.10 bindings on macos-latest (push) Waiting to run
test-bindings / Test Python 3.11 bindings on macos-latest (push) Waiting to run
test-bindings / Test Python 3.12 bindings on macos-latest (push) Waiting to run
test-bindings / Test Python 3.13 bindings on macos-latest (push) Waiting to run
test-bindings / Test Python 3.10 bindings on windows-latest (push) Waiting to run
test-bindings / Test Python 3.11 bindings on windows-latest (push) Waiting to run
test-bindings / Test Python 3.12 bindings on windows-latest (push) Waiting to run
test-bindings / Test Python 3.13 bindings on windows-latest (push) Waiting to run
test-bindings / Test Rust bindings on macos-latest (push) Waiting to run
test-bindings / Test Rust bindings on windows-latest (push) Waiting to run
bazel / bazel.ubuntu-latest (push) Failing after 1s
build-and-test-perfcounters / ubuntu-latest.Debug (push) Failing after 0s
build-and-test-perfcounters / ubuntu-latest.Release (push) Failing after 1s
doxygen / Build HTML documentation (push) Failing after 1s
python + Bazel pre-commit checks / pre-commit (push) Failing after 1s
sanitizer / tsan.Debug (push) Failing after 1s
sanitizer / ubsan.Debug (push) Failing after 0s
sanitizer / ubsan.RelWithDebInfo (push) Failing after 1s
build-and-test-min-cmake / ubuntu-latest.min-cmake (push) Failing after 1s
clang-format-lint / check-clang-format (push) Failing after 1s
sanitizer / asan.Debug (push) Failing after 1s
sanitizer / msan.RelWithDebInfo (push) Failing after 1s
clang-tidy / run-clang-tidy (push) Failing after 1s
sanitizer / msan.Debug (push) Failing after 1s
sanitizer / asan.RelWithDebInfo (push) Failing after 0s
sanitizer / tsan.RelWithDebInfo (push) Failing after 0s
test-bindings / Test Rust bindings on ubuntu-latest (push) Failing after 0s
test-bindings / Test Python 3.10 bindings on ubuntu-latest (push) Failing after 0s
test-bindings / Test Python 3.11 bindings on ubuntu-latest (push) Failing after 0s
test-bindings / Test Python 3.12 bindings on ubuntu-latest (push) Failing after 1s
test-bindings / Test Python 3.13 bindings on ubuntu-latest (push) Failing after 0s
105 lines
2.6 KiB
C++
105 lines
2.6 KiB
C++
#include <vector>
|
|
|
|
#include "benchmark/benchmark_api.h"
|
|
#include "benchmark/managers.h"
|
|
#include "benchmark/reporter.h"
|
|
#include "benchmark/state.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace {
|
|
|
|
using benchmark::Benchmark;
|
|
using benchmark::ClearRegisteredBenchmarks;
|
|
using benchmark::ConsoleReporter;
|
|
using benchmark::MemoryManager;
|
|
using benchmark::RegisterBenchmark;
|
|
using benchmark::RunSpecifiedBenchmarks;
|
|
using benchmark::State;
|
|
|
|
constexpr int N_REPETITIONS = 100;
|
|
constexpr int N_ITERATIONS = 1;
|
|
|
|
int num_allocs = 0;
|
|
int max_bytes_used = 0;
|
|
int total_allocated_bytes = 0;
|
|
int net_heap_growth = 0;
|
|
|
|
void reset() {
|
|
num_allocs = 0;
|
|
max_bytes_used = 0;
|
|
total_allocated_bytes = 0;
|
|
net_heap_growth = 0;
|
|
}
|
|
class TestMemoryManager : public MemoryManager {
|
|
void Start() override {}
|
|
void Stop(Result& result) override {
|
|
result.num_allocs = num_allocs;
|
|
result.net_heap_growth = net_heap_growth;
|
|
result.max_bytes_used = max_bytes_used;
|
|
result.total_allocated_bytes = total_allocated_bytes;
|
|
|
|
num_allocs += 1;
|
|
max_bytes_used += 2;
|
|
net_heap_growth += 4;
|
|
total_allocated_bytes += 10;
|
|
}
|
|
};
|
|
|
|
class TestReporter : public ConsoleReporter {
|
|
public:
|
|
TestReporter() = default;
|
|
virtual ~TestReporter() = default;
|
|
|
|
bool ReportContext(const Context& /*unused*/) override { return true; }
|
|
|
|
void PrintHeader(const Run&) override {}
|
|
void PrintRunData(const Run& run) override {
|
|
if (run.repetition_index == -1) return;
|
|
if (!run.memory_result.memory_iterations) return;
|
|
|
|
store.push_back(run.memory_result);
|
|
}
|
|
|
|
std::vector<MemoryManager::Result> store;
|
|
};
|
|
|
|
class MemoryResultsTest : public testing::Test {
|
|
public:
|
|
Benchmark* bm;
|
|
TestReporter reporter;
|
|
|
|
void SetUp() override {
|
|
bm = RegisterBenchmark("BM", [](State& st) {
|
|
for (auto _ : st) {
|
|
}
|
|
});
|
|
bm->Repetitions(N_REPETITIONS);
|
|
bm->Iterations(N_ITERATIONS);
|
|
reset();
|
|
}
|
|
void TearDown() override { ClearRegisteredBenchmarks(); }
|
|
};
|
|
|
|
TEST_F(MemoryResultsTest, NoMMTest) {
|
|
RunSpecifiedBenchmarks(&reporter);
|
|
EXPECT_EQ(reporter.store.size(), 0);
|
|
}
|
|
|
|
TEST_F(MemoryResultsTest, ResultsTest) {
|
|
auto mm = std::make_unique<TestMemoryManager>();
|
|
RegisterMemoryManager(mm.get());
|
|
|
|
RunSpecifiedBenchmarks(&reporter);
|
|
EXPECT_EQ(reporter.store.size(), N_REPETITIONS);
|
|
|
|
for (size_t i = 0; i < reporter.store.size(); i++) {
|
|
EXPECT_EQ(reporter.store[i].num_allocs, static_cast<int64_t>(i));
|
|
EXPECT_EQ(reporter.store[i].max_bytes_used, static_cast<int64_t>(i) * 2);
|
|
EXPECT_EQ(reporter.store[i].net_heap_growth, static_cast<int64_t>(i) * 4);
|
|
EXPECT_EQ(reporter.store[i].total_allocated_bytes,
|
|
static_cast<int64_t>(i) * 10);
|
|
}
|
|
}
|
|
|
|
} // namespace
|