Commit 7cc78c53 authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

cppgc: Align cppgc::MetricRecorder with v8::metrics::Recorder

Update the MetricRecorder struct to have a similar structure and similar
fields to the GC struct defined in v8-metrics.h

Bug: chromium:1056170
Change-Id: Ieb77412476353557134aeac5cf8f66ab257e22dc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2653236Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72394}
parent ab7c7c78
......@@ -20,39 +20,47 @@ class StatsCollector;
*/
class MetricRecorder {
public:
struct CppGCCycleEndMetricSamples {
int64_t atomic_mark_us;
int64_t atomic_weak_us;
int64_t atomic_compact_us;
int64_t atomic_sweep_us;
int64_t incremental_mark_us;
int64_t incremental_sweep_us;
int64_t concurrent_mark_us;
int64_t concurrent_sweep_us;
int64_t objects_before_bytes;
int64_t objects_after_bytes;
int64_t objects_freed_bytes;
int64_t memory_before_bytes;
int64_t memory_after_bytes;
int64_t memory_freed_bytes;
struct CppGCFullCycle {
struct IncrementalPhases {
int64_t mark_duration_us;
int64_t sweep_duration_us;
};
struct Phases : public IncrementalPhases {
int64_t weak_duration_us;
int64_t compact_duration_us;
};
struct Sizes {
int64_t before_bytes;
int64_t after_bytes;
int64_t freed_bytes;
};
Phases total;
Phases main_thread;
Phases main_thread_atomic;
IncrementalPhases main_thread_incremental;
Sizes objects;
Sizes memory;
double collection_rate_in_percent;
double efficiency_in_bytes_per_us;
double main_thread_efficiency_in_bytes_per_us;
};
struct CppGCIncrementalMarkMetricSample {
struct CppGCMainThreadIncrementalMark {
int64_t duration_us;
};
struct CppGCIncrementalSweepMetricSample {
struct CppGCMainThreadIncrementalSweep {
int64_t duration_us;
};
virtual ~MetricRecorder() = default;
virtual void AddMainThreadEvent(const CppGCCycleEndMetricSamples& event) {}
virtual void AddMainThreadEvent(
const CppGCIncrementalMarkMetricSample& event) {}
virtual void AddMainThreadEvent(const CppGCFullCycle& event) {}
virtual void AddMainThreadEvent(const CppGCMainThreadIncrementalMark& event) {
}
virtual void AddMainThreadEvent(
const CppGCIncrementalSweepMetricSample& event) {}
const CppGCMainThreadIncrementalSweep& event) {}
};
} // namespace internal
......
......@@ -123,13 +123,78 @@ double StatsCollector::GetRecentAllocationSpeedInBytesPerMs() const {
(current_time - time_of_last_end_of_marking_).InMillisecondsF();
}
namespace {
int64_t SumPhases(const MetricRecorder::CppGCFullCycle::Phases& phases) {
return phases.mark_duration_us + phases.weak_duration_us +
phases.compact_duration_us + phases.sweep_duration_us;
}
MetricRecorder::CppGCFullCycle GetFullCycleEventForMetricRecorder(
int64_t atomic_mark_us, int64_t atomic_weak_us, int64_t atomic_compact_us,
int64_t atomic_sweep_us, int64_t incremental_mark_us,
int64_t incremental_sweep_us, int64_t concurrent_mark_us,
int64_t concurrent_sweep_us, int64_t objects_before_bytes,
int64_t objects_after_bytes, int64_t objects_freed_bytes,
int64_t memory_before_bytes, int64_t memory_after_bytes,
int64_t memory_freed_bytes) {
MetricRecorder::CppGCFullCycle event;
// MainThread.Incremental:
event.main_thread_incremental.mark_duration_us = incremental_mark_us;
event.main_thread_incremental.sweep_duration_us = incremental_sweep_us;
// MainThread.Atomic:
event.main_thread_atomic.mark_duration_us = atomic_mark_us;
event.main_thread_atomic.weak_duration_us = atomic_weak_us;
event.main_thread_atomic.compact_duration_us = atomic_compact_us;
event.main_thread_atomic.sweep_duration_us = atomic_sweep_us;
// MainThread:
event.main_thread.mark_duration_us =
event.main_thread_atomic.mark_duration_us +
event.main_thread_incremental.mark_duration_us;
event.main_thread.weak_duration_us =
event.main_thread_atomic.weak_duration_us;
event.main_thread.compact_duration_us =
event.main_thread_atomic.compact_duration_us;
event.main_thread.sweep_duration_us =
event.main_thread_atomic.sweep_duration_us +
event.main_thread_incremental.sweep_duration_us;
// Total:
event.total.mark_duration_us =
event.main_thread.mark_duration_us + concurrent_mark_us;
event.total.weak_duration_us = event.main_thread.weak_duration_us;
event.total.compact_duration_us = event.main_thread.compact_duration_us;
event.total.sweep_duration_us =
event.main_thread.sweep_duration_us + concurrent_sweep_us;
// Objects:
event.objects.before_bytes = objects_before_bytes;
event.objects.after_bytes = objects_after_bytes;
event.objects.freed_bytes = objects_freed_bytes;
// Memory:
event.memory.before_bytes = memory_before_bytes;
event.memory.after_bytes = memory_after_bytes;
event.memory.freed_bytes = memory_freed_bytes;
// Collection Rate:
event.collection_rate_in_percent =
static_cast<double>(event.objects.after_bytes) /
event.objects.before_bytes;
// Efficiency:
event.efficiency_in_bytes_per_us =
static_cast<double>(event.objects.freed_bytes) / SumPhases(event.total);
event.main_thread_efficiency_in_bytes_per_us =
static_cast<double>(event.objects.freed_bytes) /
SumPhases(event.main_thread);
return event;
}
} // namespace
void StatsCollector::NotifySweepingCompleted() {
DCHECK_EQ(GarbageCollectionState::kSweeping, gc_state_);
gc_state_ = GarbageCollectionState::kNotRunning;
previous_ = std::move(current_);
current_ = Event();
if (metric_recorder_) {
MetricRecorder::CppGCCycleEndMetricSamples event{
MetricRecorder::CppGCFullCycle event = GetFullCycleEventForMetricRecorder(
previous_.scope_data[kAtomicMark].InMicroseconds(),
previous_.scope_data[kAtomicWeak].InMicroseconds(),
previous_.scope_data[kAtomicCompact].InMicroseconds(),
......@@ -145,7 +210,7 @@ void StatsCollector::NotifySweepingCompleted() {
previous_.memory_size_before_sweep_bytes /* memory_before */,
previous_.memory_size_before_sweep_bytes -
memory_freed_bytes_since_end_of_marking_ /* memory_after */,
memory_freed_bytes_since_end_of_marking_ /* memory_freed */};
memory_freed_bytes_since_end_of_marking_ /* memory_freed */);
metric_recorder_->AddMainThreadEvent(event);
}
}
......@@ -175,13 +240,13 @@ void StatsCollector::RecordHistogramSample(ScopeId scope_id_,
v8::base::TimeDelta time) {
switch (scope_id_) {
case kIncrementalMark: {
MetricRecorder::CppGCIncrementalMarkMetricSample event{
MetricRecorder::CppGCMainThreadIncrementalMark event{
time.InMicroseconds()};
metric_recorder_->AddMainThreadEvent(event);
break;
}
case kIncrementalSweep: {
MetricRecorder::CppGCIncrementalSweepMetricSample event{
MetricRecorder::CppGCMainThreadIncrementalSweep event{
time.InMicroseconds()};
metric_recorder_->AddMainThreadEvent(event);
break;
......
......@@ -13,40 +13,36 @@ namespace internal {
namespace {
class MetricRecorderImpl final : public MetricRecorder {
public:
void AddMainThreadEvent(const CppGCCycleEndMetricSamples& event) final {
CppGCCycleEndMetricSamples_event = event;
CppGCCycleEndMetricSamples_callcount++;
void AddMainThreadEvent(const CppGCFullCycle& event) final {
CppGCFullCycle_event = event;
CppGCFullCycle_callcount++;
}
void AddMainThreadEvent(const CppGCIncrementalMarkMetricSample& event) final {
CppGCIncrementalMarkMetricSample_event = event;
CppGCIncrementalMarkMetricSample_callcount++;
void AddMainThreadEvent(const CppGCMainThreadIncrementalMark& event) final {
CppGCMainThreadIncrementalMark_event = event;
CppGCMainThreadIncrementalMark_callcount++;
}
void AddMainThreadEvent(
const CppGCIncrementalSweepMetricSample& event) final {
CppGCIncrementalSweepMetricSample_event = event;
CppGCIncrementalSweepMetricSample_callcount++;
void AddMainThreadEvent(const CppGCMainThreadIncrementalSweep& event) final {
CppGCMainThreadIncrementalSweep_event = event;
CppGCMainThreadIncrementalSweep_callcount++;
}
static size_t CppGCCycleEndMetricSamples_callcount;
static CppGCCycleEndMetricSamples CppGCCycleEndMetricSamples_event;
static size_t CppGCIncrementalMarkMetricSample_callcount;
static CppGCIncrementalMarkMetricSample
CppGCIncrementalMarkMetricSample_event;
static size_t CppGCIncrementalSweepMetricSample_callcount;
static CppGCIncrementalSweepMetricSample
CppGCIncrementalSweepMetricSample_event;
static size_t CppGCFullCycle_callcount;
static CppGCFullCycle CppGCFullCycle_event;
static size_t CppGCMainThreadIncrementalMark_callcount;
static CppGCMainThreadIncrementalMark CppGCMainThreadIncrementalMark_event;
static size_t CppGCMainThreadIncrementalSweep_callcount;
static CppGCMainThreadIncrementalSweep CppGCMainThreadIncrementalSweep_event;
};
// static
size_t MetricRecorderImpl::CppGCCycleEndMetricSamples_callcount = 0u;
MetricRecorderImpl::CppGCCycleEndMetricSamples
MetricRecorderImpl::CppGCCycleEndMetricSamples_event;
size_t MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount = 0u;
MetricRecorderImpl::CppGCIncrementalMarkMetricSample
MetricRecorderImpl::CppGCIncrementalMarkMetricSample_event;
size_t MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount = 0u;
MetricRecorderImpl::CppGCIncrementalSweepMetricSample
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_event;
size_t MetricRecorderImpl::CppGCFullCycle_callcount = 0u;
MetricRecorderImpl::CppGCFullCycle MetricRecorderImpl::CppGCFullCycle_event;
size_t MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount = 0u;
MetricRecorderImpl::CppGCMainThreadIncrementalMark
MetricRecorderImpl::CppGCMainThreadIncrementalMark_event;
size_t MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount = 0u;
MetricRecorderImpl::CppGCMainThreadIncrementalSweep
MetricRecorderImpl::CppGCMainThreadIncrementalSweep_event;
class MetricRecorderTest : public testing::TestWithHeap {
public:
......@@ -69,28 +65,26 @@ class MetricRecorderTest : public testing::TestWithHeap {
} // namespace
TEST_F(MetricRecorderTest, IncrementalScopesReportedImmediately) {
MetricRecorderImpl::CppGCCycleEndMetricSamples_callcount = 0u;
MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount = 0u;
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount = 0u;
MetricRecorderImpl::CppGCFullCycle_callcount = 0u;
MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount = 0u;
MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount = 0u;
StartGC();
{
EXPECT_EQ(0u,
MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount);
{
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kIncrementalMark);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(1));
}
EXPECT_EQ(1u,
MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount);
EXPECT_EQ(1u, MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount);
EXPECT_LT(
0u,
MetricRecorderImpl::CppGCIncrementalMarkMetricSample_event.duration_us);
MetricRecorderImpl::CppGCMainThreadIncrementalMark_event.duration_us);
}
{
EXPECT_EQ(0u,
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount);
MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount);
{
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kIncrementalSweep);
......@@ -98,18 +92,19 @@ TEST_F(MetricRecorderTest, IncrementalScopesReportedImmediately) {
v8::base::TimeDelta::FromMilliseconds(1));
}
EXPECT_EQ(1u,
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount);
EXPECT_LT(0u, MetricRecorderImpl::CppGCIncrementalSweepMetricSample_event
.duration_us);
MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount);
EXPECT_LT(
0u,
MetricRecorderImpl::CppGCMainThreadIncrementalSweep_event.duration_us);
}
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_callcount);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCFullCycle_callcount);
EndGC(0);
}
TEST_F(MetricRecorderTest, AtomicScopesNotReportedImmediately) {
MetricRecorderImpl::CppGCCycleEndMetricSamples_callcount = 0u;
MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount = 0u;
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount = 0u;
TEST_F(MetricRecorderTest, NonIncrementlaScopesNotReportedImmediately) {
MetricRecorderImpl::CppGCFullCycle_callcount = 0u;
MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount = 0u;
MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount = 0u;
StartGC();
{
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
......@@ -127,241 +122,157 @@ TEST_F(MetricRecorderTest, AtomicScopesNotReportedImmediately) {
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kAtomicSweep);
}
EXPECT_EQ(0u, MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount);
EXPECT_EQ(0u,
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_callcount);
{
StatsCollector::EnabledConcurrentScope scope(
*Heap::From(GetHeap()), StatsCollector::kConcurrentMark);
}
{
StatsCollector::EnabledConcurrentScope scope(
*Heap::From(GetHeap()), StatsCollector::kConcurrentSweep);
}
EXPECT_EQ(0u, MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCFullCycle_callcount);
EndGC(0);
}
TEST_F(MetricRecorderTest, CycleEndMetricsReportedOnGcEnd) {
MetricRecorderImpl::CppGCCycleEndMetricSamples_callcount = 0u;
MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount = 0u;
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount = 0u;
MetricRecorderImpl::CppGCFullCycle_callcount = 0u;
MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount = 0u;
MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount = 0u;
StartGC();
EndGC(0);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount);
EXPECT_EQ(0u,
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount);
EXPECT_EQ(1u, MetricRecorderImpl::CppGCCycleEndMetricSamples_callcount);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount);
EXPECT_EQ(1u, MetricRecorderImpl::CppGCFullCycle_callcount);
}
TEST_F(MetricRecorderTest, CycleEndHistogramReportsValuesForAtomicScopes) {
{
StartGC();
EndGC(0);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_mark_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_weak_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_compact_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_sweep_us);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.incremental_mark_us);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.incremental_sweep_us);
}
{
StartGC();
{
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kAtomicMark);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(1));
}
EndGC(0);
EXPECT_LT(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_mark_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_weak_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_compact_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_sweep_us);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.incremental_mark_us);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.incremental_sweep_us);
}
TEST_F(MetricRecorderTest, CycleEndHistogramReportsCorrectValues) {
StartGC();
EndGC(1000);
StartGC();
{
StartGC();
{
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kAtomicWeak);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(1));
}
EndGC(0);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_mark_us);
EXPECT_LT(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_weak_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_compact_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_sweep_us);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.incremental_mark_us);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.incremental_sweep_us);
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kIncrementalMark);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(10));
}
{
StartGC();
{
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kAtomicCompact);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(1));
}
EndGC(0);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_mark_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_weak_us);
EXPECT_LT(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_compact_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_sweep_us);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.incremental_mark_us);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.incremental_sweep_us);
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kIncrementalSweep);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(20));
}
{
StartGC();
{
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kAtomicSweep);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(1));
}
EndGC(0);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_mark_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_weak_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_compact_us);
EXPECT_LT(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_sweep_us);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.incremental_mark_us);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.incremental_sweep_us);
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kAtomicMark);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(30));
}
{
StartGC();
{
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kIncrementalMark);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(1));
}
EndGC(0);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_mark_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_weak_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_compact_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_sweep_us);
EXPECT_LT(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.incremental_mark_us);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.incremental_sweep_us);
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kAtomicWeak);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(50));
}
{
StartGC();
{
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kIncrementalSweep);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(1));
}
EndGC(0);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_mark_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_weak_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_compact_us);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.atomic_sweep_us);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.incremental_mark_us);
EXPECT_LT(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.incremental_sweep_us);
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kAtomicCompact);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(60));
}
}
TEST_F(MetricRecorderTest, ConcurrentSamplesAreReported) {
{
StartGC();
EndGC(0);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.concurrent_mark_us);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.concurrent_sweep_us);
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kAtomicSweep);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(70));
}
{
StartGC();
{
StatsCollector::EnabledConcurrentScope scope(
*Heap::From(GetHeap()), StatsCollector::kConcurrentMark);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(1));
}
EndGC(0);
EXPECT_LT(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.concurrent_mark_us);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.concurrent_sweep_us);
StatsCollector::EnabledConcurrentScope scope(
*Heap::From(GetHeap()), StatsCollector::kConcurrentMark);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(80));
}
{
StartGC();
{
StatsCollector::EnabledConcurrentScope scope(
*Heap::From(GetHeap()), StatsCollector::kConcurrentSweep);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(1));
}
EndGC(0);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.concurrent_mark_us);
EXPECT_LT(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.concurrent_sweep_us);
StatsCollector::EnabledConcurrentScope scope(
*Heap::From(GetHeap()), StatsCollector::kConcurrentSweep);
scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(100));
}
EndGC(300);
// Check durations.
static constexpr int64_t kDurationComparisonTolerance = 50;
EXPECT_LT(std::abs(MetricRecorderImpl::CppGCFullCycle_event
.main_thread_incremental.mark_duration_us -
10000),
kDurationComparisonTolerance);
EXPECT_LT(std::abs(MetricRecorderImpl::CppGCFullCycle_event
.main_thread_incremental.sweep_duration_us -
20000),
kDurationComparisonTolerance);
EXPECT_LT(std::abs(MetricRecorderImpl::CppGCFullCycle_event.main_thread_atomic
.mark_duration_us -
30000),
kDurationComparisonTolerance);
EXPECT_LT(std::abs(MetricRecorderImpl::CppGCFullCycle_event.main_thread_atomic
.weak_duration_us -
50000),
kDurationComparisonTolerance);
EXPECT_LT(std::abs(MetricRecorderImpl::CppGCFullCycle_event.main_thread_atomic
.compact_duration_us -
60000),
kDurationComparisonTolerance);
EXPECT_LT(std::abs(MetricRecorderImpl::CppGCFullCycle_event.main_thread_atomic
.sweep_duration_us -
70000),
kDurationComparisonTolerance);
EXPECT_LT(std::abs(MetricRecorderImpl::CppGCFullCycle_event.main_thread
.mark_duration_us -
40000),
kDurationComparisonTolerance);
EXPECT_LT(std::abs(MetricRecorderImpl::CppGCFullCycle_event.main_thread
.weak_duration_us -
50000),
kDurationComparisonTolerance);
EXPECT_LT(std::abs(MetricRecorderImpl::CppGCFullCycle_event.main_thread
.compact_duration_us -
60000),
kDurationComparisonTolerance);
EXPECT_LT(std::abs(MetricRecorderImpl::CppGCFullCycle_event.main_thread
.sweep_duration_us -
90000),
kDurationComparisonTolerance);
EXPECT_LT(
std::abs(MetricRecorderImpl::CppGCFullCycle_event.total.mark_duration_us -
120000),
kDurationComparisonTolerance);
EXPECT_LT(
std::abs(MetricRecorderImpl::CppGCFullCycle_event.total.weak_duration_us -
50000),
kDurationComparisonTolerance);
EXPECT_LT(
std::abs(
MetricRecorderImpl::CppGCFullCycle_event.total.compact_duration_us -
60000),
kDurationComparisonTolerance);
EXPECT_LT(
std::abs(
MetricRecorderImpl::CppGCFullCycle_event.total.sweep_duration_us -
190000),
kDurationComparisonTolerance);
// Check collection rate and efficiency.
EXPECT_DOUBLE_EQ(
0.3, MetricRecorderImpl::CppGCFullCycle_event.collection_rate_in_percent);
static constexpr double kEfficiencyComparisonTolerance = 0.00001;
EXPECT_LT(
std::abs(
MetricRecorderImpl::CppGCFullCycle_event.efficiency_in_bytes_per_us -
(700.0 / (120000 + 50000 + 60000 + 190000))),
kEfficiencyComparisonTolerance);
EXPECT_LT(std::abs(MetricRecorderImpl::CppGCFullCycle_event
.main_thread_efficiency_in_bytes_per_us -
(700.0 / (40000 + 50000 + 60000 + 90000))),
kEfficiencyComparisonTolerance);
}
TEST_F(MetricRecorderTest, ObjectSizeMetricsNoAllocations) {
......@@ -371,23 +282,13 @@ TEST_F(MetricRecorderTest, ObjectSizeMetricsNoAllocations) {
// Populate current event.
StartGC();
EndGC(800);
EXPECT_EQ(1000u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.objects_before_bytes);
EXPECT_EQ(
800u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.objects_after_bytes);
EXPECT_EQ(
200u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.objects_freed_bytes);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.memory_before_bytes);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.memory_after_bytes);
EXPECT_EQ(
0u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.memory_freed_bytes);
EXPECT_EQ(1000u,
MetricRecorderImpl::CppGCFullCycle_event.objects.before_bytes);
EXPECT_EQ(800u, MetricRecorderImpl::CppGCFullCycle_event.objects.after_bytes);
EXPECT_EQ(200u, MetricRecorderImpl::CppGCFullCycle_event.objects.freed_bytes);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCFullCycle_event.memory.before_bytes);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCFullCycle_event.memory.after_bytes);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCFullCycle_event.memory.freed_bytes);
}
TEST_F(MetricRecorderTest, ObjectSizeMetricsWithAllocations) {
......@@ -404,23 +305,13 @@ TEST_F(MetricRecorderTest, ObjectSizeMetricsWithAllocations) {
stats->NotifyAllocatedMemory(1000);
stats->NotifyFreedMemory(400);
stats->NotifySweepingCompleted();
EXPECT_EQ(1300u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.objects_before_bytes);
EXPECT_EQ(
800,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.objects_after_bytes);
EXPECT_EQ(
500u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.objects_freed_bytes);
EXPECT_EQ(
700u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.memory_before_bytes);
EXPECT_EQ(
300u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.memory_after_bytes);
EXPECT_EQ(
400u,
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.memory_freed_bytes);
EXPECT_EQ(1300u,
MetricRecorderImpl::CppGCFullCycle_event.objects.before_bytes);
EXPECT_EQ(800, MetricRecorderImpl::CppGCFullCycle_event.objects.after_bytes);
EXPECT_EQ(500u, MetricRecorderImpl::CppGCFullCycle_event.objects.freed_bytes);
EXPECT_EQ(700u, MetricRecorderImpl::CppGCFullCycle_event.memory.before_bytes);
EXPECT_EQ(300u, MetricRecorderImpl::CppGCFullCycle_event.memory.after_bytes);
EXPECT_EQ(400u, MetricRecorderImpl::CppGCFullCycle_event.memory.freed_bytes);
}
} // namespace internal
......
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