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) {
});
}
ThreadHeapStatsCollector::Event::Event() {
static std::atomic<size_t> counter{0};
unique_id = counter.fetch_add(1);
}
void ThreadHeapStatsCollector::NotifyMarkingStarted(
BlinkGC::CollectionType collection_type,
BlinkGC::GCReason reason) {
BlinkGC::GCReason reason,
bool is_forced_gc) {
DCHECK(!is_started_);
DCHECK(current_.marking_time().is_zero());
is_started_ = true;
current_.reason = reason;
current_.collection_type = collection_type;
current_.is_forced_gc = is_forced_gc;
}
void ThreadHeapStatsCollector::NotifyMarkingCompleted(size_t marked_bytes) {
......
......@@ -220,6 +220,8 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector {
// 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.
struct PLATFORM_EXPORT Event {
Event();
// Overall time spent in the GC cycle. This includes marking time as well as
// sweeping time.
base::TimeDelta gc_cycle_time() const;
......@@ -267,6 +269,7 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector {
double marking_time_in_bytes_per_second() const;
// Marked bytes collected during sweeping.
size_t unique_id = -1;
size_t marked_bytes = 0;
size_t compaction_freed_bytes = 0;
size_t compaction_freed_pages = 0;
......@@ -280,10 +283,13 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector {
size_t partition_alloc_bytes_before_sweeping = 0;
double live_object_rate = 0;
base::TimeDelta gc_nested_in_v8;
bool is_forced_gc = true;
};
// 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
// completed.
......@@ -437,8 +443,10 @@ template <ThreadHeapStatsCollector::TraceCategory trace_category,
ThreadHeapStatsCollector::ScopeContext scope_category>
void ThreadHeapStatsCollector::InternalScope<trace_category,
scope_category>::StopTrace() {
TRACE_EVENT_END0(TraceCategory(),
ToString(id_, tracer_->current_.collection_type));
TRACE_EVENT_END2(TraceCategory(),
ToString(id_, tracer_->current_.collection_type), "epoch",
tracer_->current_.unique_id, "forced",
tracer_->current_.is_forced_gc);
}
template <ThreadHeapStatsCollector::TraceCategory trace_category,
......
......@@ -265,8 +265,8 @@ class TestGCScope : public TestGCCollectGarbageScope {
explicit TestGCScope(BlinkGC::StackState state)
: TestGCCollectGarbageScope(state) {
ThreadState::Current()->Heap().stats_collector()->NotifyMarkingStarted(
BlinkGC::CollectionType::kMajor,
BlinkGC::GCReason::kForcedGCForTesting);
BlinkGC::CollectionType::kMajor, BlinkGC::GCReason::kForcedGCForTesting,
true /* is_forced_gc */);
ThreadState::Current()->AtomicPauseMarkPrologue(
BlinkGC::CollectionType::kMajor, state, BlinkGC::kAtomicMarking,
BlinkGC::GCReason::kForcedGCForTesting);
......
......@@ -682,8 +682,7 @@ void ThreadState::AtomicPauseMarkPrologue(
BlinkGC::GCReason reason) {
ThreadHeapStatsCollector::EnabledScope mark_prologue_scope(
Heap().stats_collector(),
ThreadHeapStatsCollector::kAtomicPauseMarkPrologue, "epoch", gc_age_,
"forced", IsForcedGC(reason));
ThreadHeapStatsCollector::kAtomicPauseMarkPrologue);
EnterAtomicPause();
EnterNoAllocationScope();
EnterGCForbiddenScope();
......@@ -768,8 +767,7 @@ void ThreadState::CompleteSweep() {
ScriptForbiddenScope script_forbidden;
SweepForbiddenScope scope(this);
ThreadHeapStatsCollector::EnabledScope stats_scope(
Heap().stats_collector(), ThreadHeapStatsCollector::kCompleteSweep,
"forced", IsForcedGC(current_gc_data_.reason));
Heap().stats_collector(), ThreadHeapStatsCollector::kCompleteSweep);
// Boost priority of sweeping job to complete ASAP and avoid taking time on
// the main thread.
if (sweeper_handle_)
......@@ -1114,7 +1112,7 @@ void ThreadState::IncrementalMarkingStart(BlinkGC::GCReason reason) {
// Sweeping is performed in driver functions.
DCHECK(!IsSweepingInProgress());
Heap().stats_collector()->NotifyMarkingStarted(
BlinkGC::CollectionType::kMajor, reason);
BlinkGC::CollectionType::kMajor, reason, IsForcedGC(reason));
{
ThreadHeapStatsCollector::EnabledScope stats_scope(
Heap().stats_collector(),
......@@ -1294,7 +1292,8 @@ void ThreadState::CollectGarbage(BlinkGC::CollectionType collection_type,
if (should_do_full_gc) {
CompleteSweep();
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,
reason);
}
......@@ -1333,8 +1332,8 @@ void ThreadState::AtomicPauseMarkRoots(BlinkGC::StackState stack_state,
BlinkGC::MarkingType marking_type,
BlinkGC::GCReason reason) {
ThreadHeapStatsCollector::EnabledScope advance_tracing_scope(
Heap().stats_collector(), ThreadHeapStatsCollector::kAtomicPauseMarkRoots,
"epoch", gc_age_, "forced", IsForcedGC(current_gc_data_.reason));
Heap().stats_collector(),
ThreadHeapStatsCollector::kAtomicPauseMarkRoots);
MarkPhaseVisitRoots();
MarkPhaseVisitNotFullyConstructedObjects();
}
......@@ -1342,8 +1341,7 @@ void ThreadState::AtomicPauseMarkRoots(BlinkGC::StackState stack_state,
void ThreadState::AtomicPauseMarkTransitiveClosure() {
ThreadHeapStatsCollector::EnabledScope advance_tracing_scope(
Heap().stats_collector(),
ThreadHeapStatsCollector::kAtomicPauseMarkTransitiveClosure, "epoch",
gc_age_, "forced", IsForcedGC(current_gc_data_.reason));
ThreadHeapStatsCollector::kAtomicPauseMarkTransitiveClosure);
// base::TimeTicks::Now() + base::TimeDelta::Max() == base::TimeTicks::Max()
CHECK(MarkPhaseAdvanceMarking(base::TimeDelta::Max(),
EphemeronProcessing::kFullProcessing));
......@@ -1352,8 +1350,7 @@ void ThreadState::AtomicPauseMarkTransitiveClosure() {
void ThreadState::AtomicPauseMarkEpilogue(BlinkGC::MarkingType marking_type) {
ThreadHeapStatsCollector::EnabledScope stats_scope(
Heap().stats_collector(),
ThreadHeapStatsCollector::kAtomicPauseMarkEpilogue, "epoch", gc_age_,
"forced", IsForcedGC(current_gc_data_.reason));
ThreadHeapStatsCollector::kAtomicPauseMarkEpilogue);
MarkPhaseEpilogue(marking_type);
LeaveGCForbiddenScope();
LeaveNoAllocationScope();
......@@ -1367,8 +1364,7 @@ void ThreadState::AtomicPauseSweepAndCompact(
BlinkGC::SweepingType sweeping_type) {
ThreadHeapStatsCollector::EnabledScope stats(
Heap().stats_collector(),
ThreadHeapStatsCollector::kAtomicPauseSweepAndCompact, "epoch", gc_age_,
"forced", IsForcedGC(current_gc_data_.reason));
ThreadHeapStatsCollector::kAtomicPauseSweepAndCompact);
AtomicPauseScope atomic_pause_scope(this);
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