Commit 332122a2 authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Counters] Only create TLS key for WorkerThreadRuntimeCallStats if used.

BUG=chromium:919394

Change-Id: I99d0b557f8d52c87c4422cd971a43211e5d5e849
Reviewed-on: https://chromium-review.googlesource.com/c/1425198Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58964}
parent 42e0bf22
......@@ -531,11 +531,16 @@ void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) {
in_use_ = false;
}
WorkerThreadRuntimeCallStats::WorkerThreadRuntimeCallStats()
: tls_key_(base::Thread::CreateThreadLocalKey()) {}
WorkerThreadRuntimeCallStats::WorkerThreadRuntimeCallStats() {}
WorkerThreadRuntimeCallStats::~WorkerThreadRuntimeCallStats() {
base::Thread::DeleteThreadLocalKey(tls_key_);
if (tls_key_) base::Thread::DeleteThreadLocalKey(*tls_key_);
}
base::Thread::LocalStorageKey WorkerThreadRuntimeCallStats::GetKey() {
DCHECK(FLAG_runtime_stats);
if (!tls_key_) tls_key_ = base::Thread::CreateThreadLocalKey();
return *tls_key_;
}
RuntimeCallStats* WorkerThreadRuntimeCallStats::NewTable() {
......
......@@ -8,6 +8,7 @@
#include "include/v8.h"
#include "src/allocation.h"
#include "src/base/atomic-utils.h"
#include "src/base/optional.h"
#include "src/base/platform/elapsed-timer.h"
#include "src/base/platform/time.h"
#include "src/globals.h"
......@@ -1101,7 +1102,7 @@ class WorkerThreadRuntimeCallStats final {
~WorkerThreadRuntimeCallStats();
// Returns the TLS key associated with this WorkerThreadRuntimeCallStats.
base::Thread::LocalStorageKey GetKey() const { return tls_key_; }
base::Thread::LocalStorageKey GetKey();
// Returns a new worker thread runtime call stats table managed by this
// WorkerThreadRuntimeCallStats.
......@@ -1113,7 +1114,7 @@ class WorkerThreadRuntimeCallStats final {
private:
base::Mutex mutex_;
std::vector<std::unique_ptr<RuntimeCallStats>> tables_;
base::Thread::LocalStorageKey tls_key_;
base::Optional<base::Thread::LocalStorageKey> tls_key_;
};
// Creating a WorkerThreadRuntimeCallStatsScope will provide a thread-local
......
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