OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project 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 "src/libplatform/default-platform.h" | 5 #include "src/libplatform/default-platform.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "src/base/logging.h" | 10 #include "src/base/logging.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 platform->SetThreadPoolSize(thread_pool_size); | 22 platform->SetThreadPoolSize(thread_pool_size); |
23 platform->EnsureInitialized(); | 23 platform->EnsureInitialized(); |
24 return platform; | 24 return platform; |
25 } | 25 } |
26 | 26 |
27 | 27 |
28 bool PumpMessageLoop(v8::Platform* platform, v8::Isolate* isolate) { | 28 bool PumpMessageLoop(v8::Platform* platform, v8::Isolate* isolate) { |
29 return reinterpret_cast<DefaultPlatform*>(platform)->PumpMessageLoop(isolate); | 29 return reinterpret_cast<DefaultPlatform*>(platform)->PumpMessageLoop(isolate); |
30 } | 30 } |
31 | 31 |
| 32 void SetTracingController( |
| 33 v8::Platform* platform, |
| 34 v8::platform::tracing::TracingController* tracing_controller) { |
| 35 return reinterpret_cast<DefaultPlatform*>(platform)->SetTracingController( |
| 36 tracing_controller); |
| 37 } |
| 38 |
32 const int DefaultPlatform::kMaxThreadPoolSize = 8; | 39 const int DefaultPlatform::kMaxThreadPoolSize = 8; |
33 | 40 |
34 DefaultPlatform::DefaultPlatform() | 41 DefaultPlatform::DefaultPlatform() |
35 : initialized_(false), thread_pool_size_(0) {} | 42 : initialized_(false), thread_pool_size_(0), tracing_controller_(NULL) {} |
36 | |
37 | 43 |
38 DefaultPlatform::~DefaultPlatform() { | 44 DefaultPlatform::~DefaultPlatform() { |
39 base::LockGuard<base::Mutex> guard(&lock_); | 45 base::LockGuard<base::Mutex> guard(&lock_); |
40 queue_.Terminate(); | 46 queue_.Terminate(); |
41 if (initialized_) { | 47 if (initialized_) { |
42 for (auto i = thread_pool_.begin(); i != thread_pool_.end(); ++i) { | 48 for (auto i = thread_pool_.begin(); i != thread_pool_.end(); ++i) { |
43 delete *i; | 49 delete *i; |
44 } | 50 } |
45 } | 51 } |
46 for (auto i = main_thread_queue_.begin(); i != main_thread_queue_.end(); | 52 for (auto i = main_thread_queue_.begin(); i != main_thread_queue_.end(); |
47 ++i) { | 53 ++i) { |
48 while (!i->second.empty()) { | 54 while (!i->second.empty()) { |
49 delete i->second.front(); | 55 delete i->second.front(); |
50 i->second.pop(); | 56 i->second.pop(); |
51 } | 57 } |
52 } | 58 } |
53 for (auto i = main_thread_delayed_queue_.begin(); | 59 for (auto i = main_thread_delayed_queue_.begin(); |
54 i != main_thread_delayed_queue_.end(); ++i) { | 60 i != main_thread_delayed_queue_.end(); ++i) { |
55 while (!i->second.empty()) { | 61 while (!i->second.empty()) { |
56 delete i->second.top().second; | 62 delete i->second.top().second; |
57 i->second.pop(); | 63 i->second.pop(); |
58 } | 64 } |
59 } | 65 } |
| 66 |
| 67 if (tracing_controller_) { |
| 68 delete tracing_controller_; |
| 69 } |
60 } | 70 } |
61 | 71 |
62 | 72 |
63 void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) { | 73 void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) { |
64 base::LockGuard<base::Mutex> guard(&lock_); | 74 base::LockGuard<base::Mutex> guard(&lock_); |
65 DCHECK(thread_pool_size >= 0); | 75 DCHECK(thread_pool_size >= 0); |
66 if (thread_pool_size < 1) { | 76 if (thread_pool_size < 1) { |
67 thread_pool_size = base::SysInfo::NumberOfProcessors() - 1; | 77 thread_pool_size = base::SysInfo::NumberOfProcessors() - 1; |
68 } | 78 } |
69 thread_pool_size_ = | 79 thread_pool_size_ = |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 return base::TimeTicks::HighResolutionNow().ToInternalValue() / | 176 return base::TimeTicks::HighResolutionNow().ToInternalValue() / |
167 static_cast<double>(base::Time::kMicrosecondsPerSecond); | 177 static_cast<double>(base::Time::kMicrosecondsPerSecond); |
168 } | 178 } |
169 | 179 |
170 | 180 |
171 uint64_t DefaultPlatform::AddTraceEvent( | 181 uint64_t DefaultPlatform::AddTraceEvent( |
172 char phase, const uint8_t* category_enabled_flag, const char* name, | 182 char phase, const uint8_t* category_enabled_flag, const char* name, |
173 const char* scope, uint64_t id, uint64_t bind_id, int num_args, | 183 const char* scope, uint64_t id, uint64_t bind_id, int num_args, |
174 const char** arg_names, const uint8_t* arg_types, | 184 const char** arg_names, const uint8_t* arg_types, |
175 const uint64_t* arg_values, unsigned int flags) { | 185 const uint64_t* arg_values, unsigned int flags) { |
| 186 if (tracing_controller_) { |
| 187 return tracing_controller_->AddTraceEvent( |
| 188 phase, category_enabled_flag, name, scope, id, bind_id, num_args, |
| 189 arg_names, arg_types, arg_values, flags); |
| 190 } |
| 191 |
176 return 0; | 192 return 0; |
177 } | 193 } |
178 | 194 |
179 | |
180 void DefaultPlatform::UpdateTraceEventDuration( | 195 void DefaultPlatform::UpdateTraceEventDuration( |
181 const uint8_t* category_enabled_flag, const char* name, uint64_t handle) {} | 196 const uint8_t* category_enabled_flag, const char* name, uint64_t handle) { |
182 | 197 if (tracing_controller_) { |
| 198 tracing_controller_->UpdateTraceEventDuration(category_enabled_flag, name, |
| 199 handle); |
| 200 } |
| 201 } |
183 | 202 |
184 const uint8_t* DefaultPlatform::GetCategoryGroupEnabled(const char* name) { | 203 const uint8_t* DefaultPlatform::GetCategoryGroupEnabled(const char* name) { |
| 204 if (tracing_controller_) { |
| 205 return tracing_controller_->GetCategoryGroupEnabled(name); |
| 206 } |
185 static uint8_t no = 0; | 207 static uint8_t no = 0; |
186 return &no; | 208 return &no; |
187 } | 209 } |
188 | 210 |
189 | 211 |
190 const char* DefaultPlatform::GetCategoryGroupName( | 212 const char* DefaultPlatform::GetCategoryGroupName( |
191 const uint8_t* category_enabled_flag) { | 213 const uint8_t* category_enabled_flag) { |
192 static const char dummy[] = "dummy"; | 214 static const char dummy[] = "dummy"; |
193 return dummy; | 215 return dummy; |
194 } | 216 } |
195 | 217 |
| 218 void DefaultPlatform::SetTracingController( |
| 219 tracing::TracingController* tracing_controller) { |
| 220 tracing_controller_ = tracing_controller; |
| 221 } |
196 | 222 |
197 size_t DefaultPlatform::NumberOfAvailableBackgroundThreads() { | 223 size_t DefaultPlatform::NumberOfAvailableBackgroundThreads() { |
198 return static_cast<size_t>(thread_pool_size_); | 224 return static_cast<size_t>(thread_pool_size_); |
199 } | 225 } |
200 | 226 |
201 } // namespace platform | 227 } // namespace platform |
202 } // namespace v8 | 228 } // namespace v8 |
OLD | NEW |