Commit 3eae9d57 authored by Michael Lippautz's avatar Michael Lippautz Committed by V8 LUCI CQ

cppgc: Initialize benchmark process only once

Otherwise, DCHECKs complain that the PageAllocator used for the
GlobalGCInfoTable may differ when setting up the platform repeatedly
through benchmarking SetUp().

Change-Id: I7e87e8c9d8c283105e1bd75a4cd176df7f304315
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3283075Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77920}
parent df5efab1
......@@ -26,13 +26,15 @@ if (v8_enable_google_benchmark) {
sources = [
"../../../../test/unittests/heap/cppgc/test-platform.cc",
"../../../../test/unittests/heap/cppgc/test-platform.h",
"utils.h",
"benchmark_main.cc",
"benchmark_utils.cc",
"benchmark_utils.h",
]
deps = [ "//third_party/google_benchmark:benchmark_main" ]
public_deps = [ "//third_party/google_benchmark:google_benchmark" ]
if (cppgc_is_standalone) {
deps += [ "../../../..:cppgc_for_testing" ]
deps = [ "../../../..:cppgc_for_testing" ]
} else {
deps += [ "../../../..:v8_for_testing" ]
deps = [ "../../../..:v8_for_testing" ]
}
}
......@@ -48,10 +50,7 @@ if (v8_enable_google_benchmark) {
"allocation_perf.cc",
"trace_perf.cc",
]
deps = [
":cppgc_benchmark_support",
"//third_party/google_benchmark:benchmark_main",
]
deps = [ ":cppgc_benchmark_support" ]
if (cppgc_is_standalone) {
deps += [ "../../../..:cppgc_for_testing" ]
} else {
......
......@@ -8,7 +8,7 @@
#include "src/base/macros.h"
#include "src/heap/cppgc/globals.h"
#include "src/heap/cppgc/heap.h"
#include "test/benchmarks/cpp/cppgc/utils.h"
#include "test/benchmarks/cpp/cppgc/benchmark_utils.h"
#include "third_party/google_benchmark/src/include/benchmark/benchmark.h"
namespace cppgc {
......
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "include/cppgc/platform.h"
#include "test/benchmarks/cpp/cppgc/benchmark_utils.h"
#include "third_party/google_benchmark/src/include/benchmark/benchmark.h"
// Expanded macro BENCHMARK_MAIN() to allow per-process setup.
int main(int argc, char** argv) {
cppgc::internal::testing::BenchmarkWithHeap::InitializeProcess();
// Contents of BENCHMARK_MAIN().
{
::benchmark::Initialize(&argc, argv);
if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1;
::benchmark::RunSpecifiedBenchmarks();
::benchmark::Shutdown();
}
cppgc::internal::testing::BenchmarkWithHeap::ShutdownProcess();
return 0;
}
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "test/benchmarks/cpp/cppgc/benchmark_utils.h"
#include "include/cppgc/platform.h"
#include "test/unittests/heap/cppgc/test-platform.h"
namespace cppgc {
namespace internal {
namespace testing {
// static
std::shared_ptr<testing::TestPlatform> BenchmarkWithHeap::platform_;
// static
void BenchmarkWithHeap::InitializeProcess() {
platform_ = std::make_shared<testing::TestPlatform>();
cppgc::InitializeProcess(platform_->GetPageAllocator());
}
// static
void BenchmarkWithHeap::ShutdownProcess() {
cppgc::ShutdownProcess();
platform_.reset();
}
} // namespace testing
} // namespace internal
} // namespace cppgc
......@@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef TEST_BENCHMARK_CPP_CPPGC_UTILS_H_
#define TEST_BENCHMARK_CPP_CPPGC_UTILS_H_
#ifndef TEST_BENCHMARK_CPP_CPPGC_BENCHMARK_UTILS_H_
#define TEST_BENCHMARK_CPP_CPPGC_BENCHMARK_UTILS_H_
#include "include/cppgc/heap.h"
#include "include/cppgc/platform.h"
#include "test/unittests/heap/cppgc/test-platform.h"
#include "third_party/google_benchmark/src/include/benchmark/benchmark.h"
......@@ -15,22 +14,26 @@ namespace internal {
namespace testing {
class BenchmarkWithHeap : public benchmark::Fixture {
public:
static void InitializeProcess();
static void ShutdownProcess();
protected:
void SetUp(const ::benchmark::State& state) override {
platform_ = std::make_shared<testing::TestPlatform>();
cppgc::InitializeProcess(platform_->GetPageAllocator());
heap_ = cppgc::Heap::Create(platform_);
void SetUp(::benchmark::State& state) override {
heap_ = cppgc::Heap::Create(GetPlatform());
}
void TearDown(const ::benchmark::State& state) override {
heap_.reset();
cppgc::ShutdownProcess();
}
void TearDown(::benchmark::State& state) override { heap_.reset(); }
cppgc::Heap& heap() const { return *heap_.get(); }
private:
std::shared_ptr<testing::TestPlatform> platform_;
static std::shared_ptr<testing::TestPlatform> GetPlatform() {
return platform_;
}
static std::shared_ptr<testing::TestPlatform> platform_;
std::unique_ptr<cppgc::Heap> heap_;
};
......@@ -38,4 +41,4 @@ class BenchmarkWithHeap : public benchmark::Fixture {
} // namespace internal
} // namespace cppgc
#endif // TEST_BENCHMARK_CPP_CPPGC_UTILS_H_
#endif // TEST_BENCHMARK_CPP_CPPGC_BENCHMARK_UTILS_H_
......@@ -8,7 +8,7 @@
#include "src/base/macros.h"
#include "src/heap/cppgc/globals.h"
#include "src/heap/cppgc/heap.h"
#include "test/benchmarks/cpp/cppgc/utils.h"
#include "test/benchmarks/cpp/cppgc/benchmark_utils.h"
#include "third_party/google_benchmark/src/include/benchmark/benchmark.h"
#include "v8config.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment