summaryrefslogtreecommitdiff
path: root/deps/v8/src/libplatform/tracing/tracing-controller.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/libplatform/tracing/tracing-controller.cc')
-rw-r--r--deps/v8/src/libplatform/tracing/tracing-controller.cc69
1 files changed, 37 insertions, 32 deletions
diff --git a/deps/v8/src/libplatform/tracing/tracing-controller.cc b/deps/v8/src/libplatform/tracing/tracing-controller.cc
index 53fe01e42d..8d25787495 100644
--- a/deps/v8/src/libplatform/tracing/tracing-controller.cc
+++ b/deps/v8/src/libplatform/tracing/tracing-controller.cc
@@ -16,7 +16,7 @@ namespace v8 {
namespace platform {
namespace tracing {
-#define MAX_CATEGORY_GROUPS 200
+static const size_t kMaxCategoryGroups = 200;
// Parallel arrays g_category_groups and g_category_group_enabled are separate
// so that a pointer to a member of g_category_group_enabled can be easily
@@ -24,13 +24,13 @@ namespace tracing {
// only with char enabled pointers from g_category_group_enabled, and we can
// convert internally to determine the category name from the char enabled
// pointer.
-const char* g_category_groups[MAX_CATEGORY_GROUPS] = {
+const char* g_category_groups[kMaxCategoryGroups] = {
"toplevel",
- "tracing categories exhausted; must increase MAX_CATEGORY_GROUPS",
+ "tracing categories exhausted; must increase kMaxCategoryGroups",
"__metadata"};
// The enabled flag is char instead of bool so that the API can be used from C.
-unsigned char g_category_group_enabled[MAX_CATEGORY_GROUPS] = {0};
+unsigned char g_category_group_enabled[kMaxCategoryGroups] = {0};
// Indexes here have to match the g_category_groups array indexes above.
const int g_category_categories_exhausted = 1;
// Metadata category not used in V8.
@@ -78,13 +78,16 @@ uint64_t TracingController::AddTraceEvent(
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
unsigned int flags) {
uint64_t handle = 0;
- if (mode_ != DISABLED) {
+ if (recording_.load(std::memory_order_acquire)) {
TraceObject* trace_object = trace_buffer_->AddTraceEvent(&handle);
if (trace_object) {
- trace_object->Initialize(
- phase, category_enabled_flag, name, scope, id, bind_id, num_args,
- arg_names, arg_types, arg_values, arg_convertables, flags,
- CurrentTimestampMicroseconds(), CurrentCpuTimestampMicroseconds());
+ {
+ base::MutexGuard lock(mutex_.get());
+ trace_object->Initialize(
+ phase, category_enabled_flag, name, scope, id, bind_id, num_args,
+ arg_names, arg_types, arg_values, arg_convertables, flags,
+ CurrentTimestampMicroseconds(), CurrentCpuTimestampMicroseconds());
+ }
}
}
return handle;
@@ -98,13 +101,16 @@ uint64_t TracingController::AddTraceEventWithTimestamp(
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
unsigned int flags, int64_t timestamp) {
uint64_t handle = 0;
- if (mode_ != DISABLED) {
+ if (recording_.load(std::memory_order_acquire)) {
TraceObject* trace_object = trace_buffer_->AddTraceEvent(&handle);
if (trace_object) {
- trace_object->Initialize(phase, category_enabled_flag, name, scope, id,
- bind_id, num_args, arg_names, arg_types,
- arg_values, arg_convertables, flags, timestamp,
- CurrentCpuTimestampMicroseconds());
+ {
+ base::MutexGuard lock(mutex_.get());
+ trace_object->Initialize(phase, category_enabled_flag, name, scope, id,
+ bind_id, num_args, arg_names, arg_types,
+ arg_values, arg_convertables, flags, timestamp,
+ CurrentCpuTimestampMicroseconds());
+ }
}
}
return handle;
@@ -118,11 +124,6 @@ void TracingController::UpdateTraceEventDuration(
CurrentCpuTimestampMicroseconds());
}
-const uint8_t* TracingController::GetCategoryGroupEnabled(
- const char* category_group) {
- return GetCategoryGroupEnabledInternal(category_group);
-}
-
const char* TracingController::GetCategoryGroupName(
const uint8_t* category_group_enabled) {
// Calculate the index of the category group by finding
@@ -133,7 +134,7 @@ const char* TracingController::GetCategoryGroupName(
// Check for out of bounds category pointers.
DCHECK(category_ptr >= category_begin &&
category_ptr < reinterpret_cast<uintptr_t>(g_category_group_enabled +
- MAX_CATEGORY_GROUPS));
+ kMaxCategoryGroups));
uintptr_t category_index =
(category_ptr - category_begin) / sizeof(g_category_group_enabled[0]);
return g_category_groups[category_index];
@@ -144,7 +145,7 @@ void TracingController::StartTracing(TraceConfig* trace_config) {
std::unordered_set<v8::TracingController::TraceStateObserver*> observers_copy;
{
base::MutexGuard lock(mutex_.get());
- mode_ = RECORDING_MODE;
+ recording_.store(true, std::memory_order_release);
UpdateCategoryGroupEnabledFlags();
observers_copy = observers_;
}
@@ -154,11 +155,11 @@ void TracingController::StartTracing(TraceConfig* trace_config) {
}
void TracingController::StopTracing() {
- if (mode_ == DISABLED) {
+ bool expected = true;
+ if (!recording_.compare_exchange_strong(expected, false)) {
return;
}
DCHECK(trace_buffer_);
- mode_ = DISABLED;
UpdateCategoryGroupEnabledFlags();
std::unordered_set<v8::TracingController::TraceStateObserver*> observers_copy;
{
@@ -168,13 +169,16 @@ void TracingController::StopTracing() {
for (auto o : observers_copy) {
o->OnTraceDisabled();
}
- trace_buffer_->Flush();
+ {
+ base::MutexGuard lock(mutex_.get());
+ trace_buffer_->Flush();
+ }
}
void TracingController::UpdateCategoryGroupEnabledFlag(size_t category_index) {
unsigned char enabled_flag = 0;
const char* category_group = g_category_groups[category_index];
- if (mode_ == RECORDING_MODE &&
+ if (recording_.load(std::memory_order_acquire) &&
trace_config_->IsCategoryGroupEnabled(category_group)) {
enabled_flag |= ENABLED_FOR_RECORDING;
}
@@ -183,7 +187,8 @@ void TracingController::UpdateCategoryGroupEnabledFlag(size_t category_index) {
// TODO(primiano): this is a temporary workaround for catapult:#2341,
// to guarantee that metadata events are always added even if the category
// filter is "-*". See crbug.com/618054 for more details and long-term fix.
- if (mode_ == RECORDING_MODE && !strcmp(category_group, "__metadata")) {
+ if (recording_.load(std::memory_order_acquire) &&
+ !strcmp(category_group, "__metadata")) {
enabled_flag |= ENABLED_FOR_RECORDING;
}
@@ -193,13 +198,13 @@ void TracingController::UpdateCategoryGroupEnabledFlag(size_t category_index) {
}
void TracingController::UpdateCategoryGroupEnabledFlags() {
- size_t category_index = base::Relaxed_Load(&g_category_index);
+ size_t category_index = base::Acquire_Load(&g_category_index);
for (size_t i = 0; i < category_index; i++) UpdateCategoryGroupEnabledFlag(i);
}
-const uint8_t* TracingController::GetCategoryGroupEnabledInternal(
+const uint8_t* TracingController::GetCategoryGroupEnabled(
const char* category_group) {
- // Check that category groups does not contain double quote
+ // Check that category group does not contain double quote
DCHECK(!strchr(category_group, '"'));
// The g_category_groups is append only, avoid using a lock for the fast path.
@@ -226,8 +231,8 @@ const uint8_t* TracingController::GetCategoryGroupEnabledInternal(
// Create a new category group.
// Check that there is a slot for the new category_group.
- DCHECK(category_index < MAX_CATEGORY_GROUPS);
- if (category_index < MAX_CATEGORY_GROUPS) {
+ DCHECK(category_index < kMaxCategoryGroups);
+ if (category_index < kMaxCategoryGroups) {
// Don't hold on to the category_group pointer, so that we can create
// category groups with strings not known at compile time (this is
// required by SetWatchEvent).
@@ -253,7 +258,7 @@ void TracingController::AddTraceStateObserver(
{
base::MutexGuard lock(mutex_.get());
observers_.insert(observer);
- if (mode_ != RECORDING_MODE) return;
+ if (!recording_.load(std::memory_order_acquire)) return;
}
// Fire the observer if recording is already in progress.
observer->OnTraceEnabled();