| 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 #ifndef VM_PROFILER_H_ | 5 #ifndef VM_PROFILER_H_ |
| 6 #define VM_PROFILER_H_ | 6 #define VM_PROFILER_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/code_observers.h" | 9 #include "vm/code_observers.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| 11 #include "vm/thread.h" | 11 #include "vm/thread.h" |
| 12 #include "vm/thread_interrupter.h" | 12 #include "vm/thread_interrupter.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 | 15 |
| 16 // Forward declarations. | 16 // Forward declarations. |
| 17 class JSONArray; | 17 class JSONArray; |
| 18 class JSONStream; | 18 class JSONStream; |
| 19 class ProfilerCodeRegionTable; | 19 class ProfilerCodeRegionTable; |
| 20 struct Sample; | 20 class Sample; |
| 21 class SampleBuffer; |
| 21 | 22 |
| 22 // Profiler | 23 // Profiler |
| 23 class Profiler : public AllStatic { | 24 class Profiler : public AllStatic { |
| 24 public: | 25 public: |
| 25 static void InitOnce(); | 26 static void InitOnce(); |
| 26 static void Shutdown(); | 27 static void Shutdown(); |
| 27 | 28 |
| 28 static void InitProfilingForIsolate(Isolate* isolate, | 29 static void InitProfilingForIsolate(Isolate* isolate, |
| 29 bool shared_buffer = true); | 30 bool shared_buffer = true); |
| 30 static void ShutdownProfilingForIsolate(Isolate* isolate); | 31 static void ShutdownProfilingForIsolate(Isolate* isolate); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 75 } |
| 75 | 76 |
| 76 private: | 77 private: |
| 77 SampleBuffer* sample_buffer_; | 78 SampleBuffer* sample_buffer_; |
| 78 bool own_sample_buffer_; | 79 bool own_sample_buffer_; |
| 79 DISALLOW_COPY_AND_ASSIGN(IsolateProfilerData); | 80 DISALLOW_COPY_AND_ASSIGN(IsolateProfilerData); |
| 80 }; | 81 }; |
| 81 | 82 |
| 82 | 83 |
| 83 // Profile sample. | 84 // Profile sample. |
| 84 struct Sample { | 85 class Sample { |
| 85 static const intptr_t kNumStackFrames = 6; | 86 public: |
| 86 enum SampleType { | 87 enum SampleType { |
| 87 kIsolateStart, | |
| 88 kIsolateStop, | |
| 89 kIsolateSample, | 88 kIsolateSample, |
| 90 }; | 89 }; |
| 91 int64_t timestamp; | |
| 92 ThreadId tid; | |
| 93 Isolate* isolate; | |
| 94 uintptr_t pcs[kNumStackFrames]; | |
| 95 SampleType type; | |
| 96 uint16_t vm_tags; | |
| 97 uint16_t runtime_tags; | |
| 98 | 90 |
| 91 static void InitOnce(); |
| 92 |
| 93 uintptr_t At(intptr_t i) const; |
| 94 void SetAt(intptr_t i, uintptr_t pc); |
| 99 void Init(SampleType type, Isolate* isolate, int64_t timestamp, ThreadId tid); | 95 void Init(SampleType type, Isolate* isolate, int64_t timestamp, ThreadId tid); |
| 96 void CopyInto(Sample* dst) const; |
| 97 |
| 98 static Sample* Allocate(); |
| 99 static intptr_t instance_size() { |
| 100 return instance_size_; |
| 101 } |
| 102 |
| 103 SampleType type() const { |
| 104 return type_; |
| 105 } |
| 106 |
| 107 Isolate* isolate() const { |
| 108 return isolate_; |
| 109 } |
| 110 |
| 111 int64_t timestamp() const { |
| 112 return timestamp_; |
| 113 } |
| 114 |
| 115 private: |
| 116 static intptr_t instance_size_; |
| 117 int64_t timestamp_; |
| 118 ThreadId tid_; |
| 119 Isolate* isolate_; |
| 120 SampleType type_; |
| 121 // Note: This class has a size determined at run-time. The pcs_ array |
| 122 // must be the final field. |
| 123 uintptr_t pcs_[0]; |
| 124 |
| 125 DISALLOW_COPY_AND_ASSIGN(Sample); |
| 100 }; | 126 }; |
| 101 | 127 |
| 102 | 128 |
| 103 // Ring buffer of samples. | 129 // Ring buffer of samples. |
| 104 class SampleBuffer { | 130 class SampleBuffer { |
| 105 public: | 131 public: |
| 106 static const intptr_t kDefaultBufferCapacity = 120000; // 2 minutes @ 1000hz. | 132 static const intptr_t kDefaultBufferCapacity = 120000; // 2 minutes @ 1000hz. |
| 107 | 133 |
| 108 explicit SampleBuffer(intptr_t capacity = kDefaultBufferCapacity); | 134 explicit SampleBuffer(intptr_t capacity = kDefaultBufferCapacity); |
| 109 ~SampleBuffer(); | 135 ~SampleBuffer(); |
| 110 | 136 |
| 111 intptr_t capacity() const { return capacity_; } | 137 intptr_t capacity() const { return capacity_; } |
| 112 | |
| 113 Sample* ReserveSample(); | 138 Sample* ReserveSample(); |
| 114 | 139 void CopySample(intptr_t i, Sample* sample) const; |
| 115 Sample GetSample(intptr_t i) const { | 140 Sample* At(intptr_t idx) const; |
| 116 ASSERT(i >= 0); | |
| 117 ASSERT(i < capacity_); | |
| 118 return samples_[i]; | |
| 119 } | |
| 120 | 141 |
| 121 private: | 142 private: |
| 122 Sample* samples_; | 143 Sample* samples_; |
| 123 intptr_t capacity_; | 144 intptr_t capacity_; |
| 124 uintptr_t cursor_; | 145 uintptr_t cursor_; |
| 125 | 146 |
| 126 DISALLOW_COPY_AND_ASSIGN(SampleBuffer); | 147 DISALLOW_COPY_AND_ASSIGN(SampleBuffer); |
| 127 }; | 148 }; |
| 128 | 149 |
| 129 | 150 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 152 const uintptr_t original_pc_; | 173 const uintptr_t original_pc_; |
| 153 const uintptr_t original_fp_; | 174 const uintptr_t original_fp_; |
| 154 const uintptr_t original_sp_; | 175 const uintptr_t original_sp_; |
| 155 uintptr_t lower_bound_; | 176 uintptr_t lower_bound_; |
| 156 }; | 177 }; |
| 157 | 178 |
| 158 | 179 |
| 159 } // namespace dart | 180 } // namespace dart |
| 160 | 181 |
| 161 #endif // VM_PROFILER_H_ | 182 #endif // VM_PROFILER_H_ |
| OLD | NEW |