| 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/utils.h" | 5 #include "platform/utils.h" |
| 6 | 6 |
| 7 #include "vm/allocation.h" | 7 #include "vm/allocation.h" |
| 8 #include "vm/atomic.h" | 8 #include "vm/atomic.h" |
| 9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #if defined(USING_SIMULATOR) || defined(TARGET_OS_WINDOWS) || \ | 23 #if defined(USING_SIMULATOR) || defined(TARGET_OS_WINDOWS) || \ |
| 24 defined(TARGET_OS_ANDROID) | 24 defined(TARGET_OS_ANDROID) |
| 25 DEFINE_FLAG(bool, profile, false, "Enable Sampling Profiler"); | 25 DEFINE_FLAG(bool, profile, false, "Enable Sampling Profiler"); |
| 26 #else | 26 #else |
| 27 DEFINE_FLAG(bool, profile, true, "Enable Sampling Profiler"); | 27 DEFINE_FLAG(bool, profile, true, "Enable Sampling Profiler"); |
| 28 #endif | 28 #endif |
| 29 DEFINE_FLAG(bool, trace_profiled_isolates, false, "Trace profiled isolates."); | 29 DEFINE_FLAG(bool, trace_profiled_isolates, false, "Trace profiled isolates."); |
| 30 DEFINE_FLAG(charp, profile_dir, NULL, | 30 DEFINE_FLAG(charp, profile_dir, NULL, |
| 31 "Enable writing profile data into specified directory."); | 31 "Enable writing profile data into specified directory."); |
| 32 DEFINE_FLAG(int, profile_period, 1000, | 32 DEFINE_FLAG(int, profile_period, 1000, |
| 33 "Time between profiler samples in microseconds. Minimum 250."); | 33 "Time between profiler samples in microseconds. Minimum 50."); |
| 34 DEFINE_FLAG(int, profile_depth, 8, | 34 DEFINE_FLAG(int, profile_depth, 8, |
| 35 "Maximum number stack frames walked. Minimum 1. Maximum 255."); | 35 "Maximum number stack frames walked. Minimum 1. Maximum 255."); |
| 36 DEFINE_FLAG(bool, profile_verify_stack_walk, false, | 36 DEFINE_FLAG(bool, profile_verify_stack_walk, false, |
| 37 "Verify instruction addresses while walking the stack."); | 37 "Verify instruction addresses while walking the stack."); |
| 38 DEFINE_FLAG(bool, profile_native_stack, true, | 38 DEFINE_FLAG(bool, profile_native_stack, true, |
| 39 "Use native stack in profiler."); | 39 "Use native stack in profiler."); |
| 40 | 40 |
| 41 bool Profiler::initialized_ = false; | 41 bool Profiler::initialized_ = false; |
| 42 SampleBuffer* Profiler::sample_buffer_ = NULL; | 42 SampleBuffer* Profiler::sample_buffer_ = NULL; |
| 43 | 43 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 74 FLAG_profile_depth = kMinimumDepth; | 74 FLAG_profile_depth = kMinimumDepth; |
| 75 } else if (depth > kMaximumDepth) { | 75 } else if (depth > kMaximumDepth) { |
| 76 FLAG_profile_depth = kMaximumDepth; | 76 FLAG_profile_depth = kMaximumDepth; |
| 77 } else { | 77 } else { |
| 78 FLAG_profile_depth = depth; | 78 FLAG_profile_depth = depth; |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 void Profiler::SetSamplePeriod(intptr_t period) { | 83 void Profiler::SetSamplePeriod(intptr_t period) { |
| 84 const int kMinimumProfilePeriod = 250; | 84 const int kMinimumProfilePeriod = 50; |
| 85 if (period < kMinimumProfilePeriod) { | 85 if (period < kMinimumProfilePeriod) { |
| 86 FLAG_profile_period = kMinimumProfilePeriod; | 86 FLAG_profile_period = kMinimumProfilePeriod; |
| 87 } else { | 87 } else { |
| 88 FLAG_profile_period = period; | 88 FLAG_profile_period = period; |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 | 92 |
| 93 void Profiler::InitProfilingForIsolate(Isolate* isolate, bool shared_buffer) { | 93 void Profiler::InitProfilingForIsolate(Isolate* isolate, bool shared_buffer) { |
| 94 if (!FLAG_profile) { | 94 if (!FLAG_profile) { |
| 95 return; | 95 return; |
| 96 } | 96 } |
| 97 ASSERT(isolate == Isolate::Current()); |
| 97 ASSERT(isolate != NULL); | 98 ASSERT(isolate != NULL); |
| 98 ASSERT(sample_buffer_ != NULL); | 99 ASSERT(sample_buffer_ != NULL); |
| 99 { | 100 { |
| 100 MutexLocker profiler_data_lock(isolate->profiler_data_mutex()); | 101 MutexLocker profiler_data_lock(isolate->profiler_data_mutex()); |
| 101 SampleBuffer* sample_buffer = sample_buffer_; | 102 SampleBuffer* sample_buffer = sample_buffer_; |
| 102 if (!shared_buffer) { | 103 if (!shared_buffer) { |
| 103 sample_buffer = new SampleBuffer(); | 104 sample_buffer = new SampleBuffer(); |
| 104 } | 105 } |
| 105 IsolateProfilerData* profiler_data = | 106 IsolateProfilerData* profiler_data = |
| 106 new IsolateProfilerData(sample_buffer, !shared_buffer); | 107 new IsolateProfilerData(sample_buffer, !shared_buffer); |
| 107 ASSERT(profiler_data != NULL); | 108 ASSERT(profiler_data != NULL); |
| 108 isolate->set_profiler_data(profiler_data); | 109 isolate->set_profiler_data(profiler_data); |
| 109 if (FLAG_trace_profiled_isolates) { | 110 if (FLAG_trace_profiled_isolates) { |
| 110 OS::Print("Profiler Setup %p %s\n", isolate, isolate->name()); | 111 OS::Print("Profiler Setup %p %s\n", isolate, isolate->name()); |
| 111 } | 112 } |
| 112 } | 113 } |
| 114 BeginExecution(isolate); |
| 113 } | 115 } |
| 114 | 116 |
| 115 | 117 |
| 116 void Profiler::ShutdownProfilingForIsolate(Isolate* isolate) { | 118 void Profiler::ShutdownProfilingForIsolate(Isolate* isolate) { |
| 117 ASSERT(isolate != NULL); | 119 ASSERT(isolate != NULL); |
| 118 if (!FLAG_profile) { | 120 if (!FLAG_profile) { |
| 119 return; | 121 return; |
| 120 } | 122 } |
| 121 // We do not have a current isolate. | 123 // We do not have a current isolate. |
| 122 ASSERT(Isolate::Current() == NULL); | 124 ASSERT(Isolate::Current() == NULL); |
| (...skipping 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1681 | 1683 |
| 1682 | 1684 |
| 1683 void Profiler::RecordSampleInterruptCallback( | 1685 void Profiler::RecordSampleInterruptCallback( |
| 1684 const InterruptedThreadState& state, | 1686 const InterruptedThreadState& state, |
| 1685 void* data) { | 1687 void* data) { |
| 1686 Isolate* isolate = reinterpret_cast<Isolate*>(data); | 1688 Isolate* isolate = reinterpret_cast<Isolate*>(data); |
| 1687 if ((isolate == NULL) || (Dart::vm_isolate() == NULL)) { | 1689 if ((isolate == NULL) || (Dart::vm_isolate() == NULL)) { |
| 1688 return; | 1690 return; |
| 1689 } | 1691 } |
| 1690 ASSERT(isolate != Dart::vm_isolate()); | 1692 ASSERT(isolate != Dart::vm_isolate()); |
| 1691 ASSERT(isolate->stub_code() != NULL); | |
| 1692 VMTagCounters* counters = isolate->vm_tag_counters(); | 1693 VMTagCounters* counters = isolate->vm_tag_counters(); |
| 1693 ASSERT(counters != NULL); | 1694 ASSERT(counters != NULL); |
| 1694 counters->Increment(isolate->vm_tag()); | 1695 counters->Increment(isolate->vm_tag()); |
| 1695 IsolateProfilerData* profiler_data = isolate->profiler_data(); | 1696 IsolateProfilerData* profiler_data = isolate->profiler_data(); |
| 1696 if (profiler_data == NULL) { | 1697 if (profiler_data == NULL) { |
| 1697 return; | 1698 return; |
| 1698 } | 1699 } |
| 1699 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); | 1700 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); |
| 1700 if (sample_buffer == NULL) { | 1701 if (sample_buffer == NULL) { |
| 1701 return; | 1702 return; |
| 1702 } | 1703 } |
| 1703 Sample* sample = sample_buffer->ReserveSample(); | 1704 Sample* sample = sample_buffer->ReserveSample(); |
| 1704 sample->Init(isolate, OS::GetCurrentTimeMicros(), state.tid); | 1705 sample->Init(isolate, OS::GetCurrentTimeMicros(), state.tid); |
| 1705 sample->set_vm_tag(isolate->vm_tag()); | 1706 sample->set_vm_tag(isolate->vm_tag()); |
| 1706 sample->set_user_tag(isolate->user_tag()); | 1707 sample->set_user_tag(isolate->user_tag()); |
| 1707 if (FLAG_profile_native_stack) { | 1708 if (FLAG_profile_native_stack) { |
| 1708 // Collect native and Dart frames. | 1709 // Collect native and Dart frames. |
| 1709 uword stack_lower = 0; | 1710 uword stack_lower = 0; |
| 1710 uword stack_upper = 0; | 1711 uword stack_upper = 0; |
| 1711 isolate->GetStackBounds(&stack_lower, &stack_upper); | 1712 isolate->GetStackBounds(&stack_lower, &stack_upper); |
| 1712 if ((stack_lower == 0) || (stack_upper == 0)) { | 1713 if ((stack_lower == 0) || (stack_upper == 0)) { |
| 1713 stack_lower = 0; | 1714 stack_lower = 0; |
| 1714 stack_upper = 0; | 1715 stack_upper = 0; |
| 1715 } | 1716 } |
| 1716 ProfilerNativeStackWalker stackWalker(sample, stack_lower, stack_upper, | 1717 ProfilerNativeStackWalker stackWalker(sample, stack_lower, stack_upper, |
| 1717 state.pc, state.fp, state.sp); | 1718 state.pc, state.fp, state.sp); |
| 1718 stackWalker.walk(isolate->heap()); | 1719 stackWalker.walk(isolate->heap()); |
| 1719 } else { | 1720 } else { |
| 1720 if (isolate->top_exit_frame_info() != 0) { | 1721 if ((isolate->top_exit_frame_info() != 0) && |
| 1722 (isolate->stub_code() != NULL)) { |
| 1721 ProfilerDartStackWalker stackWalker(sample); | 1723 ProfilerDartStackWalker stackWalker(sample); |
| 1722 stackWalker.walk(); | 1724 stackWalker.walk(); |
| 1723 } else { | 1725 } else { |
| 1724 // TODO(johnmccutchan): Support collecting only Dart frames with | 1726 // TODO(johnmccutchan): Support collecting only Dart frames with |
| 1725 // ProfilerNativeStackWalker. | 1727 // ProfilerNativeStackWalker. |
| 1726 } | 1728 } |
| 1727 } | 1729 } |
| 1728 } | 1730 } |
| 1729 | 1731 |
| 1730 } // namespace dart | 1732 } // namespace dart |
| OLD | NEW |