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) {
}
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) {
STATIC_ASSERT(Scope::FIRST_SCOPE == Scope::MC_INCREMENTAL);
......@@ -34,10 +37,20 @@ RuntimeCallCounterId GCTracer::RCSCounterFromScope(Scope::ScopeId 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)
: tracer_(tracer), scope_(scope) {
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;
runtime_stats_ = tracer_->heap_->isolate()->counters()->runtime_call_stats();
runtime_stats_->Enter(&timer_, GCTracer::RCSCounterFromScope(scope));
......@@ -46,30 +59,25 @@ GCTracer::Scope::Scope(GCTracer* tracer, ScopeId scope)
GCTracer::Scope::~Scope() {
tracer_->AddScopeSample(
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;
runtime_stats_->Leave(&timer_);
}
GCTracer::BackgroundScope::BackgroundScope(GCTracer* tracer, ScopeId scope)
: tracer_(tracer), scope_(scope), runtime_stats_enabled_(false) {
GCTracer::BackgroundScope::BackgroundScope(GCTracer* tracer, ScopeId scope,
RuntimeCallStats* runtime_stats)
: tracer_(tracer), scope_(scope), runtime_stats_(runtime_stats) {
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;
timer_.Start(&counter_, nullptr);
runtime_stats_enabled_ = true;
runtime_stats_->Enter(&timer_,
GCTracer::RCSCounterFromBackgroundScope(scope));
}
GCTracer::BackgroundScope::~BackgroundScope() {
double duration_ms =
tracer_->heap_->MonotonicallyIncreasingTimeInMs() - start_time_;
// TODO(cbruni): remove once we fully moved to a trace-based system.
if (V8_LIKELY(!runtime_stats_enabled_)) {
tracer_->AddBackgroundScopeSample(scope_, duration_ms, nullptr);
} else {
timer_.Stop();
tracer_->AddBackgroundScopeSample(scope_, duration_ms, &counter_);
}
tracer_->AddBackgroundScopeSample(scope_, duration_ms);
if (V8_LIKELY(runtime_stats_ == nullptr)) return;
runtime_stats_->Leave(&timer_);
}
const char* GCTracer::Scope::Name(ScopeId id) {
......@@ -170,7 +178,6 @@ GCTracer::GCTracer(Heap* heap)
current_.end_time = heap_->MonotonicallyIncreasingTimeInMs();
for (int i = 0; i < BackgroundScope::NUMBER_OF_SCOPES; i++) {
background_counter_[i].total_duration_ms = 0;
background_counter_[i].runtime_call_counter = RuntimeCallCounter(nullptr);
}
}
......@@ -204,7 +211,6 @@ void GCTracer::ResetForTesting() {
base::MutexGuard guard(&background_counter_mutex_);
for (int i = 0; i < BackgroundScope::NUMBER_OF_SCOPES; i++) {
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,
background_counter_[first_background_scope + i].total_duration_ms;
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(
BackgroundScope::ScopeId scope, double duration,
RuntimeCallCounter* runtime_call_counter) {
void GCTracer::AddBackgroundScopeSample(BackgroundScope::ScopeId scope,
double duration) {
base::MutexGuard guard(&background_counter_mutex_);
BackgroundCounter& counter = background_counter_[scope];
counter.total_duration_ms += duration;
if (runtime_call_counter) {
counter.runtime_call_counter.Add(runtime_call_counter);
}
}
void GCTracer::RecordGCPhasesHistograms(TimedHistogram* gc_timer) {
......
......@@ -32,7 +32,10 @@ enum ScavengeSpeedMode { kForAllObjects, kForSurvivedObjects };
GCTracer::Scope::Name(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"), \
GCTracer::BackgroundScope::Name(scope_id))
......@@ -82,7 +85,8 @@ class V8_EXPORT_PRIVATE GCTracer {
FIRST_TOP_MC_SCOPE = MC_CLEAR,
LAST_TOP_MC_SCOPE = MC_SWEEP,
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);
......@@ -113,7 +117,8 @@ class V8_EXPORT_PRIVATE GCTracer {
FIRST_MINOR_GC_BACKGROUND_SCOPE = MINOR_MC_BACKGROUND_EVACUATE_COPY,
LAST_MINOR_GC_BACKGROUND_SCOPE = SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL
};
BackgroundScope(GCTracer* tracer, ScopeId scope);
BackgroundScope(GCTracer* tracer, ScopeId scope,
RuntimeCallStats* runtime_stats);
~BackgroundScope();
static const char* Name(ScopeId id);
......@@ -123,8 +128,7 @@ class V8_EXPORT_PRIVATE GCTracer {
ScopeId scope_;
double start_time_;
RuntimeCallTimer timer_;
RuntimeCallCounter counter_;
bool runtime_stats_enabled_;
RuntimeCallStats* runtime_stats_;
DISALLOW_COPY_AND_ASSIGN(BackgroundScope);
};
......@@ -206,6 +210,8 @@ class V8_EXPORT_PRIVATE GCTracer {
double optional_speed);
static RuntimeCallCounterId RCSCounterFromScope(Scope::ScopeId id);
static RuntimeCallCounterId RCSCounterFromBackgroundScope(
BackgroundScope::ScopeId id);
explicit GCTracer(Heap* heap);
......@@ -340,13 +346,15 @@ class V8_EXPORT_PRIVATE GCTracer {
}
}
void AddBackgroundScopeSample(BackgroundScope::ScopeId scope, double duration,
RuntimeCallCounter* runtime_call_counter);
void AddBackgroundScopeSample(BackgroundScope::ScopeId scope,
double duration);
void RecordGCPhasesHistograms(TimedHistogram* gc_timer);
void RecordEmbedderSpeed(size_t bytes, double duration);
WorkerThreadRuntimeCallStats* worker_thread_runtime_call_stats();
private:
FRIEND_TEST(GCTracer, AverageSpeed);
FRIEND_TEST(GCTracerTest, AllocationThroughput);
......@@ -369,7 +377,6 @@ class V8_EXPORT_PRIVATE GCTracer {
struct BackgroundCounter {
double total_duration_ms;
RuntimeCallCounter runtime_call_counter;
};
// Returns the average speed of the events in the buffer.
......
......@@ -355,11 +355,9 @@ TEST_F(GCTracerTest, BackgroundScavengerScope) {
tracer->Start(SCAVENGER, GarbageCollectionReason::kTesting,
"collector unittest");
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL, 10,
nullptr);
GCTracer::BackgroundScope::SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL, 10);
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL, 1,
nullptr);
GCTracer::BackgroundScope::SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL, 1);
tracer->Stop(SCAVENGER);
EXPECT_DOUBLE_EQ(
11, tracer->current_
......@@ -372,20 +370,19 @@ TEST_F(GCTracerTest, BackgroundMinorMCScope) {
tracer->Start(MINOR_MARK_COMPACTOR, GarbageCollectionReason::kTesting,
"collector unittest");
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_MARKING, 10, nullptr);
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_MARKING, 10);
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_MARKING, 1, nullptr);
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_MARKING, 1);
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_COPY, 20,
nullptr);
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_COPY, 20);
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_COPY, 2, nullptr);
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_COPY, 2);
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_UPDATE_POINTERS,
30, nullptr);
30);
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MINOR_MC_BACKGROUND_EVACUATE_UPDATE_POINTERS,
3, nullptr);
3);
tracer->Stop(MINOR_MARK_COMPACTOR);
EXPECT_DOUBLE_EQ(
11,
......@@ -402,33 +399,31 @@ TEST_F(GCTracerTest, BackgroundMajorMCScope) {
GCTracer* tracer = i_isolate()->heap()->tracer();
tracer->ResetForTesting();
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_MARKING, 100, nullptr);
GCTracer::BackgroundScope::MC_BACKGROUND_MARKING, 100);
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_SWEEPING, 200, nullptr);
GCTracer::BackgroundScope::MC_BACKGROUND_SWEEPING, 200);
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_MARKING, 10, nullptr);
GCTracer::BackgroundScope::MC_BACKGROUND_MARKING, 10);
// Scavenger should not affect the major mark-compact scopes.
tracer->Start(SCAVENGER, GarbageCollectionReason::kTesting,
"collector unittest");
tracer->Stop(SCAVENGER);
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_SWEEPING, 20, nullptr);
GCTracer::BackgroundScope::MC_BACKGROUND_SWEEPING, 20);
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_MARKING, 1, nullptr);
GCTracer::BackgroundScope::MC_BACKGROUND_MARKING, 1);
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_SWEEPING, 2, nullptr);
GCTracer::BackgroundScope::MC_BACKGROUND_SWEEPING, 2);
tracer->Start(MARK_COMPACTOR, GarbageCollectionReason::kTesting,
"collector unittest");
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_COPY, 30, nullptr);
GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_COPY, 30);
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_COPY, 3, nullptr);
GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_COPY, 3);
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_UPDATE_POINTERS, 40,
nullptr);
GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_UPDATE_POINTERS, 40);
tracer->AddBackgroundScopeSample(
GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_UPDATE_POINTERS, 4,
nullptr);
GCTracer::BackgroundScope::MC_BACKGROUND_EVACUATE_UPDATE_POINTERS, 4);
tracer->Stop(MARK_COMPACTOR);
EXPECT_DOUBLE_EQ(
111, tracer->current_.scopes[GCTracer::Scope::MC_BACKGROUND_MARKING]);
......@@ -448,7 +443,7 @@ class ThreadWithBackgroundScope final : public base::Thread {
: Thread(Options("ThreadWithBackgroundScope")), tracer_(tracer) {}
void Run() override {
GCTracer::BackgroundScope scope(
tracer_, GCTracer::BackgroundScope::MC_BACKGROUND_MARKING);
tracer_, GCTracer::BackgroundScope::MC_BACKGROUND_MARKING, nullptr);
}
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