Commit ae1d7f8e authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

cppgc: Add additional memory metrics

Bug: chromium:1056170
Change-Id: Ia312e96b421d596d25cccf584c2df823bd9e1ea0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2652498Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72367}
parent c7375b20
......@@ -114,6 +114,7 @@ NormalPage* NormalPage::Create(PageBackend* page_backend,
void* memory = page_backend->AllocateNormalPageMemory(space->index());
auto* normal_page = new (memory) NormalPage(space->raw_heap()->heap(), space);
normal_page->SynchronizedStore();
normal_page->heap()->stats_collector()->NotifyAllocatedMemory(kPageSize);
return normal_page;
}
......@@ -199,6 +200,8 @@ LargePage* LargePage::Create(PageBackend* page_backend, LargePageSpace* space,
void* memory = page_backend->AllocateLargePageMemory(allocation_size);
LargePage* page = new (memory) LargePage(heap, space, size);
page->SynchronizedStore();
page->heap()->stats_collector()->NotifyAllocatedMemory(
LargePageAllocationSize(page->PayloadSize()));
return page;
}
......
......@@ -33,6 +33,8 @@ class MetricRecorder {
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;
};
......
......@@ -100,6 +100,11 @@ void StatsCollector::NotifyMarkingCompleted(size_t marked_bytes) {
allocated_bytes_since_safepoint_ = 0;
explicitly_freed_bytes_since_safepoint_ = 0;
DCHECK_LE(memory_freed_bytes_since_end_of_marking_, memory_allocated_bytes_);
memory_allocated_bytes_ -= memory_freed_bytes_since_end_of_marking_;
current_.memory_size_before_sweep_bytes = memory_allocated_bytes_;
memory_freed_bytes_since_end_of_marking_ = 0;
ForAllAllocationObservers([marked_bytes](AllocationObserver* observer) {
observer->ResetAllocatedObjectSize(marked_bytes);
});
......@@ -108,7 +113,6 @@ void StatsCollector::NotifyMarkingCompleted(size_t marked_bytes) {
// execution of ResetAllocatedObjectSize.
allocated_bytes_since_end_of_marking_ = 0;
time_of_last_end_of_marking_ = v8::base::TimeTicks::Now();
freed_memory_bytes_since_end_of_marking_ = 0;
}
double StatsCollector::GetRecentAllocationSpeedInBytesPerMs() const {
......@@ -138,7 +142,10 @@ void StatsCollector::NotifySweepingCompleted() {
previous_.marked_bytes /* objects_after */,
previous_.object_size_before_sweep_bytes -
previous_.marked_bytes /* objects_freed */,
freed_memory_bytes_since_end_of_marking_ /* memory_freed */};
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 */};
metric_recorder_->AddMainThreadEvent(event);
}
}
......@@ -156,8 +163,12 @@ size_t StatsCollector::allocated_object_size() const {
allocated_bytes_since_end_of_marking_);
}
void StatsCollector::NotifyAllocatedMemory(int64_t size) {
memory_allocated_bytes_ += size;
}
void StatsCollector::NotifyFreedMemory(int64_t size) {
freed_memory_bytes_since_end_of_marking_ += size;
memory_freed_bytes_since_end_of_marking_ += size;
}
void StatsCollector::RecordHistogramSample(ScopeId scope_id_,
......
......@@ -105,6 +105,7 @@ class V8_EXPORT_PRIVATE StatsCollector final {
// Marked bytes collected during marking.
size_t marked_bytes = 0;
size_t object_size_before_sweep_bytes = -1;
size_t memory_size_before_sweep_bytes = -1;
};
private:
......@@ -270,6 +271,7 @@ class V8_EXPORT_PRIVATE StatsCollector final {
const Event& GetPreviousEventForTesting() const { return previous_; }
void NotifyAllocatedMemory(int64_t);
void NotifyFreedMemory(int64_t);
void SetMetricRecorderForTesting(
......@@ -306,7 +308,8 @@ class V8_EXPORT_PRIVATE StatsCollector final {
int64_t allocated_bytes_since_safepoint_ = 0;
int64_t explicitly_freed_bytes_since_safepoint_ = 0;
int64_t freed_memory_bytes_since_end_of_marking_ = 0;
int64_t memory_allocated_bytes_ = 0;
int64_t memory_freed_bytes_since_end_of_marking_ = 0;
// vector to allow fast iteration of observers. Register/Unregisters only
// happens on startup/teardown.
......
......@@ -379,6 +379,12 @@ TEST_F(MetricRecorderTest, ObjectSizeMetricsNoAllocations) {
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);
......@@ -391,9 +397,11 @@ TEST_F(MetricRecorderTest, ObjectSizeMetricsWithAllocations) {
// Populate current event.
StartGC();
stats->NotifyAllocation(300);
stats->NotifyAllocatedMemory(1400);
stats->NotifyFreedMemory(700);
stats->NotifyMarkingCompleted(800);
stats->NotifyAllocation(150);
stats->NotifyAllocatedMemory(1000);
stats->NotifyFreedMemory(400);
stats->NotifySweepingCompleted();
EXPECT_EQ(1300u, MetricRecorderImpl::CppGCCycleEndMetricSamples_event
......@@ -404,6 +412,12 @@ TEST_F(MetricRecorderTest, ObjectSizeMetricsWithAllocations) {
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);
......
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