Commit 32939550 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[heap, tracing] Use WorkerThreadRuntimeCallStatsScope in background GC

Before this CL the main thread fetched the background GC stats and
added them to the main runtime-call-stats table. This resulted
in background GC stats showing up in the main thread trace.

This CL switches the background GC stats to use worker thread runtime-
calls-stats table. This is now consistent with other background
components of V8 suchs background compiler and parser.

Bug: v8:9508
Change-Id: Ic4c0685ded6024f78d0f22f81419fd5677202f25
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1776083Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63459}
parent a5811358
...@@ -26,6 +26,9 @@ static size_t CountTotalHolesSize(Heap* heap) { ...@@ -26,6 +26,9 @@ static size_t CountTotalHolesSize(Heap* heap) {
} }
return holes_size; return holes_size;
} }
WorkerThreadRuntimeCallStats* GCTracer::worker_thread_runtime_call_stats() {
return heap_->isolate()->counters()->worker_thread_runtime_call_stats();
}
RuntimeCallCounterId GCTracer::RCSCounterFromScope(Scope::ScopeId id) { RuntimeCallCounterId GCTracer::RCSCounterFromScope(Scope::ScopeId id) {
STATIC_ASSERT(Scope::FIRST_SCOPE == Scope::MC_INCREMENTAL); STATIC_ASSERT(Scope::FIRST_SCOPE == Scope::MC_INCREMENTAL);
...@@ -34,10 +37,20 @@ RuntimeCallCounterId GCTracer::RCSCounterFromScope(Scope::ScopeId id) { ...@@ -34,10 +37,20 @@ RuntimeCallCounterId GCTracer::RCSCounterFromScope(Scope::ScopeId id) {
static_cast<int>(id)); static_cast<int>(id));
} }
RuntimeCallCounterId GCTracer::RCSCounterFromBackgroundScope(
BackgroundScope::ScopeId id) {
STATIC_ASSERT(Scope::FIRST_BACKGROUND_SCOPE ==
Scope::BACKGROUND_ARRAY_BUFFER_FREE);
STATIC_ASSERT(
0 == static_cast<int>(BackgroundScope::BACKGROUND_ARRAY_BUFFER_FREE));
return static_cast<RuntimeCallCounterId>(
static_cast<int>(RCSCounterFromScope(Scope::FIRST_BACKGROUND_SCOPE)) +
static_cast<int>(id));
}
GCTracer::Scope::Scope(GCTracer* tracer, ScopeId scope) GCTracer::Scope::Scope(GCTracer* tracer, ScopeId scope)
: tracer_(tracer), scope_(scope) { : tracer_(tracer), scope_(scope) {
start_time_ = tracer_->heap_->MonotonicallyIncreasingTimeInMs(); start_time_ = tracer_->heap_->MonotonicallyIncreasingTimeInMs();
// TODO(cbruni): remove once we fully moved to a trace-based system.
if (V8_LIKELY(!TracingFlags::is_runtime_stats_enabled())) return; if (V8_LIKELY(!TracingFlags::is_runtime_stats_enabled())) return;
runtime_stats_ = tracer_->heap_->isolate()->counters()->runtime_call_stats(); runtime_stats_ = tracer_->heap_->isolate()->counters()->runtime_call_stats();
runtime_stats_->Enter(&timer_, GCTracer::RCSCounterFromScope(scope)); runtime_stats_->Enter(&timer_, GCTracer::RCSCounterFromScope(scope));
...@@ -46,30 +59,25 @@ GCTracer::Scope::Scope(GCTracer* tracer, ScopeId scope) ...@@ -46,30 +59,25 @@ GCTracer::Scope::Scope(GCTracer* tracer, ScopeId scope)
GCTracer::Scope::~Scope() { GCTracer::Scope::~Scope() {
tracer_->AddScopeSample( tracer_->AddScopeSample(
scope_, tracer_->heap_->MonotonicallyIncreasingTimeInMs() - start_time_); scope_, tracer_->heap_->MonotonicallyIncreasingTimeInMs() - start_time_);
// TODO(cbruni): remove once we fully moved to a trace-based system.
if (V8_LIKELY(runtime_stats_ == nullptr)) return; if (V8_LIKELY(runtime_stats_ == nullptr)) return;
runtime_stats_->Leave(&timer_); runtime_stats_->Leave(&timer_);
} }
GCTracer::BackgroundScope::BackgroundScope(GCTracer* tracer, ScopeId scope) GCTracer::BackgroundScope::BackgroundScope(GCTracer* tracer, ScopeId scope,
: tracer_(tracer), scope_(scope), runtime_stats_enabled_(false) { RuntimeCallStats* runtime_stats)
: tracer_(tracer), scope_(scope), runtime_stats_(runtime_stats) {
start_time_ = tracer_->heap_->MonotonicallyIncreasingTimeInMs(); start_time_ = tracer_->heap_->MonotonicallyIncreasingTimeInMs();
// TODO(cbruni): remove once we fully moved to a trace-based system.
if (V8_LIKELY(!TracingFlags::is_runtime_stats_enabled())) return; if (V8_LIKELY(!TracingFlags::is_runtime_stats_enabled())) return;
timer_.Start(&counter_, nullptr); runtime_stats_->Enter(&timer_,
runtime_stats_enabled_ = true; GCTracer::RCSCounterFromBackgroundScope(scope));
} }
GCTracer::BackgroundScope::~BackgroundScope() { GCTracer::BackgroundScope::~BackgroundScope() {
double duration_ms = double duration_ms =
tracer_->heap_->MonotonicallyIncreasingTimeInMs() - start_time_; tracer_->heap_->MonotonicallyIncreasingTimeInMs() - start_time_;
// TODO(cbruni): remove once we fully moved to a trace-based system. tracer_->AddBackgroundScopeSample(scope_, duration_ms);
if (V8_LIKELY(!runtime_stats_enabled_)) { if (V8_LIKELY(runtime_stats_ == nullptr)) return;
tracer_->AddBackgroundScopeSample(scope_, duration_ms, nullptr); runtime_stats_->Leave(&timer_);
} else {
timer_.Stop();
tracer_->AddBackgroundScopeSample(scope_, duration_ms, &counter_);
}
} }
const char* GCTracer::Scope::Name(ScopeId id) { const char* GCTracer::Scope::Name(ScopeId id) {
...@@ -170,7 +178,6 @@ GCTracer::GCTracer(Heap* heap) ...@@ -170,7 +178,6 @@ GCTracer::GCTracer(Heap* heap)
current_.end_time = heap_->MonotonicallyIncreasingTimeInMs(); current_.end_time = heap_->MonotonicallyIncreasingTimeInMs();
for (int i = 0; i < BackgroundScope::NUMBER_OF_SCOPES; i++) { for (int i = 0; i < BackgroundScope::NUMBER_OF_SCOPES; i++) {
background_counter_[i].total_duration_ms = 0; background_counter_[i].total_duration_ms = 0;
background_counter_[i].runtime_call_counter = RuntimeCallCounter(nullptr);
} }
} }
...@@ -204,7 +211,6 @@ void GCTracer::ResetForTesting() { ...@@ -204,7 +211,6 @@ void GCTracer::ResetForTesting() {
base::MutexGuard guard(&background_counter_mutex_); base::MutexGuard guard(&background_counter_mutex_);
for (int i = 0; i < BackgroundScope::NUMBER_OF_SCOPES; i++) { for (int i = 0; i < BackgroundScope::NUMBER_OF_SCOPES; i++) {
background_counter_[i].total_duration_ms = 0; background_counter_[i].total_duration_ms = 0;
background_counter_[i].runtime_call_counter.Reset();
} }
} }
...@@ -1144,30 +1150,13 @@ void GCTracer::FetchBackgroundCounters(int first_global_scope, ...@@ -1144,30 +1150,13 @@ void GCTracer::FetchBackgroundCounters(int first_global_scope,
background_counter_[first_background_scope + i].total_duration_ms; background_counter_[first_background_scope + i].total_duration_ms;
background_counter_[first_background_scope + i].total_duration_ms = 0; background_counter_[first_background_scope + i].total_duration_ms = 0;
} }
if (V8_LIKELY(!TracingFlags::is_runtime_stats_enabled())) return;
RuntimeCallStats* runtime_stats =
heap_->isolate()->counters()->runtime_call_stats();
if (!runtime_stats) return;
for (int i = 0; i < background_mc_scopes; i++) {
runtime_stats
->GetCounter(GCTracer::RCSCounterFromScope(
static_cast<Scope::ScopeId>(first_global_scope + i)))
->Add(&background_counter_[first_background_scope + i]
.runtime_call_counter);
background_counter_[first_background_scope + i]
.runtime_call_counter.Reset();
}
} }
void GCTracer::AddBackgroundScopeSample( void GCTracer::AddBackgroundScopeSample(BackgroundScope::ScopeId scope,
BackgroundScope::ScopeId scope, double duration, double duration) {
RuntimeCallCounter* runtime_call_counter) {
base::MutexGuard guard(&background_counter_mutex_); base::MutexGuard guard(&background_counter_mutex_);
BackgroundCounter& counter = background_counter_[scope]; BackgroundCounter& counter = background_counter_[scope];
counter.total_duration_ms += duration; counter.total_duration_ms += duration;
if (runtime_call_counter) {
counter.runtime_call_counter.Add(runtime_call_counter);
}
} }
void GCTracer::RecordGCPhasesHistograms(TimedHistogram* gc_timer) { void GCTracer::RecordGCPhasesHistograms(TimedHistogram* gc_timer) {
......
...@@ -32,7 +32,10 @@ enum ScavengeSpeedMode { kForAllObjects, kForSurvivedObjects }; ...@@ -32,7 +32,10 @@ enum ScavengeSpeedMode { kForAllObjects, kForSurvivedObjects };
GCTracer::Scope::Name(gc_tracer_scope_id)) GCTracer::Scope::Name(gc_tracer_scope_id))
#define TRACE_BACKGROUND_GC(tracer, scope_id) \ #define TRACE_BACKGROUND_GC(tracer, scope_id) \
GCTracer::BackgroundScope background_scope(tracer, scope_id); \ WorkerThreadRuntimeCallStatsScope runtime_call_stats_scope( \
tracer->worker_thread_runtime_call_stats()); \
GCTracer::BackgroundScope background_scope(tracer, scope_id, \
runtime_call_stats_scope.Get()); \
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.gc"), \ TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.gc"), \
GCTracer::BackgroundScope::Name(scope_id)) GCTracer::BackgroundScope::Name(scope_id))
...@@ -82,7 +85,8 @@ class V8_EXPORT_PRIVATE GCTracer { ...@@ -82,7 +85,8 @@ class V8_EXPORT_PRIVATE GCTracer {
FIRST_TOP_MC_SCOPE = MC_CLEAR, FIRST_TOP_MC_SCOPE = MC_CLEAR,
LAST_TOP_MC_SCOPE = MC_SWEEP, LAST_TOP_MC_SCOPE = MC_SWEEP,
FIRST_MINOR_GC_BACKGROUND_SCOPE = MINOR_MC_BACKGROUND_EVACUATE_COPY, FIRST_MINOR_GC_BACKGROUND_SCOPE = MINOR_MC_BACKGROUND_EVACUATE_COPY,
LAST_MINOR_GC_BACKGROUND_SCOPE = SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL LAST_MINOR_GC_BACKGROUND_SCOPE = SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL,
FIRST_BACKGROUND_SCOPE = FIRST_GENERAL_BACKGROUND_SCOPE
}; };
Scope(GCTracer* tracer, ScopeId scope); Scope(GCTracer* tracer, ScopeId scope);
...@@ -113,7 +117,8 @@ class V8_EXPORT_PRIVATE GCTracer { ...@@ -113,7 +117,8 @@ class V8_EXPORT_PRIVATE GCTracer {
FIRST_MINOR_GC_BACKGROUND_SCOPE = MINOR_MC_BACKGROUND_EVACUATE_COPY, FIRST_MINOR_GC_BACKGROUND_SCOPE = MINOR_MC_BACKGROUND_EVACUATE_COPY,
LAST_MINOR_GC_BACKGROUND_SCOPE = SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL LAST_MINOR_GC_BACKGROUND_SCOPE = SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL
}; };
BackgroundScope(GCTracer* tracer, ScopeId scope); BackgroundScope(GCTracer* tracer, ScopeId scope,
RuntimeCallStats* runtime_stats);
~BackgroundScope(); ~BackgroundScope();
static const char* Name(ScopeId id); static const char* Name(ScopeId id);
...@@ -123,8 +128,7 @@ class V8_EXPORT_PRIVATE GCTracer { ...@@ -123,8 +128,7 @@ class V8_EXPORT_PRIVATE GCTracer {
ScopeId scope_; ScopeId scope_;
double start_time_; double start_time_;
RuntimeCallTimer timer_; RuntimeCallTimer timer_;
RuntimeCallCounter counter_; RuntimeCallStats* runtime_stats_;
bool runtime_stats_enabled_;
DISALLOW_COPY_AND_ASSIGN(BackgroundScope); DISALLOW_COPY_AND_ASSIGN(BackgroundScope);
}; };
...@@ -206,6 +210,8 @@ class V8_EXPORT_PRIVATE GCTracer { ...@@ -206,6 +210,8 @@ class V8_EXPORT_PRIVATE GCTracer {
double optional_speed); double optional_speed);
static RuntimeCallCounterId RCSCounterFromScope(Scope::ScopeId id); static RuntimeCallCounterId RCSCounterFromScope(Scope::ScopeId id);
static RuntimeCallCounterId RCSCounterFromBackgroundScope(
BackgroundScope::ScopeId id);
explicit GCTracer(Heap* heap); explicit GCTracer(Heap* heap);
...@@ -340,13 +346,15 @@ class V8_EXPORT_PRIVATE GCTracer { ...@@ -340,13 +346,15 @@ class V8_EXPORT_PRIVATE GCTracer {
} }
} }
void AddBackgroundScopeSample(BackgroundScope::ScopeId scope, double duration, void AddBackgroundScopeSample(BackgroundScope::ScopeId scope,
RuntimeCallCounter* runtime_call_counter); double duration);
void RecordGCPhasesHistograms(TimedHistogram* gc_timer); void RecordGCPhasesHistograms(TimedHistogram* gc_timer);
void RecordEmbedderSpeed(size_t bytes, double duration); void RecordEmbedderSpeed(size_t bytes, double duration);
WorkerThreadRuntimeCallStats* worker_thread_runtime_call_stats();
private: private:
FRIEND_TEST(GCTracer, AverageSpeed); FRIEND_TEST(GCTracer, AverageSpeed);
FRIEND_TEST(GCTracerTest, AllocationThroughput); FRIEND_TEST(GCTracerTest, AllocationThroughput);
...@@ -369,7 +377,6 @@ class V8_EXPORT_PRIVATE GCTracer { ...@@ -369,7 +377,6 @@ class V8_EXPORT_PRIVATE GCTracer {
struct BackgroundCounter { struct BackgroundCounter {
double total_duration_ms; double total_duration_ms;
RuntimeCallCounter runtime_call_counter;
}; };
// Returns the average speed of the events in the buffer. // Returns the average speed of the events in the buffer.
......
...@@ -355,11 +355,9 @@ TEST_F(GCTracerTest, BackgroundScavengerScope) { ...@@ -355,11 +355,9 @@ TEST_F(GCTracerTest, BackgroundScavengerScope) {
tracer->Start(SCAVENGER, GarbageCollectionReason::kTesting, tracer->Start(SCAVENGER, GarbageCollectionReason::kTesting,
"collector unittest"); "collector unittest");
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL, 10, GCTracer::BackgroundScope::SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL, 10);
nullptr);
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL, 1, GCTracer::BackgroundScope::SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL, 1);
nullptr);
tracer->Stop(SCAVENGER); tracer->Stop(SCAVENGER);
EXPECT_DOUBLE_EQ( EXPECT_DOUBLE_EQ(
11, tracer->current_ 11, tracer->current_
...@@ -372,20 +370,19 @@ TEST_F(GCTracerTest, BackgroundMinorMCScope) { ...@@ -372,20 +370,19 @@ TEST_F(GCTracerTest, BackgroundMinorMCScope) {
tracer->Start(MINOR_MARK_COMPACTOR, GarbageCollectionReason::kTesting, tracer->Start(MINOR_MARK_COMPACTOR, GarbageCollectionReason::kTesting,
"collector unittest"); "collector unittest");
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_MARKING, 10, nullptr); GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_MARKING, 10);
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_MARKING, 1, nullptr); GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_MARKING, 1);
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_COPY, 20, GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_COPY, 20);
nullptr);
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_COPY, 2, nullptr); GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_COPY, 2);
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_UPDATE_POINTERS, GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_UPDATE_POINTERS,
30, nullptr); 30);
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_UPDATE_POINTERS, GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_UPDATE_POINTERS,
3, nullptr); 3);
tracer->Stop(MINOR_MARK_COMPACTOR); tracer->Stop(MINOR_MARK_COMPACTOR);
EXPECT_DOUBLE_EQ( EXPECT_DOUBLE_EQ(
11, 11,
...@@ -402,33 +399,31 @@ TEST_F(GCTracerTest, BackgroundMajorMCScope) { ...@@ -402,33 +399,31 @@ TEST_F(GCTracerTest, BackgroundMajorMCScope) {
GCTracer* tracer = i_isolate()->heap()->tracer(); GCTracer* tracer = i_isolate()->heap()->tracer();
tracer->ResetForTesting(); tracer->ResetForTesting();
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_MARKING, 100, nullptr); GCTracer::BackgroundScope::MC_BACKGROUND_MARKING, 100);
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_SWEEPING, 200, nullptr); GCTracer::BackgroundScope::MC_BACKGROUND_SWEEPING, 200);
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_MARKING, 10, nullptr); GCTracer::BackgroundScope::MC_BACKGROUND_MARKING, 10);
// Scavenger should not affect the major mark-compact scopes. // Scavenger should not affect the major mark-compact scopes.
tracer->Start(SCAVENGER, GarbageCollectionReason::kTesting, tracer->Start(SCAVENGER, GarbageCollectionReason::kTesting,
"collector unittest"); "collector unittest");
tracer->Stop(SCAVENGER); tracer->Stop(SCAVENGER);
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_SWEEPING, 20, nullptr); GCTracer::BackgroundScope::MC_BACKGROUND_SWEEPING, 20);
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_MARKING, 1, nullptr); GCTracer::BackgroundScope::MC_BACKGROUND_MARKING, 1);
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_SWEEPING, 2, nullptr); GCTracer::BackgroundScope::MC_BACKGROUND_SWEEPING, 2);
tracer->Start(MARK_COMPACTOR, GarbageCollectionReason::kTesting, tracer->Start(MARK_COMPACTOR, GarbageCollectionReason::kTesting,
"collector unittest"); "collector unittest");
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_COPY, 30, nullptr); GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_COPY, 30);
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_COPY, 3, nullptr); GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_COPY, 3);
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_UPDATE_POINTERS, 40, GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_UPDATE_POINTERS, 40);
nullptr);
tracer->AddBackgroundScopeSample( tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_UPDATE_POINTERS, 4, GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_UPDATE_POINTERS, 4);
nullptr);
tracer->Stop(MARK_COMPACTOR); tracer->Stop(MARK_COMPACTOR);
EXPECT_DOUBLE_EQ( EXPECT_DOUBLE_EQ(
111, tracer->current_.scopes[GCTracer::Scope::MC_BACKGROUND_MARKING]); 111, tracer->current_.scopes[GCTracer::Scope::MC_BACKGROUND_MARKING]);
...@@ -448,7 +443,7 @@ class ThreadWithBackgroundScope final : public base::Thread { ...@@ -448,7 +443,7 @@ class ThreadWithBackgroundScope final : public base::Thread {
: Thread(Options("ThreadWithBackgroundScope")), tracer_(tracer) {} : Thread(Options("ThreadWithBackgroundScope")), tracer_(tracer) {}
void Run() override { void Run() override {
GCTracer::BackgroundScope scope( GCTracer::BackgroundScope scope(
tracer_, GCTracer::BackgroundScope::MC_BACKGROUND_MARKING); tracer_, GCTracer::BackgroundScope::MC_BACKGROUND_MARKING, nullptr);
} }
private: private:
......
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