diff options
Diffstat (limited to 'deps/v8/src/counters.cc')
-rw-r--r-- | deps/v8/src/counters.cc | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/deps/v8/src/counters.cc b/deps/v8/src/counters.cc index bcea9e0f42..a4b08127cd 100644 --- a/deps/v8/src/counters.cc +++ b/deps/v8/src/counters.cc @@ -118,7 +118,8 @@ Counters::Counters(Isolate* isolate) STATS_COUNTER_TS_LIST(SC) #undef SC // clang format on - runtime_call_stats_() { + runtime_call_stats_(), + worker_thread_runtime_call_stats_() { static const struct { Histogram Counters::*member; const char* caption; @@ -529,5 +530,64 @@ void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) { in_use_ = false; } +WorkerThreadRuntimeCallStats::WorkerThreadRuntimeCallStats() + : tls_key_(base::Thread::CreateThreadLocalKey()) {} + +WorkerThreadRuntimeCallStats::~WorkerThreadRuntimeCallStats() { + base::Thread::DeleteThreadLocalKey(tls_key_); +} + +RuntimeCallStats* WorkerThreadRuntimeCallStats::NewTable() { + DCHECK(FLAG_runtime_stats); + std::unique_ptr<RuntimeCallStats> new_table = + base::make_unique<RuntimeCallStats>(); + RuntimeCallStats* result = new_table.get(); + + base::LockGuard<base::Mutex> lock(&mutex_); + tables_.push_back(std::move(new_table)); + return result; +} + +void WorkerThreadRuntimeCallStats::AddToMainTable( + RuntimeCallStats* main_call_stats) { + base::LockGuard<base::Mutex> lock(&mutex_); + for (auto& worker_stats : tables_) { + DCHECK_NE(main_call_stats, worker_stats.get()); + main_call_stats->Add(worker_stats.get()); + worker_stats->Reset(); + } +} + +WorkerThreadRuntimeCallStatsScope::WorkerThreadRuntimeCallStatsScope( + WorkerThreadRuntimeCallStats* worker_stats) + : table_(nullptr) { + if (V8_LIKELY(!FLAG_runtime_stats)) return; + + table_ = reinterpret_cast<RuntimeCallStats*>( + base::Thread::GetThreadLocal(worker_stats->GetKey())); + if (table_ == nullptr) { + table_ = worker_stats->NewTable(); + base::Thread::SetThreadLocal(worker_stats->GetKey(), table_); + } + + if (FLAG_runtime_stats & + v8::tracing::TracingCategoryObserver::ENABLED_BY_TRACING) { + table_->Reset(); + } +} + +WorkerThreadRuntimeCallStatsScope::~WorkerThreadRuntimeCallStatsScope() { + if (V8_LIKELY(table_ == nullptr)) return; + + if ((FLAG_runtime_stats & + v8::tracing::TracingCategoryObserver::ENABLED_BY_TRACING)) { + auto value = v8::tracing::TracedValue::Create(); + table_->Dump(value.get()); + TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats"), + "V8.RuntimeStats", TRACE_EVENT_SCOPE_THREAD, + "runtime-call-stats", std::move(value)); + } +} + } // namespace internal } // namespace v8 |