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/profiler/sampler.h" | 5 #include "src/profiler/sampler.h" |
6 | 6 |
7 #if V8_OS_POSIX && !V8_OS_CYGWIN | 7 #if V8_OS_POSIX && !V8_OS_CYGWIN |
8 | 8 |
9 #define USE_SIGNALS | 9 #define USE_SIGNALS |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT) | 35 !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT) |
36 #include <asm/sigcontext.h> // NOLINT | 36 #include <asm/sigcontext.h> // NOLINT |
37 #endif | 37 #endif |
38 | 38 |
39 #elif V8_OS_WIN || V8_OS_CYGWIN | 39 #elif V8_OS_WIN || V8_OS_CYGWIN |
40 | 40 |
41 #include "src/base/win32-headers.h" | 41 #include "src/base/win32-headers.h" |
42 | 42 |
43 #endif | 43 #endif |
44 | 44 |
45 #include "src/atomic-utils.h" | 45 #include "src/base/atomic-utils.h" |
46 #include "src/base/platform/platform.h" | 46 #include "src/base/platform/platform.h" |
47 #include "src/flags.h" | 47 #include "src/flags.h" |
48 #include "src/frames-inl.h" | 48 #include "src/frames-inl.h" |
49 #include "src/log.h" | 49 #include "src/log.h" |
50 #include "src/profiler/cpu-profiler-inl.h" | 50 #include "src/profiler/cpu-profiler-inl.h" |
51 #include "src/simulator.h" | 51 #include "src/simulator.h" |
52 #include "src/v8threads.h" | 52 #include "src/v8threads.h" |
53 #include "src/vm-state-inl.h" | 53 #include "src/vm-state-inl.h" |
54 | 54 |
55 | 55 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 235 } |
236 } | 236 } |
237 return false; | 237 return false; |
238 } | 238 } |
239 | 239 |
240 typedef List<Sampler*> SamplerList; | 240 typedef List<Sampler*> SamplerList; |
241 | 241 |
242 #if defined(USE_SIGNALS) | 242 #if defined(USE_SIGNALS) |
243 class AtomicGuard { | 243 class AtomicGuard { |
244 public: | 244 public: |
245 explicit AtomicGuard(AtomicValue<int>* atomic, bool is_block = true) | 245 explicit AtomicGuard(base::AtomicValue<int>* atomic, bool is_block = true) |
246 : atomic_(atomic), | 246 : atomic_(atomic), |
247 is_success_(false) { | 247 is_success_(false) { |
248 do { | 248 do { |
249 // Use Acquire_Load to gain mutual exclusion. | 249 // Use Acquire_Load to gain mutual exclusion. |
250 USE(atomic_->Value()); | 250 USE(atomic_->Value()); |
251 is_success_ = atomic_->TrySetValue(0, 1); | 251 is_success_ = atomic_->TrySetValue(0, 1); |
252 } while (is_block && !is_success_); | 252 } while (is_block && !is_success_); |
253 } | 253 } |
254 | 254 |
255 bool is_success() { return is_success_; } | 255 bool is_success() { return is_success_; } |
256 | 256 |
257 ~AtomicGuard() { | 257 ~AtomicGuard() { |
258 if (is_success_) { | 258 if (is_success_) { |
259 atomic_->SetValue(0); | 259 atomic_->SetValue(0); |
260 } | 260 } |
261 atomic_ = NULL; | 261 atomic_ = NULL; |
262 } | 262 } |
263 | 263 |
264 private: | 264 private: |
265 AtomicValue<int>* atomic_; | 265 base::AtomicValue<int>* atomic_; |
266 bool is_success_; | 266 bool is_success_; |
267 }; | 267 }; |
268 | 268 |
269 | 269 |
270 // Returns key for hash map. | 270 // Returns key for hash map. |
271 void* ThreadKey(pthread_t thread_id) { | 271 void* ThreadKey(pthread_t thread_id) { |
272 return reinterpret_cast<void*>(thread_id); | 272 return reinterpret_cast<void*>(thread_id); |
273 } | 273 } |
274 | 274 |
275 | 275 |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 | 740 |
741 #if defined(USE_SIGNALS) | 741 #if defined(USE_SIGNALS) |
742 struct HashMapCreateTrait { | 742 struct HashMapCreateTrait { |
743 static void Construct(HashMap* allocated_ptr) { | 743 static void Construct(HashMap* allocated_ptr) { |
744 new (allocated_ptr) HashMap(HashMap::PointersMatch); | 744 new (allocated_ptr) HashMap(HashMap::PointersMatch); |
745 } | 745 } |
746 }; | 746 }; |
747 friend class SignalHandler; | 747 friend class SignalHandler; |
748 static base::LazyInstance<HashMap, HashMapCreateTrait>::type | 748 static base::LazyInstance<HashMap, HashMapCreateTrait>::type |
749 thread_id_to_samplers_; | 749 thread_id_to_samplers_; |
750 static AtomicValue<int> sampler_list_access_counter_; | 750 static base::AtomicValue<int> sampler_list_access_counter_; |
751 static void AddSampler(Sampler* sampler) { | 751 static void AddSampler(Sampler* sampler) { |
752 AtomicGuard atomic_guard(&sampler_list_access_counter_); | 752 AtomicGuard atomic_guard(&sampler_list_access_counter_); |
753 // Add sampler into map if needed. | 753 // Add sampler into map if needed. |
754 pthread_t thread_id = sampler->platform_data()->vm_tid(); | 754 pthread_t thread_id = sampler->platform_data()->vm_tid(); |
755 HashMap::Entry *entry = | 755 HashMap::Entry *entry = |
756 thread_id_to_samplers_.Pointer()->LookupOrInsert(ThreadKey(thread_id), | 756 thread_id_to_samplers_.Pointer()->LookupOrInsert(ThreadKey(thread_id), |
757 ThreadHash(thread_id)); | 757 ThreadHash(thread_id)); |
758 if (entry->value == NULL) { | 758 if (entry->value == NULL) { |
759 SamplerList* samplers = new SamplerList(); | 759 SamplerList* samplers = new SamplerList(); |
760 samplers->Add(sampler); | 760 samplers->Add(sampler); |
(...skipping 11 matching lines...) Expand all Loading... |
772 | 772 |
773 DISALLOW_COPY_AND_ASSIGN(SamplerThread); | 773 DISALLOW_COPY_AND_ASSIGN(SamplerThread); |
774 }; | 774 }; |
775 | 775 |
776 | 776 |
777 base::Mutex* SamplerThread::mutex_ = NULL; | 777 base::Mutex* SamplerThread::mutex_ = NULL; |
778 SamplerThread* SamplerThread::instance_ = NULL; | 778 SamplerThread* SamplerThread::instance_ = NULL; |
779 #if defined(USE_SIGNALS) | 779 #if defined(USE_SIGNALS) |
780 base::LazyInstance<HashMap, SamplerThread::HashMapCreateTrait>::type | 780 base::LazyInstance<HashMap, SamplerThread::HashMapCreateTrait>::type |
781 SamplerThread::thread_id_to_samplers_ = LAZY_INSTANCE_INITIALIZER; | 781 SamplerThread::thread_id_to_samplers_ = LAZY_INSTANCE_INITIALIZER; |
782 AtomicValue<int> SamplerThread::sampler_list_access_counter_(0); | 782 base::AtomicValue<int> SamplerThread::sampler_list_access_counter_(0); |
783 | 783 |
784 // As Native Client does not support signal handling, profiling is disabled. | 784 // As Native Client does not support signal handling, profiling is disabled. |
785 #if !V8_OS_NACL | 785 #if !V8_OS_NACL |
786 void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info, | 786 void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info, |
787 void* context) { | 787 void* context) { |
788 USE(info); | 788 USE(info); |
789 if (signal != SIGPROF) return; | 789 if (signal != SIGPROF) return; |
790 AtomicGuard atomic_guard(&SamplerThread::sampler_list_access_counter_, false); | 790 AtomicGuard atomic_guard(&SamplerThread::sampler_list_access_counter_, false); |
791 if (!atomic_guard.is_success()) return; | 791 if (!atomic_guard.is_success()) return; |
792 pthread_t thread_id = pthread_self(); | 792 pthread_t thread_id = pthread_self(); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 SampleStack(state); | 1030 SampleStack(state); |
1031 } | 1031 } |
1032 ResumeThread(profiled_thread); | 1032 ResumeThread(profiled_thread); |
1033 } | 1033 } |
1034 | 1034 |
1035 #endif // USE_SIGNALS | 1035 #endif // USE_SIGNALS |
1036 | 1036 |
1037 | 1037 |
1038 } // namespace internal | 1038 } // namespace internal |
1039 } // namespace v8 | 1039 } // namespace v8 |
OLD | NEW |