Index: src/libplatform/tracing/tracing-controller.cc |
diff --git a/src/libplatform/tracing/tracing-controller.cc b/src/libplatform/tracing/tracing-controller.cc |
index e9a21725e289fd565391084a0b933a00c82df407..4d9321436508629ff02392404d7ff6aea80c94d0 100644 |
--- a/src/libplatform/tracing/tracing-controller.cc |
+++ b/src/libplatform/tracing/tracing-controller.cc |
@@ -38,8 +38,13 @@ const int g_num_builtin_categories = 4; |
// Skip default categories. |
v8::base::AtomicWord g_category_index = g_num_builtin_categories; |
+TracingController::TracingController() {} |
+ |
+TracingController::~TracingController() {} |
+ |
void TracingController::Initialize(TraceBuffer* trace_buffer) { |
trace_buffer_.reset(trace_buffer); |
+ mutex_.reset(new base::Mutex()); |
} |
uint64_t TracingController::AddTraceEvent( |
@@ -91,13 +96,29 @@ const char* TracingController::GetCategoryGroupName( |
void TracingController::StartTracing(TraceConfig* trace_config) { |
trace_config_.reset(trace_config); |
- mode_ = RECORDING_MODE; |
- UpdateCategoryGroupEnabledFlags(); |
+ std::unordered_set<Platform::TraceStateObserver*> observers_copy; |
+ { |
+ base::LockGuard<base::Mutex> lock(mutex_.get()); |
+ mode_ = RECORDING_MODE; |
+ UpdateCategoryGroupEnabledFlags(); |
+ observers_copy = observers_; |
+ } |
+ for (auto o : observers_copy) { |
+ o->OnTraceEnabled(); |
+ } |
} |
void TracingController::StopTracing() { |
mode_ = DISABLED; |
UpdateCategoryGroupEnabledFlags(); |
+ std::unordered_set<Platform::TraceStateObserver*> observers_copy; |
+ { |
+ base::LockGuard<base::Mutex> lock(mutex_.get()); |
+ observers_copy = observers_; |
+ } |
+ for (auto o : observers_copy) { |
+ o->OnTraceDisabled(); |
+ } |
trace_buffer_->Flush(); |
} |
@@ -172,6 +193,24 @@ const uint8_t* TracingController::GetCategoryGroupEnabledInternal( |
return category_group_enabled; |
} |
+void TracingController::AddTraceStateObserver( |
+ Platform::TraceStateObserver* observer) { |
+ { |
+ base::LockGuard<base::Mutex> lock(mutex_.get()); |
+ observers_.insert(observer); |
+ if (mode_ != RECORDING_MODE) return; |
+ } |
+ // Fire the observer if recording is already in progress. |
+ observer->OnTraceEnabled(); |
+} |
+ |
+void TracingController::RemoveTraceStateObserver( |
+ Platform::TraceStateObserver* observer) { |
+ base::LockGuard<base::Mutex> lock(mutex_.get()); |
+ DCHECK(observers_.find(observer) != observers_.end()); |
+ observers_.erase(observer); |
+} |
+ |
} // namespace tracing |
} // namespace platform |
} // namespace v8 |