Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Unified Diff: src/libplatform/tracing/tracing-controller.cc

Issue 2369073003: [tracing] Implement Add/RemoveTraceStateObserver for default platform. (Closed)
Patch Set: addressing comments. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/libplatform/default-platform.cc ('k') | test/cctest/libplatform/test-tracing.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « src/libplatform/default-platform.cc ('k') | test/cctest/libplatform/test-tracing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698