| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 7 | 7 |
| 8 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
| 9 #include "vm/json_stream.h" | 9 #include "vm/json_stream.h" |
| 10 #include "vm/profiler.h" | 10 #include "vm/profiler.h" |
| 11 #include "vm/signal_handler.h" | 11 #include "vm/signal_handler.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 DECLARE_FLAG(bool, profile); | 15 DECLARE_FLAG(bool, profile); |
| 16 | 16 |
| 17 static void CollectSample(IsolateProfilerData* profiler_data, | |
| 18 uintptr_t pc, | |
| 19 uintptr_t fp, | |
| 20 uintptr_t sp, | |
| 21 uintptr_t stack_lower, | |
| 22 uintptr_t stack_upper) { | |
| 23 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); | |
| 24 Sample* sample = sample_buffer->ReserveSample(); | |
| 25 ASSERT(sample != NULL); | |
| 26 sample->timestamp = OS::GetCurrentTimeMicros(); | |
| 27 } | |
| 28 | |
| 29 | 17 |
| 30 static void ProfileSignalAction(int signal, siginfo_t* info, void* context_) { | 18 static void ProfileSignalAction(int signal, siginfo_t* info, void* context_) { |
| 31 if (signal != SIGPROF) { | 19 if (signal != SIGPROF) { |
| 32 return; | 20 return; |
| 33 } | 21 } |
| 34 ucontext_t* context = reinterpret_cast<ucontext_t*>(context_); | |
| 35 mcontext_t mcontext = context->uc_mcontext; | |
| 36 Isolate* isolate = Isolate::Current(); | 22 Isolate* isolate = Isolate::Current(); |
| 37 if (isolate == NULL) { | 23 if (isolate == NULL) { |
| 38 return; | 24 return; |
| 39 } | 25 } |
| 40 // Thread owns no profiler locks at this point. | 26 // Thread owns no profiler locks at this point. |
| 41 { | 27 { |
| 42 // Thread owns isolate profiler data mutex. | 28 // Thread owns isolate profiler data mutex. |
| 43 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex()); | 29 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex()); |
| 44 IsolateProfilerData* profiler_data = isolate->profiler_data(); | 30 IsolateProfilerData* profiler_data = isolate->profiler_data(); |
| 45 if (profiler_data == NULL) { | 31 if (profiler_data == NULL) { |
| 46 return; | 32 return; |
| 47 } | 33 } |
| 48 uintptr_t stack_lower = 0; | |
| 49 uintptr_t stack_upper = 0; | |
| 50 isolate->GetStackBounds(&stack_lower, &stack_upper); | |
| 51 uintptr_t PC = SignalHandler::GetProgramCounter(mcontext); | |
| 52 uintptr_t FP = SignalHandler::GetFramePointer(mcontext); | |
| 53 uintptr_t SP = SignalHandler::GetStackPointer(mcontext); | |
| 54 int64_t sample_time = OS::GetCurrentTimeMicros(); | |
| 55 profiler_data->SampledAt(sample_time); | |
| 56 CollectSample(profiler_data, PC, FP, SP, stack_lower, stack_upper); | |
| 57 } | 34 } |
| 58 // Thread owns no profiler locks at this point. | 35 // Thread owns no profiler locks at this point. |
| 59 // This call will acquire both ProfilerManager::monitor and the | 36 // This call will acquire both ProfilerManager::monitor and the |
| 60 // isolate's profiler data mutex. | 37 // isolate's profiler data mutex. |
| 61 ProfilerManager::ScheduleIsolate(isolate); | 38 ProfilerManager::ScheduleIsolate(isolate); |
| 62 } | 39 } |
| 63 | 40 |
| 64 | 41 |
| 65 int64_t ProfilerManager::SampleAndRescheduleIsolates(int64_t current_time) { | 42 int64_t ProfilerManager::SampleAndRescheduleIsolates(int64_t current_time) { |
| 66 if (isolates_size_ == 0) { | 43 if (isolates_size_ == 0) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 int64_t current_time = OS::GetCurrentTimeMicros(); | 90 int64_t current_time = OS::GetCurrentTimeMicros(); |
| 114 int64_t next_sample = SampleAndRescheduleIsolates(current_time); | 91 int64_t next_sample = SampleAndRescheduleIsolates(current_time); |
| 115 lock.WaitMicros(next_sample); | 92 lock.WaitMicros(next_sample); |
| 116 } | 93 } |
| 117 } | 94 } |
| 118 | 95 |
| 119 | 96 |
| 120 } // namespace dart | 97 } // namespace dart |
| 121 | 98 |
| 122 #endif // defined(TARGET_OS_ANDROID) | 99 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |