Commit 85962e45 authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

heap: Prepare scopes for epoch-based metrics

Epoch based metrics will rely on "forced" tag (currently we wrongly
account event that should be forced as non-forced) and a unique
epoch id.

Bug: 986235
Change-Id: I3156eecf7e4dcca12a9d2f11ea82b380ded46f5e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2351918
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Reviewed-by: default avatarAnton Bikineev <bikineev@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797372}
parent ee9ef9e5
...@@ -90,14 +90,21 @@ void ThreadHeapStatsCollector::DecreaseAllocatedSpace(size_t bytes) { ...@@ -90,14 +90,21 @@ void ThreadHeapStatsCollector::DecreaseAllocatedSpace(size_t bytes) {
}); });
} }
ThreadHeapStatsCollector::Event::Event() {
static std::atomic<size_t> counter{0};
unique_id = counter.fetch_add(1);
}
void ThreadHeapStatsCollector::NotifyMarkingStarted( void ThreadHeapStatsCollector::NotifyMarkingStarted(
BlinkGC::CollectionType collection_type, BlinkGC::CollectionType collection_type,
BlinkGC::GCReason reason) { BlinkGC::GCReason reason,
bool is_forced_gc) {
DCHECK(!is_started_); DCHECK(!is_started_);
DCHECK(current_.marking_time().is_zero()); DCHECK(current_.marking_time().is_zero());
is_started_ = true; is_started_ = true;
current_.reason = reason; current_.reason = reason;
current_.collection_type = collection_type; current_.collection_type = collection_type;
current_.is_forced_gc = is_forced_gc;
} }
void ThreadHeapStatsCollector::NotifyMarkingCompleted(size_t marked_bytes) { void ThreadHeapStatsCollector::NotifyMarkingCompleted(size_t marked_bytes) {
......
...@@ -220,6 +220,8 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector { ...@@ -220,6 +220,8 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector {
// GCs. E.g., |atomic_marking_time()| report the marking time of the atomic // GCs. E.g., |atomic_marking_time()| report the marking time of the atomic
// phase, independent of whether the GC was a stand-alone or unified heap GC. // phase, independent of whether the GC was a stand-alone or unified heap GC.
struct PLATFORM_EXPORT Event { struct PLATFORM_EXPORT Event {
Event();
// Overall time spent in the GC cycle. This includes marking time as well as // Overall time spent in the GC cycle. This includes marking time as well as
// sweeping time. // sweeping time.
base::TimeDelta gc_cycle_time() const; base::TimeDelta gc_cycle_time() const;
...@@ -267,6 +269,7 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector { ...@@ -267,6 +269,7 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector {
double marking_time_in_bytes_per_second() const; double marking_time_in_bytes_per_second() const;
// Marked bytes collected during sweeping. // Marked bytes collected during sweeping.
size_t unique_id = -1;
size_t marked_bytes = 0; size_t marked_bytes = 0;
size_t compaction_freed_bytes = 0; size_t compaction_freed_bytes = 0;
size_t compaction_freed_pages = 0; size_t compaction_freed_pages = 0;
...@@ -280,10 +283,13 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector { ...@@ -280,10 +283,13 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector {
size_t partition_alloc_bytes_before_sweeping = 0; size_t partition_alloc_bytes_before_sweeping = 0;
double live_object_rate = 0; double live_object_rate = 0;
base::TimeDelta gc_nested_in_v8; base::TimeDelta gc_nested_in_v8;
bool is_forced_gc = true;
}; };
// Indicates a new garbage collection cycle. // Indicates a new garbage collection cycle.
void NotifyMarkingStarted(BlinkGC::CollectionType, BlinkGC::GCReason); void NotifyMarkingStarted(BlinkGC::CollectionType,
BlinkGC::GCReason,
bool is_forced_gc);
// Indicates that marking of the current garbage collection cycle is // Indicates that marking of the current garbage collection cycle is
// completed. // completed.
...@@ -437,8 +443,10 @@ template <ThreadHeapStatsCollector::TraceCategory trace_category, ...@@ -437,8 +443,10 @@ template <ThreadHeapStatsCollector::TraceCategory trace_category,
ThreadHeapStatsCollector::ScopeContext scope_category> ThreadHeapStatsCollector::ScopeContext scope_category>
void ThreadHeapStatsCollector::InternalScope<trace_category, void ThreadHeapStatsCollector::InternalScope<trace_category,
scope_category>::StopTrace() { scope_category>::StopTrace() {
TRACE_EVENT_END0(TraceCategory(), TRACE_EVENT_END2(TraceCategory(),
ToString(id_, tracer_->current_.collection_type)); ToString(id_, tracer_->current_.collection_type), "epoch",
tracer_->current_.unique_id, "forced",
tracer_->current_.is_forced_gc);
} }
template <ThreadHeapStatsCollector::TraceCategory trace_category, template <ThreadHeapStatsCollector::TraceCategory trace_category,
......
...@@ -265,8 +265,8 @@ class TestGCScope : public TestGCCollectGarbageScope { ...@@ -265,8 +265,8 @@ class TestGCScope : public TestGCCollectGarbageScope {
explicit TestGCScope(BlinkGC::StackState state) explicit TestGCScope(BlinkGC::StackState state)
: TestGCCollectGarbageScope(state) { : TestGCCollectGarbageScope(state) {
ThreadState::Current()->Heap().stats_collector()->NotifyMarkingStarted( ThreadState::Current()->Heap().stats_collector()->NotifyMarkingStarted(
BlinkGC::CollectionType::kMajor, BlinkGC::CollectionType::kMajor, BlinkGC::GCReason::kForcedGCForTesting,
BlinkGC::GCReason::kForcedGCForTesting); true /* is_forced_gc */);
ThreadState::Current()->AtomicPauseMarkPrologue( ThreadState::Current()->AtomicPauseMarkPrologue(
BlinkGC::CollectionType::kMajor, state, BlinkGC::kAtomicMarking, BlinkGC::CollectionType::kMajor, state, BlinkGC::kAtomicMarking,
BlinkGC::GCReason::kForcedGCForTesting); BlinkGC::GCReason::kForcedGCForTesting);
......
...@@ -682,8 +682,7 @@ void ThreadState::AtomicPauseMarkPrologue( ...@@ -682,8 +682,7 @@ void ThreadState::AtomicPauseMarkPrologue(
BlinkGC::GCReason reason) { BlinkGC::GCReason reason) {
ThreadHeapStatsCollector::EnabledScope mark_prologue_scope( ThreadHeapStatsCollector::EnabledScope mark_prologue_scope(
Heap().stats_collector(), Heap().stats_collector(),
ThreadHeapStatsCollector::kAtomicPauseMarkPrologue, "epoch", gc_age_, ThreadHeapStatsCollector::kAtomicPauseMarkPrologue);
"forced", IsForcedGC(reason));
EnterAtomicPause(); EnterAtomicPause();
EnterNoAllocationScope(); EnterNoAllocationScope();
EnterGCForbiddenScope(); EnterGCForbiddenScope();
...@@ -768,8 +767,7 @@ void ThreadState::CompleteSweep() { ...@@ -768,8 +767,7 @@ void ThreadState::CompleteSweep() {
ScriptForbiddenScope script_forbidden; ScriptForbiddenScope script_forbidden;
SweepForbiddenScope scope(this); SweepForbiddenScope scope(this);
ThreadHeapStatsCollector::EnabledScope stats_scope( ThreadHeapStatsCollector::EnabledScope stats_scope(
Heap().stats_collector(), ThreadHeapStatsCollector::kCompleteSweep, Heap().stats_collector(), ThreadHeapStatsCollector::kCompleteSweep);
"forced", IsForcedGC(current_gc_data_.reason));
// Boost priority of sweeping job to complete ASAP and avoid taking time on // Boost priority of sweeping job to complete ASAP and avoid taking time on
// the main thread. // the main thread.
if (sweeper_handle_) if (sweeper_handle_)
...@@ -1114,7 +1112,7 @@ void ThreadState::IncrementalMarkingStart(BlinkGC::GCReason reason) { ...@@ -1114,7 +1112,7 @@ void ThreadState::IncrementalMarkingStart(BlinkGC::GCReason reason) {
// Sweeping is performed in driver functions. // Sweeping is performed in driver functions.
DCHECK(!IsSweepingInProgress()); DCHECK(!IsSweepingInProgress());
Heap().stats_collector()->NotifyMarkingStarted( Heap().stats_collector()->NotifyMarkingStarted(
BlinkGC::CollectionType::kMajor, reason); BlinkGC::CollectionType::kMajor, reason, IsForcedGC(reason));
{ {
ThreadHeapStatsCollector::EnabledScope stats_scope( ThreadHeapStatsCollector::EnabledScope stats_scope(
Heap().stats_collector(), Heap().stats_collector(),
...@@ -1294,7 +1292,8 @@ void ThreadState::CollectGarbage(BlinkGC::CollectionType collection_type, ...@@ -1294,7 +1292,8 @@ void ThreadState::CollectGarbage(BlinkGC::CollectionType collection_type,
if (should_do_full_gc) { if (should_do_full_gc) {
CompleteSweep(); CompleteSweep();
SetGCState(kNoGCScheduled); SetGCState(kNoGCScheduled);
Heap().stats_collector()->NotifyMarkingStarted(collection_type, reason); Heap().stats_collector()->NotifyMarkingStarted(collection_type, reason,
IsForcedGC(reason));
RunAtomicPause(collection_type, stack_state, marking_type, sweeping_type, RunAtomicPause(collection_type, stack_state, marking_type, sweeping_type,
reason); reason);
} }
...@@ -1333,8 +1332,8 @@ void ThreadState::AtomicPauseMarkRoots(BlinkGC::StackState stack_state, ...@@ -1333,8 +1332,8 @@ void ThreadState::AtomicPauseMarkRoots(BlinkGC::StackState stack_state,
BlinkGC::MarkingType marking_type, BlinkGC::MarkingType marking_type,
BlinkGC::GCReason reason) { BlinkGC::GCReason reason) {
ThreadHeapStatsCollector::EnabledScope advance_tracing_scope( ThreadHeapStatsCollector::EnabledScope advance_tracing_scope(
Heap().stats_collector(), ThreadHeapStatsCollector::kAtomicPauseMarkRoots, Heap().stats_collector(),
"epoch", gc_age_, "forced", IsForcedGC(current_gc_data_.reason)); ThreadHeapStatsCollector::kAtomicPauseMarkRoots);
MarkPhaseVisitRoots(); MarkPhaseVisitRoots();
MarkPhaseVisitNotFullyConstructedObjects(); MarkPhaseVisitNotFullyConstructedObjects();
} }
...@@ -1342,8 +1341,7 @@ void ThreadState::AtomicPauseMarkRoots(BlinkGC::StackState stack_state, ...@@ -1342,8 +1341,7 @@ void ThreadState::AtomicPauseMarkRoots(BlinkGC::StackState stack_state,
void ThreadState::AtomicPauseMarkTransitiveClosure() { void ThreadState::AtomicPauseMarkTransitiveClosure() {
ThreadHeapStatsCollector::EnabledScope advance_tracing_scope( ThreadHeapStatsCollector::EnabledScope advance_tracing_scope(
Heap().stats_collector(), Heap().stats_collector(),
ThreadHeapStatsCollector::kAtomicPauseMarkTransitiveClosure, "epoch", ThreadHeapStatsCollector::kAtomicPauseMarkTransitiveClosure);
gc_age_, "forced", IsForcedGC(current_gc_data_.reason));
// base::TimeTicks::Now() + base::TimeDelta::Max() == base::TimeTicks::Max() // base::TimeTicks::Now() + base::TimeDelta::Max() == base::TimeTicks::Max()
CHECK(MarkPhaseAdvanceMarking(base::TimeDelta::Max(), CHECK(MarkPhaseAdvanceMarking(base::TimeDelta::Max(),
EphemeronProcessing::kFullProcessing)); EphemeronProcessing::kFullProcessing));
...@@ -1352,8 +1350,7 @@ void ThreadState::AtomicPauseMarkTransitiveClosure() { ...@@ -1352,8 +1350,7 @@ void ThreadState::AtomicPauseMarkTransitiveClosure() {
void ThreadState::AtomicPauseMarkEpilogue(BlinkGC::MarkingType marking_type) { void ThreadState::AtomicPauseMarkEpilogue(BlinkGC::MarkingType marking_type) {
ThreadHeapStatsCollector::EnabledScope stats_scope( ThreadHeapStatsCollector::EnabledScope stats_scope(
Heap().stats_collector(), Heap().stats_collector(),
ThreadHeapStatsCollector::kAtomicPauseMarkEpilogue, "epoch", gc_age_, ThreadHeapStatsCollector::kAtomicPauseMarkEpilogue);
"forced", IsForcedGC(current_gc_data_.reason));
MarkPhaseEpilogue(marking_type); MarkPhaseEpilogue(marking_type);
LeaveGCForbiddenScope(); LeaveGCForbiddenScope();
LeaveNoAllocationScope(); LeaveNoAllocationScope();
...@@ -1367,8 +1364,7 @@ void ThreadState::AtomicPauseSweepAndCompact( ...@@ -1367,8 +1364,7 @@ void ThreadState::AtomicPauseSweepAndCompact(
BlinkGC::SweepingType sweeping_type) { BlinkGC::SweepingType sweeping_type) {
ThreadHeapStatsCollector::EnabledScope stats( ThreadHeapStatsCollector::EnabledScope stats(
Heap().stats_collector(), Heap().stats_collector(),
ThreadHeapStatsCollector::kAtomicPauseSweepAndCompact, "epoch", gc_age_, ThreadHeapStatsCollector::kAtomicPauseSweepAndCompact);
"forced", IsForcedGC(current_gc_data_.reason));
AtomicPauseScope atomic_pause_scope(this); AtomicPauseScope atomic_pause_scope(this);
ScriptForbiddenScope script_forbidden_scope; ScriptForbiddenScope script_forbidden_scope;
......
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