Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gin/public/v8_platform.h" | 5 #include "gin/public/v8_platform.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
| 10 #include "base/threading/worker_pool.h" | 10 #include "base/threading/worker_pool.h" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "gin/per_isolate_data.h" | 12 #include "gin/per_isolate_data.h" |
| 13 #include "v8/include/v8-tracing.h" | |
| 13 | 14 |
| 14 namespace gin { | 15 namespace gin { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 base::LazyInstance<V8Platform>::Leaky g_v8_platform = LAZY_INSTANCE_INITIALIZER; | 19 base::LazyInstance<V8Platform>::Leaky g_v8_platform = LAZY_INSTANCE_INITIALIZER; |
| 19 | 20 |
| 20 } // namespace | 21 } // namespace |
| 21 | 22 |
| 22 // static | 23 // static |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 memcpy(&traceEventHandle, &handle, sizeof(handle)); | 148 memcpy(&traceEventHandle, &handle, sizeof(handle)); |
| 148 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_enabled_flag, name, | 149 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_enabled_flag, name, |
| 149 traceEventHandle); | 150 traceEventHandle); |
| 150 } | 151 } |
| 151 | 152 |
| 152 namespace { | 153 namespace { |
| 153 | 154 |
| 154 class EnabledStateObserverImpl final | 155 class EnabledStateObserverImpl final |
| 155 : public base::trace_event::TraceLog::EnabledStateObserver { | 156 : public base::trace_event::TraceLog::EnabledStateObserver { |
| 156 public: | 157 public: |
| 157 EnabledStateObserverImpl() = default; | 158 EnabledStateObserverImpl() { |
| 159 tracing_category_observer_ = v8::tracing::TracingCategoryObserver::Create(); | |
|
alph
2016/10/31 22:48:55
Why it belongs here? It should be an internal clas
| |
| 160 observers_.insert(reinterpret_cast<v8::Platform::TraceStateObserver*>( | |
|
alph
2016/10/31 22:48:55
Reinterpret cast between interfaces won't work.
| |
| 161 tracing_category_observer_.get())); | |
| 162 } | |
| 158 | 163 |
| 159 void OnTraceLogEnabled() final { | 164 void OnTraceLogEnabled() final { |
| 160 base::AutoLock lock(mutex_); | 165 base::AutoLock lock(mutex_); |
| 161 for (auto o : observers_) { | 166 for (auto o : observers_) { |
| 162 o->OnTraceEnabled(); | 167 o->OnTraceEnabled(); |
| 163 } | 168 } |
| 164 } | 169 } |
| 165 | 170 |
| 166 void OnTraceLogDisabled() final { | 171 void OnTraceLogDisabled() final { |
| 167 base::AutoLock lock(mutex_); | 172 base::AutoLock lock(mutex_); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 185 observers_.erase(observer); | 190 observers_.erase(observer); |
| 186 if (observers_.empty()) { | 191 if (observers_.empty()) { |
| 187 base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver( | 192 base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver( |
| 188 this); | 193 this); |
| 189 } | 194 } |
| 190 } | 195 } |
| 191 | 196 |
| 192 private: | 197 private: |
| 193 base::Lock mutex_; | 198 base::Lock mutex_; |
| 194 std::unordered_set<v8::Platform::TraceStateObserver*> observers_; | 199 std::unordered_set<v8::Platform::TraceStateObserver*> observers_; |
| 200 std::unique_ptr<v8::tracing::TracingCategoryObserver> | |
| 201 tracing_category_observer_; | |
| 195 | 202 |
| 196 DISALLOW_COPY_AND_ASSIGN(EnabledStateObserverImpl); | 203 DISALLOW_COPY_AND_ASSIGN(EnabledStateObserverImpl); |
| 197 }; | 204 }; |
| 198 | 205 |
| 199 base::LazyInstance<EnabledStateObserverImpl>::Leaky g_trace_state_dispatcher = | 206 base::LazyInstance<EnabledStateObserverImpl>::Leaky g_trace_state_dispatcher = |
| 200 LAZY_INSTANCE_INITIALIZER; | 207 LAZY_INSTANCE_INITIALIZER; |
| 201 | 208 |
| 202 } // namespace | 209 } // namespace |
| 203 | 210 |
| 204 void V8Platform::AddTraceStateObserver( | 211 void V8Platform::AddTraceStateObserver( |
| 205 v8::Platform::TraceStateObserver* observer) { | 212 v8::Platform::TraceStateObserver* observer) { |
| 206 g_trace_state_dispatcher.Get().AddObserver(observer); | 213 g_trace_state_dispatcher.Get().AddObserver(observer); |
| 207 } | 214 } |
| 208 | 215 |
| 209 void V8Platform::RemoveTraceStateObserver( | 216 void V8Platform::RemoveTraceStateObserver( |
| 210 v8::Platform::TraceStateObserver* observer) { | 217 v8::Platform::TraceStateObserver* observer) { |
| 211 g_trace_state_dispatcher.Get().RemoveObserver(observer); | 218 g_trace_state_dispatcher.Get().RemoveObserver(observer); |
| 212 } | 219 } |
| 213 | 220 |
| 214 } // namespace gin | 221 } // namespace gin |
| OLD | NEW |