Commit 75f14738 authored by lpy's avatar lpy Committed by Commit bot

[Tracing] Use TracingCategoryObserver in gc statistics

This patch is a follow-up patch to enable gc statistics to use
TracingCategoryObserver.

Previously we need to pass --track_gc_object_stats to v8 if we want to enable
gc statistics in tracing. In this patch, we introducce an integer flag
FLAG_gc_stats, and FLAG_track_gc_object_stats and FLAG_trace_gc_object_stats
will set it to 0x01, tracing will set it to 0x10 when we start tracing and
reset the bit when we stop tracing.

BUG=v8:5590

Review-Url: https://codereview.chromium.org/2459903003
Cr-Commit-Position: refs/heads/master@{#40777}
parent 01219881
...@@ -8087,7 +8087,7 @@ size_t Isolate::NumberOfTrackedHeapObjectTypes() { ...@@ -8087,7 +8087,7 @@ size_t Isolate::NumberOfTrackedHeapObjectTypes() {
bool Isolate::GetHeapObjectStatisticsAtLastGC( bool Isolate::GetHeapObjectStatisticsAtLastGC(
HeapObjectStatistics* object_statistics, size_t type_index) { HeapObjectStatistics* object_statistics, size_t type_index) {
if (!object_statistics) return false; if (!object_statistics) return false;
if (!i::FLAG_track_gc_object_stats) return false; if (V8_LIKELY(!i::FLAG_gc_stats)) return false;
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
i::Heap* heap = isolate->heap(); i::Heap* heap = isolate->heap();
......
...@@ -4018,7 +4018,7 @@ bool Genesis::InstallExtensions(Handle<Context> native_context, ...@@ -4018,7 +4018,7 @@ bool Genesis::InstallExtensions(Handle<Context> native_context,
InstallExtension(isolate, "v8/gc", &extension_states)) && InstallExtension(isolate, "v8/gc", &extension_states)) &&
(!FLAG_expose_externalize_string || (!FLAG_expose_externalize_string ||
InstallExtension(isolate, "v8/externalize", &extension_states)) && InstallExtension(isolate, "v8/externalize", &extension_states)) &&
(!FLAG_track_gc_object_stats || (!FLAG_gc_stats ||
InstallExtension(isolate, "v8/statistics", &extension_states)) && InstallExtension(isolate, "v8/statistics", &extension_states)) &&
(!FLAG_expose_trigger_failure || (!FLAG_expose_trigger_failure ||
InstallExtension(isolate, "v8/trigger-failure", &extension_states)) && InstallExtension(isolate, "v8/trigger-failure", &extension_states)) &&
......
...@@ -2864,7 +2864,7 @@ int Shell::Main(int argc, char* argv[]) { ...@@ -2864,7 +2864,7 @@ int Shell::Main(int argc, char* argv[]) {
base::SysInfo::AmountOfVirtualMemory()); base::SysInfo::AmountOfVirtualMemory());
Shell::counter_map_ = new CounterMap(); Shell::counter_map_ = new CounterMap();
if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) { if (i::FLAG_dump_counters || i::FLAG_gc_stats) {
create_params.counter_lookup_callback = LookupCounter; create_params.counter_lookup_callback = LookupCounter;
create_params.create_histogram_callback = CreateHistogram; create_params.create_histogram_callback = CreateHistogram;
create_params.add_histogram_sample_callback = AddHistogramSample; create_params.add_histogram_sample_callback = AddHistogramSample;
......
...@@ -744,7 +744,10 @@ DEFINE_BOOL(track_gc_object_stats, false, ...@@ -744,7 +744,10 @@ DEFINE_BOOL(track_gc_object_stats, false,
"track object counts and memory usage") "track object counts and memory usage")
DEFINE_BOOL(trace_gc_object_stats, false, DEFINE_BOOL(trace_gc_object_stats, false,
"trace object counts and memory usage") "trace object counts and memory usage")
DEFINE_INT(gc_stats, 0, "Used by tracing internally to enable gc statistics")
DEFINE_IMPLICATION(trace_gc_object_stats, track_gc_object_stats) DEFINE_IMPLICATION(trace_gc_object_stats, track_gc_object_stats)
DEFINE_VALUE_IMPLICATION(track_gc_object_stats, gc_stats, 1)
DEFINE_VALUE_IMPLICATION(trace_gc_object_stats, gc_stats, 1)
DEFINE_NEG_IMPLICATION(trace_gc_object_stats, incremental_marking) DEFINE_NEG_IMPLICATION(trace_gc_object_stats, incremental_marking)
DEFINE_BOOL(track_detached_contexts, true, DEFINE_BOOL(track_detached_contexts, true,
"track native contexts that are expected to be garbage collected") "track native contexts that are expected to be garbage collected")
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "src/heap/heap.h" #include "src/heap/heap.h"
#include "src/heap/incremental-marking-inl.h" #include "src/heap/incremental-marking-inl.h"
#include "src/heap/mark-compact.h" #include "src/heap/mark-compact.h"
#include "src/heap/object-stats.h"
#include "src/heap/remembered-set.h" #include "src/heap/remembered-set.h"
#include "src/heap/spaces-inl.h" #include "src/heap/spaces-inl.h"
#include "src/heap/store-buffer.h" #include "src/heap/store-buffer.h"
...@@ -809,6 +810,16 @@ void Heap::SetSerializedTemplates(FixedArray* templates) { ...@@ -809,6 +810,16 @@ void Heap::SetSerializedTemplates(FixedArray* templates) {
set_serialized_templates(templates); set_serialized_templates(templates);
} }
void Heap::CreateObjectStats() {
if (V8_LIKELY(FLAG_gc_stats == 0)) return;
if (!live_object_stats_) {
live_object_stats_ = new ObjectStats(this);
}
if (!dead_object_stats_) {
dead_object_stats_ = new ObjectStats(this);
}
}
AlwaysAllocateScope::AlwaysAllocateScope(Isolate* isolate) AlwaysAllocateScope::AlwaysAllocateScope(Isolate* isolate)
: heap_(isolate->heap()) { : heap_(isolate->heap()) {
heap_->always_allocate_scope_count_.Increment(1); heap_->always_allocate_scope_count_.Increment(1);
......
...@@ -5470,7 +5470,7 @@ bool Heap::SetUp() { ...@@ -5470,7 +5470,7 @@ bool Heap::SetUp() {
mark_compact_collector_ = new MarkCompactCollector(this); mark_compact_collector_ = new MarkCompactCollector(this);
gc_idle_time_handler_ = new GCIdleTimeHandler(); gc_idle_time_handler_ = new GCIdleTimeHandler();
memory_reducer_ = new MemoryReducer(this); memory_reducer_ = new MemoryReducer(this);
if (FLAG_track_gc_object_stats) { if (V8_UNLIKELY(FLAG_gc_stats)) {
live_object_stats_ = new ObjectStats(this); live_object_stats_ = new ObjectStats(this);
dead_object_stats_ = new ObjectStats(this); dead_object_stats_ = new ObjectStats(this);
} }
......
...@@ -944,6 +944,9 @@ class Heap { ...@@ -944,6 +944,9 @@ class Heap {
// Returns whether it succeeded. // Returns whether it succeeded.
bool CreateHeapObjects(); bool CreateHeapObjects();
// Create ObjectStats if live_object_stats_ or dead_object_stats_ are nullptr.
V8_INLINE void CreateObjectStats();
// Destroys all memory allocated by the heap. // Destroys all memory allocated by the heap.
void TearDown(); void TearDown();
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "src/heap/spaces-inl.h" #include "src/heap/spaces-inl.h"
#include "src/ic/ic.h" #include "src/ic/ic.h"
#include "src/ic/stub-cache.h" #include "src/ic/stub-cache.h"
#include "src/tracing/tracing-category-observer.h"
#include "src/utils-inl.h" #include "src/utils-inl.h"
#include "src/v8.h" #include "src/v8.h"
...@@ -2236,17 +2237,21 @@ void MarkCompactCollector::VisitAllObjects(HeapObjectVisitor* visitor) { ...@@ -2236,17 +2237,21 @@ void MarkCompactCollector::VisitAllObjects(HeapObjectVisitor* visitor) {
} }
void MarkCompactCollector::RecordObjectStats() { void MarkCompactCollector::RecordObjectStats() {
if (FLAG_track_gc_object_stats) { if (V8_UNLIKELY(FLAG_gc_stats)) {
heap()->CreateObjectStats();
ObjectStatsVisitor visitor(heap(), heap()->live_object_stats_, ObjectStatsVisitor visitor(heap(), heap()->live_object_stats_,
heap()->dead_object_stats_); heap()->dead_object_stats_);
VisitAllObjects(&visitor); VisitAllObjects(&visitor);
std::stringstream live, dead; if (V8_UNLIKELY(FLAG_gc_stats &
heap()->live_object_stats_->Dump(live); v8::tracing::TracingCategoryObserver::ENABLED_BY_TRACING)) {
heap()->dead_object_stats_->Dump(dead); std::stringstream live, dead;
TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("v8.gc_stats"), heap()->live_object_stats_->Dump(live);
"V8.GC_Objects_Stats", TRACE_EVENT_SCOPE_THREAD, heap()->dead_object_stats_->Dump(dead);
"live", TRACE_STR_COPY(live.str().c_str()), "dead", TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("v8.gc_stats"),
TRACE_STR_COPY(dead.str().c_str())); "V8.GC_Objects_Stats", TRACE_EVENT_SCOPE_THREAD,
"live", TRACE_STR_COPY(live.str().c_str()), "dead",
TRACE_STR_COPY(dead.str().c_str()));
}
if (FLAG_trace_gc_object_stats) { if (FLAG_trace_gc_object_stats) {
heap()->live_object_stats_->PrintJSON("live"); heap()->live_object_stats_->PrintJSON("live");
heap()->dead_object_stats_->PrintJSON("dead"); heap()->dead_object_stats_->PrintJSON("dead");
......
...@@ -18,6 +18,7 @@ void TracingCategoryObserver::SetUp() { ...@@ -18,6 +18,7 @@ void TracingCategoryObserver::SetUp() {
v8::internal::V8::GetCurrentPlatform()->AddTraceStateObserver( v8::internal::V8::GetCurrentPlatform()->AddTraceStateObserver(
TracingCategoryObserver::instance_); TracingCategoryObserver::instance_);
TRACE_EVENT_WARMUP_CATEGORY(TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats")); TRACE_EVENT_WARMUP_CATEGORY(TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats"));
TRACE_EVENT_WARMUP_CATEGORY(TRACE_DISABLED_BY_DEFAULT("v8.gc_stats"));
} }
void TracingCategoryObserver::TearDown() { void TracingCategoryObserver::TearDown() {
...@@ -33,10 +34,16 @@ void TracingCategoryObserver::OnTraceEnabled() { ...@@ -33,10 +34,16 @@ void TracingCategoryObserver::OnTraceEnabled() {
if (enabled) { if (enabled) {
v8::internal::FLAG_runtime_stats |= ENABLED_BY_TRACING; v8::internal::FLAG_runtime_stats |= ENABLED_BY_TRACING;
} }
TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("v8.gc_stats"),
&enabled);
if (enabled) {
v8::internal::FLAG_gc_stats |= ENABLED_BY_TRACING;
}
} }
void TracingCategoryObserver::OnTraceDisabled() { void TracingCategoryObserver::OnTraceDisabled() {
v8::internal::FLAG_runtime_stats &= ~ENABLED_BY_TRACING; v8::internal::FLAG_runtime_stats &= ~ENABLED_BY_TRACING;
v8::internal::FLAG_gc_stats &= ~ENABLED_BY_TRACING;
} }
} // namespace tracing } // namespace tracing
......
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