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; ...@@ -20,39 +20,47 @@ class StatsCollector;
*/ */
class MetricRecorder { class MetricRecorder {
public: public:
struct CppGCCycleEndMetricSamples { struct CppGCFullCycle {
int64_t atomic_mark_us; struct IncrementalPhases {
int64_t atomic_weak_us; int64_t mark_duration_us;
int64_t atomic_compact_us; int64_t sweep_duration_us;
int64_t atomic_sweep_us; };
int64_t incremental_mark_us; struct Phases : public IncrementalPhases {
int64_t incremental_sweep_us; int64_t weak_duration_us;
int64_t concurrent_mark_us; int64_t compact_duration_us;
int64_t concurrent_sweep_us; };
struct Sizes {
int64_t objects_before_bytes; int64_t before_bytes;
int64_t objects_after_bytes; int64_t after_bytes;
int64_t objects_freed_bytes; int64_t freed_bytes;
int64_t memory_before_bytes; };
int64_t memory_after_bytes;
int64_t memory_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; int64_t duration_us;
}; };
struct CppGCIncrementalSweepMetricSample { struct CppGCMainThreadIncrementalSweep {
int64_t duration_us; int64_t duration_us;
}; };
virtual ~MetricRecorder() = default; virtual ~MetricRecorder() = default;
virtual void AddMainThreadEvent(const CppGCCycleEndMetricSamples& event) {} virtual void AddMainThreadEvent(const CppGCFullCycle& event) {}
virtual void AddMainThreadEvent( virtual void AddMainThreadEvent(const CppGCMainThreadIncrementalMark& event) {
const CppGCIncrementalMarkMetricSample& event) {} }
virtual void AddMainThreadEvent( virtual void AddMainThreadEvent(
const CppGCIncrementalSweepMetricSample& event) {} const CppGCMainThreadIncrementalSweep& event) {}
}; };
} // namespace internal } // namespace internal
......
...@@ -123,13 +123,78 @@ double StatsCollector::GetRecentAllocationSpeedInBytesPerMs() const { ...@@ -123,13 +123,78 @@ double StatsCollector::GetRecentAllocationSpeedInBytesPerMs() const {
(current_time - time_of_last_end_of_marking_).InMillisecondsF(); (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() { void StatsCollector::NotifySweepingCompleted() {
DCHECK_EQ(GarbageCollectionState::kSweeping, gc_state_); DCHECK_EQ(GarbageCollectionState::kSweeping, gc_state_);
gc_state_ = GarbageCollectionState::kNotRunning; gc_state_ = GarbageCollectionState::kNotRunning;
previous_ = std::move(current_); previous_ = std::move(current_);
current_ = Event(); current_ = Event();
if (metric_recorder_) { if (metric_recorder_) {
MetricRecorder::CppGCCycleEndMetricSamples event{ MetricRecorder::CppGCFullCycle event = GetFullCycleEventForMetricRecorder(
previous_.scope_data[kAtomicMark].InMicroseconds(), previous_.scope_data[kAtomicMark].InMicroseconds(),
previous_.scope_data[kAtomicWeak].InMicroseconds(), previous_.scope_data[kAtomicWeak].InMicroseconds(),
previous_.scope_data[kAtomicCompact].InMicroseconds(), previous_.scope_data[kAtomicCompact].InMicroseconds(),
...@@ -145,7 +210,7 @@ void StatsCollector::NotifySweepingCompleted() { ...@@ -145,7 +210,7 @@ void StatsCollector::NotifySweepingCompleted() {
previous_.memory_size_before_sweep_bytes /* memory_before */, previous_.memory_size_before_sweep_bytes /* memory_before */,
previous_.memory_size_before_sweep_bytes - previous_.memory_size_before_sweep_bytes -
memory_freed_bytes_since_end_of_marking_ /* memory_after */, 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); metric_recorder_->AddMainThreadEvent(event);
} }
} }
...@@ -175,13 +240,13 @@ void StatsCollector::RecordHistogramSample(ScopeId scope_id_, ...@@ -175,13 +240,13 @@ void StatsCollector::RecordHistogramSample(ScopeId scope_id_,
v8::base::TimeDelta time) { v8::base::TimeDelta time) {
switch (scope_id_) { switch (scope_id_) {
case kIncrementalMark: { case kIncrementalMark: {
MetricRecorder::CppGCIncrementalMarkMetricSample event{ MetricRecorder::CppGCMainThreadIncrementalMark event{
time.InMicroseconds()}; time.InMicroseconds()};
metric_recorder_->AddMainThreadEvent(event); metric_recorder_->AddMainThreadEvent(event);
break; break;
} }
case kIncrementalSweep: { case kIncrementalSweep: {
MetricRecorder::CppGCIncrementalSweepMetricSample event{ MetricRecorder::CppGCMainThreadIncrementalSweep event{
time.InMicroseconds()}; time.InMicroseconds()};
metric_recorder_->AddMainThreadEvent(event); metric_recorder_->AddMainThreadEvent(event);
break; break;
......
...@@ -13,40 +13,36 @@ namespace internal { ...@@ -13,40 +13,36 @@ namespace internal {
namespace { namespace {
class MetricRecorderImpl final : public MetricRecorder { class MetricRecorderImpl final : public MetricRecorder {
public: public:
void AddMainThreadEvent(const CppGCCycleEndMetricSamples& event) final { void AddMainThreadEvent(const CppGCFullCycle& event) final {
CppGCCycleEndMetricSamples_event = event; CppGCFullCycle_event = event;
CppGCCycleEndMetricSamples_callcount++; CppGCFullCycle_callcount++;
} }
void AddMainThreadEvent(const CppGCIncrementalMarkMetricSample& event) final { void AddMainThreadEvent(const CppGCMainThreadIncrementalMark& event) final {
CppGCIncrementalMarkMetricSample_event = event; CppGCMainThreadIncrementalMark_event = event;
CppGCIncrementalMarkMetricSample_callcount++; CppGCMainThreadIncrementalMark_callcount++;
} }
void AddMainThreadEvent( void AddMainThreadEvent(const CppGCMainThreadIncrementalSweep& event) final {
const CppGCIncrementalSweepMetricSample& event) final { CppGCMainThreadIncrementalSweep_event = event;
CppGCIncrementalSweepMetricSample_event = event; CppGCMainThreadIncrementalSweep_callcount++;
CppGCIncrementalSweepMetricSample_callcount++;
} }
static size_t CppGCCycleEndMetricSamples_callcount; static size_t CppGCFullCycle_callcount;
static CppGCCycleEndMetricSamples CppGCCycleEndMetricSamples_event; static CppGCFullCycle CppGCFullCycle_event;
static size_t CppGCIncrementalMarkMetricSample_callcount; static size_t CppGCMainThreadIncrementalMark_callcount;
static CppGCIncrementalMarkMetricSample static CppGCMainThreadIncrementalMark CppGCMainThreadIncrementalMark_event;
CppGCIncrementalMarkMetricSample_event; static size_t CppGCMainThreadIncrementalSweep_callcount;
static size_t CppGCIncrementalSweepMetricSample_callcount; static CppGCMainThreadIncrementalSweep CppGCMainThreadIncrementalSweep_event;
static CppGCIncrementalSweepMetricSample
CppGCIncrementalSweepMetricSample_event;
}; };
// static // static
size_t MetricRecorderImpl::CppGCCycleEndMetricSamples_callcount = 0u; size_t MetricRecorderImpl::CppGCFullCycle_callcount = 0u;
MetricRecorderImpl::CppGCCycleEndMetricSamples MetricRecorderImpl::CppGCFullCycle MetricRecorderImpl::CppGCFullCycle_event;
MetricRecorderImpl::CppGCCycleEndMetricSamples_event; size_t MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount = 0u;
size_t MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount = 0u; MetricRecorderImpl::CppGCMainThreadIncrementalMark
MetricRecorderImpl::CppGCIncrementalMarkMetricSample MetricRecorderImpl::CppGCMainThreadIncrementalMark_event;
MetricRecorderImpl::CppGCIncrementalMarkMetricSample_event; size_t MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount = 0u;
size_t MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount = 0u; MetricRecorderImpl::CppGCMainThreadIncrementalSweep
MetricRecorderImpl::CppGCIncrementalSweepMetricSample MetricRecorderImpl::CppGCMainThreadIncrementalSweep_event;
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_event;
class MetricRecorderTest : public testing::TestWithHeap { class MetricRecorderTest : public testing::TestWithHeap {
public: public:
...@@ -69,28 +65,26 @@ class MetricRecorderTest : public testing::TestWithHeap { ...@@ -69,28 +65,26 @@ class MetricRecorderTest : public testing::TestWithHeap {
} // namespace } // namespace
TEST_F(MetricRecorderTest, IncrementalScopesReportedImmediately) { TEST_F(MetricRecorderTest, IncrementalScopesReportedImmediately) {
MetricRecorderImpl::CppGCCycleEndMetricSamples_callcount = 0u; MetricRecorderImpl::CppGCFullCycle_callcount = 0u;
MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount = 0u; MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount = 0u;
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount = 0u; MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount = 0u;
StartGC(); StartGC();
{ {
EXPECT_EQ(0u, EXPECT_EQ(0u, MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount);
MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount);
{ {
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()), StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kIncrementalMark); StatsCollector::kIncrementalMark);
scope.DecreaseStartTimeForTesting( scope.DecreaseStartTimeForTesting(
v8::base::TimeDelta::FromMilliseconds(1)); v8::base::TimeDelta::FromMilliseconds(1));
} }
EXPECT_EQ(1u, EXPECT_EQ(1u, MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount);
MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount);
EXPECT_LT( EXPECT_LT(
0u, 0u,
MetricRecorderImpl::CppGCIncrementalMarkMetricSample_event.duration_us); MetricRecorderImpl::CppGCMainThreadIncrementalMark_event.duration_us);
} }
{ {
EXPECT_EQ(0u, EXPECT_EQ(0u,
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount); MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount);
{ {
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()), StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kIncrementalSweep); StatsCollector::kIncrementalSweep);
...@@ -98,18 +92,19 @@ TEST_F(MetricRecorderTest, IncrementalScopesReportedImmediately) { ...@@ -98,18 +92,19 @@ TEST_F(MetricRecorderTest, IncrementalScopesReportedImmediately) {
v8::base::TimeDelta::FromMilliseconds(1)); v8::base::TimeDelta::FromMilliseconds(1));
} }
EXPECT_EQ(1u, EXPECT_EQ(1u,
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount); MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount);
EXPECT_LT(0u, MetricRecorderImpl::CppGCIncrementalSweepMetricSample_event EXPECT_LT(
.duration_us); 0u,
MetricRecorderImpl::CppGCMainThreadIncrementalSweep_event.duration_us);
} }
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_callcount); EXPECT_EQ(0u, MetricRecorderImpl::CppGCFullCycle_callcount);
EndGC(0); EndGC(0);
} }
TEST_F(MetricRecorderTest, AtomicScopesNotReportedImmediately) { TEST_F(MetricRecorderTest, NonIncrementlaScopesNotReportedImmediately) {
MetricRecorderImpl::CppGCCycleEndMetricSamples_callcount = 0u; MetricRecorderImpl::CppGCFullCycle_callcount = 0u;
MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount = 0u; MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount = 0u;
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount = 0u; MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount = 0u;
StartGC(); StartGC();
{ {
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()), StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
...@@ -127,241 +122,157 @@ TEST_F(MetricRecorderTest, AtomicScopesNotReportedImmediately) { ...@@ -127,241 +122,157 @@ TEST_F(MetricRecorderTest, AtomicScopesNotReportedImmediately) {
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()), StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
StatsCollector::kAtomicSweep); StatsCollector::kAtomicSweep);
} }
EXPECT_EQ(0u, MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount); {
EXPECT_EQ(0u, StatsCollector::EnabledConcurrentScope scope(
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount); *Heap::From(GetHeap()), StatsCollector::kConcurrentMark);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_callcount); }
{
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); EndGC(0);
} }
TEST_F(MetricRecorderTest, CycleEndMetricsReportedOnGcEnd) { TEST_F(MetricRecorderTest, CycleEndMetricsReportedOnGcEnd) {
MetricRecorderImpl::CppGCCycleEndMetricSamples_callcount = 0u; MetricRecorderImpl::CppGCFullCycle_callcount = 0u;
MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount = 0u; MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount = 0u;
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount = 0u; MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount = 0u;
StartGC(); StartGC();
EndGC(0); EndGC(0);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCIncrementalMarkMetricSample_callcount); EXPECT_EQ(0u, MetricRecorderImpl::CppGCMainThreadIncrementalMark_callcount);
EXPECT_EQ(0u, EXPECT_EQ(0u, MetricRecorderImpl::CppGCMainThreadIncrementalSweep_callcount);
MetricRecorderImpl::CppGCIncrementalSweepMetricSample_callcount); EXPECT_EQ(1u, MetricRecorderImpl::CppGCFullCycle_callcount);
EXPECT_EQ(1u, MetricRecorderImpl::CppGCCycleEndMetricSamples_callcount);
} }
TEST_F(MetricRecorderTest, CycleEndHistogramReportsValuesForAtomicScopes) { TEST_F(MetricRecorderTest, CycleEndHistogramReportsCorrectValues) {
{ StartGC();
StartGC(); EndGC(1000);
EndGC(0); StartGC();
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);
}
{ {
StartGC(); StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
{ StatsCollector::kIncrementalMark);
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()), scope.DecreaseStartTimeForTesting(
StatsCollector::kAtomicWeak); v8::base::TimeDelta::FromMilliseconds(10));
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);
} }
{ {
StartGC(); StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
{ StatsCollector::kIncrementalSweep);
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()), scope.DecreaseStartTimeForTesting(
StatsCollector::kAtomicCompact); v8::base::TimeDelta::FromMilliseconds(20));
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);
} }
{ {
StartGC(); StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
{ StatsCollector::kAtomicMark);
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()), scope.DecreaseStartTimeForTesting(
StatsCollector::kAtomicSweep); v8::base::TimeDelta::FromMilliseconds(30));
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);
} }
{ {
StartGC(); StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
{ StatsCollector::kAtomicWeak);
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()), scope.DecreaseStartTimeForTesting(
StatsCollector::kIncrementalMark); v8::base::TimeDelta::FromMilliseconds(50));
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);
} }
{ {
StartGC(); StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
{ StatsCollector::kAtomicCompact);
StatsCollector::EnabledScope scope(*Heap::From(GetHeap()), scope.DecreaseStartTimeForTesting(
StatsCollector::kIncrementalSweep); v8::base::TimeDelta::FromMilliseconds(60));
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);
} }
}
TEST_F(MetricRecorderTest, ConcurrentSamplesAreReported) {
{ {
StartGC(); StatsCollector::EnabledScope scope(*Heap::From(GetHeap()),
EndGC(0); StatsCollector::kAtomicSweep);
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event scope.DecreaseStartTimeForTesting(
.concurrent_mark_us); v8::base::TimeDelta::FromMilliseconds(70));
EXPECT_EQ(0u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
.concurrent_sweep_us);
} }
{ {
StartGC(); StatsCollector::EnabledConcurrentScope scope(
{ *Heap::From(GetHeap()), StatsCollector::kConcurrentMark);
StatsCollector::EnabledConcurrentScope scope( scope.DecreaseStartTimeForTesting(
*Heap::From(GetHeap()), StatsCollector::kConcurrentMark); v8::base::TimeDelta::FromMilliseconds(80));
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);
} }
{ {
StartGC(); StatsCollector::EnabledConcurrentScope scope(
{ *Heap::From(GetHeap()), StatsCollector::kConcurrentSweep);
StatsCollector::EnabledConcurrentScope scope( scope.DecreaseStartTimeForTesting(
*Heap::From(GetHeap()), StatsCollector::kConcurrentSweep); v8::base::TimeDelta::FromMilliseconds(100));
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);
} }
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) { TEST_F(MetricRecorderTest, ObjectSizeMetricsNoAllocations) {
...@@ -371,23 +282,13 @@ TEST_F(MetricRecorderTest, ObjectSizeMetricsNoAllocations) { ...@@ -371,23 +282,13 @@ TEST_F(MetricRecorderTest, ObjectSizeMetricsNoAllocations) {
// Populate current event. // Populate current event.
StartGC(); StartGC();
EndGC(800); EndGC(800);
EXPECT_EQ(1000u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event EXPECT_EQ(1000u,
.objects_before_bytes); MetricRecorderImpl::CppGCFullCycle_event.objects.before_bytes);
EXPECT_EQ( EXPECT_EQ(800u, MetricRecorderImpl::CppGCFullCycle_event.objects.after_bytes);
800u, EXPECT_EQ(200u, MetricRecorderImpl::CppGCFullCycle_event.objects.freed_bytes);
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.objects_after_bytes); EXPECT_EQ(0u, MetricRecorderImpl::CppGCFullCycle_event.memory.before_bytes);
EXPECT_EQ( EXPECT_EQ(0u, MetricRecorderImpl::CppGCFullCycle_event.memory.after_bytes);
200u, EXPECT_EQ(0u, MetricRecorderImpl::CppGCFullCycle_event.memory.freed_bytes);
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);
} }
TEST_F(MetricRecorderTest, ObjectSizeMetricsWithAllocations) { TEST_F(MetricRecorderTest, ObjectSizeMetricsWithAllocations) {
...@@ -404,23 +305,13 @@ TEST_F(MetricRecorderTest, ObjectSizeMetricsWithAllocations) { ...@@ -404,23 +305,13 @@ TEST_F(MetricRecorderTest, ObjectSizeMetricsWithAllocations) {
stats->NotifyAllocatedMemory(1000); stats->NotifyAllocatedMemory(1000);
stats->NotifyFreedMemory(400); stats->NotifyFreedMemory(400);
stats->NotifySweepingCompleted(); stats->NotifySweepingCompleted();
EXPECT_EQ(1300u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event EXPECT_EQ(1300u,
.objects_before_bytes); MetricRecorderImpl::CppGCFullCycle_event.objects.before_bytes);
EXPECT_EQ( EXPECT_EQ(800, MetricRecorderImpl::CppGCFullCycle_event.objects.after_bytes);
800, EXPECT_EQ(500u, MetricRecorderImpl::CppGCFullCycle_event.objects.freed_bytes);
MetricRecorderImpl::CppGCCycleEndMetricSamples_event.objects_after_bytes); EXPECT_EQ(700u, MetricRecorderImpl::CppGCFullCycle_event.memory.before_bytes);
EXPECT_EQ( EXPECT_EQ(300u, MetricRecorderImpl::CppGCFullCycle_event.memory.after_bytes);
500u, EXPECT_EQ(400u, MetricRecorderImpl::CppGCFullCycle_event.memory.freed_bytes);
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);
} }
} // namespace internal } // 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