[heap, perfetto] Emit MinorGC/MajorGC trace events for each GC
Currently these events are emitted by Blink in GC prologue/epilogue. That however does not respect event nesting and breaks with future perfetto changes. This CL emits the events inside V8 using a scope to guarantee proper event nesting. The events are same except for the "type" argument that now gets more detailed information. The corresponding Blink CL that removes these trace events: https://chromium-review.googlesource.com/c/chromium/src/+/1929227 Bug: chromium:1026658 Change-Id: Ifbfab647f40f81af7acf315ff4608b9dc9444f94 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1928857 Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#65120}
This commit is contained in:
parent
93f189f19a
commit
3eea45f455
@ -1015,6 +1015,8 @@ void GlobalHandles::IterateYoungWeakUnmodifiedRootsForPhantomHandles(
|
||||
void GlobalHandles::InvokeSecondPassPhantomCallbacksFromTask() {
|
||||
DCHECK(second_pass_callbacks_task_posted_);
|
||||
second_pass_callbacks_task_posted_ = false;
|
||||
Heap::DevToolsTraceEventScope devtools_trace_event_scope(
|
||||
isolate()->heap(), "MajorGC", "invoke weak phantom callbacks");
|
||||
TRACE_EVENT0("v8", "V8.GCPhantomHandleProcessingCallback");
|
||||
isolate()->heap()->CallGCPrologueCallbacks(
|
||||
GCType::kGCTypeProcessWeakCallbacks, kNoGCCallbackFlags);
|
||||
@ -1141,6 +1143,8 @@ void GlobalHandles::InvokeOrScheduleSecondPassPhantomCallbacks(
|
||||
bool synchronous_second_pass) {
|
||||
if (!second_pass_callbacks_.empty()) {
|
||||
if (FLAG_optimize_for_size || FLAG_predictable || synchronous_second_pass) {
|
||||
Heap::DevToolsTraceEventScope devtools_trace_event_scope(
|
||||
isolate()->heap(), "MajorGC", "invoke weak phantom callbacks");
|
||||
isolate()->heap()->CallGCPrologueCallbacks(
|
||||
GCType::kGCTypeProcessWeakCallbacks, kNoGCCallbackFlags);
|
||||
InvokeSecondPassPhantomCallbacks();
|
||||
|
@ -1486,6 +1486,19 @@ void Heap::EnsureFillerObjectAtTop() {
|
||||
}
|
||||
}
|
||||
|
||||
Heap::DevToolsTraceEventScope::DevToolsTraceEventScope(Heap* heap,
|
||||
const char* event_name,
|
||||
const char* event_type)
|
||||
: heap_(heap), event_name_(event_name) {
|
||||
TRACE_EVENT_BEGIN2("devtools.timeline,v8", event_name_, "usedHeapSizeBefore",
|
||||
heap_->SizeOfObjects(), "type", event_type);
|
||||
}
|
||||
|
||||
Heap::DevToolsTraceEventScope::~DevToolsTraceEventScope() {
|
||||
TRACE_EVENT_END1("devtools.timeline,v8", event_name_, "usedHeapSizeAfter",
|
||||
heap_->SizeOfObjects());
|
||||
}
|
||||
|
||||
bool Heap::CollectGarbage(AllocationSpace space,
|
||||
GarbageCollectionReason gc_reason,
|
||||
const v8::GCCallbackFlags gc_callback_flags) {
|
||||
@ -1493,6 +1506,10 @@ bool Heap::CollectGarbage(AllocationSpace space,
|
||||
GarbageCollector collector = SelectGarbageCollector(space, &collector_reason);
|
||||
is_current_gc_forced_ = gc_callback_flags & v8::kGCCallbackFlagForced;
|
||||
|
||||
DevToolsTraceEventScope devtools_trace_event_scope(
|
||||
this, IsYoungGenerationCollector(collector) ? "MinorGC" : "MajorGC",
|
||||
GarbageCollectionReasonToString(gc_reason));
|
||||
|
||||
if (!CanExpandOldGeneration(new_space()->Capacity() +
|
||||
new_lo_space()->Size())) {
|
||||
InvokeNearHeapLimitCallback();
|
||||
@ -3335,6 +3352,9 @@ void Heap::FinalizeIncrementalMarkingIncrementally(
|
||||
Heap::GarbageCollectionReasonToString(gc_reason));
|
||||
}
|
||||
|
||||
DevToolsTraceEventScope devtools_trace_event_scope(
|
||||
this, "MajorGC", "incremental finalization step");
|
||||
|
||||
HistogramTimerScope incremental_marking_scope(
|
||||
isolate()->counters()->gc_incremental_marking_finalize());
|
||||
TRACE_EVENT0("v8", "V8.GCIncrementalMarkingFinalize");
|
||||
|
@ -228,6 +228,18 @@ class Heap {
|
||||
TEAR_DOWN
|
||||
};
|
||||
|
||||
// Emits GC events for DevTools timeline.
|
||||
class DevToolsTraceEventScope {
|
||||
public:
|
||||
DevToolsTraceEventScope(Heap* heap, const char* event_name,
|
||||
const char* event_type);
|
||||
~DevToolsTraceEventScope();
|
||||
|
||||
private:
|
||||
Heap* heap_;
|
||||
const char* event_name_;
|
||||
};
|
||||
|
||||
using PretenuringFeedbackMap =
|
||||
std::unordered_map<AllocationSite, size_t, Object::Hasher>;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user