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

Side by Side Diff: gin/v8_platform.cc

Issue 2456073004: [Tracing] Create TracingCategoryObserver in gin/. (Closed)
Patch Set: rebase Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698