| 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 18 matching lines...) Expand all Loading... |
| 29 #endif | 29 #endif |
| 30 DEFINE_FLAG(bool, trace_profiled_isolates, false, "Trace profiled isolates."); | 30 DEFINE_FLAG(bool, trace_profiled_isolates, false, "Trace profiled isolates."); |
| 31 DEFINE_FLAG(charp, profile_dir, NULL, | 31 DEFINE_FLAG(charp, profile_dir, NULL, |
| 32 "Enable writing profile data into specified directory."); | 32 "Enable writing profile data into specified directory."); |
| 33 DEFINE_FLAG(int, profile_period, 1000, | 33 DEFINE_FLAG(int, profile_period, 1000, |
| 34 "Time between profiler samples in microseconds. Minimum 50."); | 34 "Time between profiler samples in microseconds. Minimum 50."); |
| 35 DEFINE_FLAG(int, profile_depth, 8, | 35 DEFINE_FLAG(int, profile_depth, 8, |
| 36 "Maximum number stack frames walked. Minimum 1. Maximum 255."); | 36 "Maximum number stack frames walked. Minimum 1. Maximum 255."); |
| 37 DEFINE_FLAG(bool, profile_verify_stack_walk, false, | 37 DEFINE_FLAG(bool, profile_verify_stack_walk, false, |
| 38 "Verify instruction addresses while walking the stack."); | 38 "Verify instruction addresses while walking the stack."); |
| 39 DEFINE_FLAG(bool, profile_native_stack, true, | 39 DEFINE_FLAG(bool, profile_vm, false, |
| 40 "Use native stack in profiler."); | 40 "Always collect native stack traces."); |
| 41 | 41 |
| 42 bool Profiler::initialized_ = false; | 42 bool Profiler::initialized_ = false; |
| 43 SampleBuffer* Profiler::sample_buffer_ = NULL; | 43 SampleBuffer* Profiler::sample_buffer_ = NULL; |
| 44 | 44 |
| 45 void Profiler::InitOnce() { | 45 void Profiler::InitOnce() { |
| 46 // Place some sane restrictions on user controlled flags. | 46 // Place some sane restrictions on user controlled flags. |
| 47 SetSamplePeriod(FLAG_profile_period); | 47 SetSamplePeriod(FLAG_profile_period); |
| 48 SetSampleDepth(FLAG_profile_depth); | 48 SetSampleDepth(FLAG_profile_depth); |
| 49 Sample::InitOnce(); | 49 Sample::InitOnce(); |
| 50 if (!FLAG_profile) { | 50 if (!FLAG_profile) { |
| (...skipping 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1664 | 1664 |
| 1665 | 1665 |
| 1666 class ProfilerDartStackWalker : public ValueObject { | 1666 class ProfilerDartStackWalker : public ValueObject { |
| 1667 public: | 1667 public: |
| 1668 explicit ProfilerDartStackWalker(Sample* sample) | 1668 explicit ProfilerDartStackWalker(Sample* sample) |
| 1669 : sample_(sample), | 1669 : sample_(sample), |
| 1670 frame_iterator_() { | 1670 frame_iterator_() { |
| 1671 ASSERT(sample_ != NULL); | 1671 ASSERT(sample_ != NULL); |
| 1672 } | 1672 } |
| 1673 | 1673 |
| 1674 ProfilerDartStackWalker(Sample* sample, uword pc, uword fp, uword sp) | |
| 1675 : sample_(sample), | |
| 1676 frame_iterator_(fp, sp, pc) { | |
| 1677 ASSERT(sample_ != NULL); | |
| 1678 } | |
| 1679 | |
| 1680 ProfilerDartStackWalker(Sample* sample, uword fp) | 1674 ProfilerDartStackWalker(Sample* sample, uword fp) |
| 1681 : sample_(sample), | 1675 : sample_(sample), |
| 1682 frame_iterator_(fp) { | 1676 frame_iterator_(fp) { |
| 1683 ASSERT(sample_ != NULL); | 1677 ASSERT(sample_ != NULL); |
| 1684 } | 1678 } |
| 1685 | 1679 |
| 1686 int walk() { | 1680 int walk() { |
| 1687 intptr_t frame_index = 0; | 1681 intptr_t frame_index = 0; |
| 1688 StackFrame* frame = frame_iterator_.NextFrame(); | 1682 StackFrame* frame = frame_iterator_.NextFrame(); |
| 1689 while (frame != NULL) { | 1683 while (frame != NULL) { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1874 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); | 1868 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); |
| 1875 if (sample_buffer == NULL) { | 1869 if (sample_buffer == NULL) { |
| 1876 return; | 1870 return; |
| 1877 } | 1871 } |
| 1878 Sample* sample = sample_buffer->ReserveSample(); | 1872 Sample* sample = sample_buffer->ReserveSample(); |
| 1879 sample->Init(isolate, OS::GetCurrentTimeMicros(), state.tid); | 1873 sample->Init(isolate, OS::GetCurrentTimeMicros(), state.tid); |
| 1880 sample->set_vm_tag(isolate->vm_tag()); | 1874 sample->set_vm_tag(isolate->vm_tag()); |
| 1881 sample->set_user_tag(isolate->user_tag()); | 1875 sample->set_user_tag(isolate->user_tag()); |
| 1882 sample->set_sp(state.sp); | 1876 sample->set_sp(state.sp); |
| 1883 sample->set_fp(state.fp); | 1877 sample->set_fp(state.fp); |
| 1884 if (FLAG_profile_native_stack) { | 1878 |
| 1879 uword stack_lower = 0; |
| 1880 uword stack_upper = 0; |
| 1881 isolate->GetStackBounds(&stack_lower, &stack_upper); |
| 1882 if ((stack_lower == 0) || (stack_upper == 0)) { |
| 1883 stack_lower = 0; |
| 1884 stack_upper = 0; |
| 1885 } |
| 1886 if (FLAG_profile_vm) { |
| 1885 // Collect native and Dart frames. | 1887 // Collect native and Dart frames. |
| 1886 uword stack_lower = 0; | |
| 1887 uword stack_upper = 0; | |
| 1888 isolate->GetStackBounds(&stack_lower, &stack_upper); | |
| 1889 if ((stack_lower == 0) || (stack_upper == 0)) { | |
| 1890 stack_lower = 0; | |
| 1891 stack_upper = 0; | |
| 1892 } | |
| 1893 ProfilerNativeStackWalker stackWalker(sample, stack_lower, stack_upper, | 1888 ProfilerNativeStackWalker stackWalker(sample, stack_lower, stack_upper, |
| 1894 state.pc, state.fp, state.sp); | 1889 state.pc, state.fp, state.sp); |
| 1895 stackWalker.walk(isolate->heap()); | 1890 stackWalker.walk(isolate->heap()); |
| 1896 } else { | 1891 } else { |
| 1897 if ((isolate->top_exit_frame_info() != 0) && | 1892 if ((isolate->stub_code() != NULL) && |
| 1898 (isolate->stub_code() != NULL)) { | 1893 (isolate->top_exit_frame_info() != 0)) { |
| 1894 // Collect only Dart frames. |
| 1899 ProfilerDartStackWalker stackWalker(sample); | 1895 ProfilerDartStackWalker stackWalker(sample); |
| 1900 stackWalker.walk(); | 1896 stackWalker.walk(); |
| 1901 } else { | 1897 } else { |
| 1902 // TODO(johnmccutchan): Support collecting only Dart frames with | 1898 // Collect native and Dart frames. |
| 1903 // ProfilerNativeStackWalker. | 1899 ProfilerNativeStackWalker stackWalker(sample, stack_lower, stack_upper, |
| 1900 state.pc, state.fp, state.sp); |
| 1901 stackWalker.walk(isolate->heap()); |
| 1904 } | 1902 } |
| 1905 } | 1903 } |
| 1906 } | 1904 } |
| 1907 | 1905 |
| 1908 } // namespace dart | 1906 } // namespace dart |
| OLD | NEW |