diff options
Diffstat (limited to 'deps/v8/src/libplatform/tracing/tracing-controller.cc')
-rw-r--r-- | deps/v8/src/libplatform/tracing/tracing-controller.cc | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/deps/v8/src/libplatform/tracing/tracing-controller.cc b/deps/v8/src/libplatform/tracing/tracing-controller.cc index e0a6a1234c5..daaebc291a5 100644 --- a/deps/v8/src/libplatform/tracing/tracing-controller.cc +++ b/deps/v8/src/libplatform/tracing/tracing-controller.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include <stdio.h> +#include <stdlib.h> #include <string.h> #include "include/libplatform/v8-tracing.h" @@ -41,7 +42,20 @@ v8::base::AtomicWord g_category_index = g_num_builtin_categories; TracingController::TracingController() {} -TracingController::~TracingController() { StopTracing(); } +TracingController::~TracingController() { + StopTracing(); + + { + // Free memory for category group names allocated via strdup. + base::LockGuard<base::Mutex> lock(mutex_.get()); + for (size_t i = g_category_index - 1; i >= g_num_builtin_categories; --i) { + const char* group = g_category_groups[i]; + g_category_groups[i] = nullptr; + free(const_cast<char*>(group)); + } + g_category_index = g_num_builtin_categories; + } +} void TracingController::Initialize(TraceBuffer* trace_buffer) { trace_buffer_.reset(trace_buffer); @@ -63,15 +77,13 @@ uint64_t TracingController::AddTraceEvent( const uint64_t* arg_values, std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables, unsigned int flags) { - uint64_t handle = 0; - if (mode_ != DISABLED) { - 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()); - } + uint64_t handle; + 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()); } return handle; } @@ -83,15 +95,13 @@ uint64_t TracingController::AddTraceEventWithTimestamp( const uint64_t* arg_values, std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables, unsigned int flags, int64_t timestamp) { - uint64_t handle = 0; - if (mode_ != DISABLED) { - 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()); - } + uint64_t handle; + 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()); } return handle; } @@ -189,17 +199,21 @@ const uint8_t* TracingController::GetCategoryGroupEnabledInternal( DCHECK(!strchr(category_group, '"')); // The g_category_groups is append only, avoid using a lock for the fast path. - size_t current_category_index = v8::base::Acquire_Load(&g_category_index); + size_t category_index = base::Acquire_Load(&g_category_index); // Search for pre-existing category group. - for (size_t i = 0; i < current_category_index; ++i) { + for (size_t i = 0; i < category_index; ++i) { if (strcmp(g_category_groups[i], category_group) == 0) { return &g_category_group_enabled[i]; } } + // Slow path. Grab the lock. + base::LockGuard<base::Mutex> lock(mutex_.get()); + + // Check the list again with lock in hand. unsigned char* category_group_enabled = nullptr; - size_t category_index = base::Acquire_Load(&g_category_index); + category_index = base::Acquire_Load(&g_category_index); for (size_t i = 0; i < category_index; ++i) { if (strcmp(g_category_groups[i], category_group) == 0) { return &g_category_group_enabled[i]; |