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 tracing_controller_->StopTracing(); |
| 69 delete tracing_controller_; |
| 70 } |
60 } | 71 } |
61 | 72 |
62 | 73 |
63 void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) { | 74 void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) { |
64 base::LockGuard<base::Mutex> guard(&lock_); | 75 base::LockGuard<base::Mutex> guard(&lock_); |
65 DCHECK(thread_pool_size >= 0); | 76 DCHECK(thread_pool_size >= 0); |
66 if (thread_pool_size < 1) { | 77 if (thread_pool_size < 1) { |
67 thread_pool_size = base::SysInfo::NumberOfProcessors() - 1; | 78 thread_pool_size = base::SysInfo::NumberOfProcessors() - 1; |
68 } | 79 } |
69 thread_pool_size_ = | 80 thread_pool_size_ = |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 return base::TimeTicks::HighResolutionNow().ToInternalValue() / | 177 return base::TimeTicks::HighResolutionNow().ToInternalValue() / |
167 static_cast<double>(base::Time::kMicrosecondsPerSecond); | 178 static_cast<double>(base::Time::kMicrosecondsPerSecond); |
168 } | 179 } |
169 | 180 |
170 | 181 |
171 uint64_t DefaultPlatform::AddTraceEvent( | 182 uint64_t DefaultPlatform::AddTraceEvent( |
172 char phase, const uint8_t* category_enabled_flag, const char* name, | 183 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, | 184 const char* scope, uint64_t id, uint64_t bind_id, int num_args, |
174 const char** arg_names, const uint8_t* arg_types, | 185 const char** arg_names, const uint8_t* arg_types, |
175 const uint64_t* arg_values, unsigned int flags) { | 186 const uint64_t* arg_values, unsigned int flags) { |
| 187 if (tracing_controller_) { |
| 188 return tracing_controller_->AddTraceEvent( |
| 189 phase, category_enabled_flag, name, scope, id, bind_id, num_args, |
| 190 arg_names, arg_types, arg_values, flags); |
| 191 } |
| 192 |
176 return 0; | 193 return 0; |
177 } | 194 } |
178 | 195 |
179 | |
180 void DefaultPlatform::UpdateTraceEventDuration( | 196 void DefaultPlatform::UpdateTraceEventDuration( |
181 const uint8_t* category_enabled_flag, const char* name, uint64_t handle) {} | 197 const uint8_t* category_enabled_flag, const char* name, uint64_t handle) { |
182 | 198 if (tracing_controller_) { |
| 199 tracing_controller_->UpdateTraceEventDuration(category_enabled_flag, name, |
| 200 handle); |
| 201 } |
| 202 } |
183 | 203 |
184 const uint8_t* DefaultPlatform::GetCategoryGroupEnabled(const char* name) { | 204 const uint8_t* DefaultPlatform::GetCategoryGroupEnabled(const char* name) { |
| 205 if (tracing_controller_) { |
| 206 return tracing_controller_->GetCategoryGroupEnabled(name); |
| 207 } |
185 static uint8_t no = 0; | 208 static uint8_t no = 0; |
186 return &no; | 209 return &no; |
187 } | 210 } |
188 | 211 |
189 | 212 |
190 const char* DefaultPlatform::GetCategoryGroupName( | 213 const char* DefaultPlatform::GetCategoryGroupName( |
191 const uint8_t* category_enabled_flag) { | 214 const uint8_t* category_enabled_flag) { |
192 static const char dummy[] = "dummy"; | 215 static const char dummy[] = "dummy"; |
193 return dummy; | 216 return dummy; |
194 } | 217 } |
195 | 218 |
| 219 void DefaultPlatform::SetTracingController( |
| 220 tracing::TracingController* tracing_controller) { |
| 221 tracing_controller_ = tracing_controller; |
| 222 } |
196 | 223 |
197 size_t DefaultPlatform::NumberOfAvailableBackgroundThreads() { | 224 size_t DefaultPlatform::NumberOfAvailableBackgroundThreads() { |
198 return static_cast<size_t>(thread_pool_size_); | 225 return static_cast<size_t>(thread_pool_size_); |
199 } | 226 } |
200 | 227 |
201 } // namespace platform | 228 } // namespace platform |
202 } // namespace v8 | 229 } // namespace v8 |
OLD | NEW |