v8/test/unittests/heap/cppgc/test-platform.cc
Omer Katz 6a1a3a101e cppgc: Add tracing scopes
This CL adds tracing scopes for the various cppgc classes.
Scopes use TRACE_EVENT_BEGIN and TRACE_EVENT_END macros to report trace
events. To do so they need to include trace-event.h. For unified heap
builds, trace-event.h forwards to v8's src/tracing/trace-event.h. For
other builds, trace-event.h provides a subset of
src/tracing/trace-event.h that covers just the parts used by cppgc.

This CL covers what we need for traces and blink gc metrics (up to
renaming events from BlinkGC.* to CppGC.*). UMA and UKM are not yet
handled.

Bug: chromium:1056170
Change-Id: Id92e84b27259ff0aadae7692f3d79d30896fb8e7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2540548
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71284}
2020-11-19 15:48:17 +00:00

48 lines
1.5 KiB
C++

// Copyright 2020 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/unittests/heap/cppgc/test-platform.h"
#include "include/libplatform/libplatform.h"
#include "src/base/platform/platform.h"
#include "src/base/platform/time.h"
namespace cppgc {
namespace internal {
namespace testing {
TestPlatform::TestPlatform(
std::unique_ptr<v8::TracingController> tracing_controller)
: DefaultPlatform(0 /* thread_pool_size */, IdleTaskSupport::kEnabled,
std::move(tracing_controller)) {}
std::unique_ptr<cppgc::JobHandle> TestPlatform::PostJob(
cppgc::TaskPriority priority, std::unique_ptr<cppgc::JobTask> job_task) {
if (AreBackgroundTasksDisabled()) return nullptr;
return v8_platform_->PostJob(priority, std::move(job_task));
}
void TestPlatform::RunAllForegroundTasks() {
v8::platform::PumpMessageLoop(v8_platform_.get(), kNoIsolate);
if (GetForegroundTaskRunner()->IdleTasksEnabled()) {
v8::platform::RunIdleTasks(v8_platform_.get(), kNoIsolate,
std::numeric_limits<double>::max());
}
}
TestPlatform::DisableBackgroundTasksScope::DisableBackgroundTasksScope(
TestPlatform* platform)
: platform_(platform) {
++platform_->disabled_background_tasks_;
}
TestPlatform::DisableBackgroundTasksScope::~DisableBackgroundTasksScope()
V8_NOEXCEPT {
--platform_->disabled_background_tasks_;
}
} // namespace testing
} // namespace internal
} // namespace cppgc