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" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 } | 76 } |
77 | 77 |
78 private: | 78 private: |
79 SampleBuffer* sample_buffer_; | 79 SampleBuffer* sample_buffer_; |
80 bool own_sample_buffer_; | 80 bool own_sample_buffer_; |
81 | 81 |
82 DISALLOW_COPY_AND_ASSIGN(IsolateProfilerData); | 82 DISALLOW_COPY_AND_ASSIGN(IsolateProfilerData); |
83 }; | 83 }; |
84 | 84 |
85 | 85 |
86 class SampleVisitor { | 86 class SampleVisitor : public ValueObject { |
87 public: | 87 public: |
88 explicit SampleVisitor(Isolate* isolate) : isolate_(isolate), visited_(0) { } | 88 explicit SampleVisitor(Isolate* isolate) : isolate_(isolate), visited_(0) { } |
89 virtual ~SampleVisitor() {} | 89 virtual ~SampleVisitor() {} |
90 | 90 |
91 virtual void VisitSample(Sample* sample) = 0; | 91 virtual void VisitSample(Sample* sample) = 0; |
92 | 92 |
93 intptr_t visited() const { | 93 intptr_t visited() const { |
94 return visited_; | 94 return visited_; |
95 } | 95 } |
96 | 96 |
(...skipping 15 matching lines...) Expand all Loading... | |
112 // The maximum number of stack frames a sample can hold. | 112 // The maximum number of stack frames a sample can hold. |
113 #define kSampleFramesSize 256 | 113 #define kSampleFramesSize 256 |
114 | 114 |
115 // Each Sample holds a stack trace from an isolate. | 115 // Each Sample holds a stack trace from an isolate. |
116 class Sample { | 116 class Sample { |
117 public: | 117 public: |
118 void Init(Isolate* isolate, int64_t timestamp, ThreadId tid) { | 118 void Init(Isolate* isolate, int64_t timestamp, ThreadId tid) { |
119 timestamp_ = timestamp; | 119 timestamp_ = timestamp; |
120 tid_ = tid; | 120 tid_ = tid; |
121 isolate_ = isolate; | 121 isolate_ = isolate; |
122 pc_marker_ = 0; | |
122 vm_tag_ = VMTag::kInvalidTagId; | 123 vm_tag_ = VMTag::kInvalidTagId; |
123 user_tag_ = UserTags::kNoUserTag; | 124 user_tag_ = UserTags::kNoUserTag; |
125 sp_ = 0; | |
126 fp_ = 0; | |
127 state_ = 0; | |
124 for (intptr_t i = 0; i < kSampleFramesSize; i++) { | 128 for (intptr_t i = 0; i < kSampleFramesSize; i++) { |
125 pcs_[i] = 0; | 129 pcs_[i] = 0; |
126 } | 130 } |
127 } | 131 } |
128 | 132 |
129 // Isolate sample was taken from. | 133 // Isolate sample was taken from. |
130 Isolate* isolate() const { | 134 Isolate* isolate() const { |
131 return isolate_; | 135 return isolate_; |
132 } | 136 } |
133 | 137 |
(...skipping 24 matching lines...) Expand all Loading... | |
158 vm_tag_ = tag; | 162 vm_tag_ = tag; |
159 } | 163 } |
160 | 164 |
161 uword user_tag() const { | 165 uword user_tag() const { |
162 return user_tag_; | 166 return user_tag_; |
163 } | 167 } |
164 void set_user_tag(uword tag) { | 168 void set_user_tag(uword tag) { |
165 user_tag_ = tag; | 169 user_tag_ = tag; |
166 } | 170 } |
167 | 171 |
172 uword pc_marker() const { | |
173 return pc_marker_; | |
174 } | |
175 | |
176 void set_pc_marker(uword pc_marker) { | |
177 pc_marker_ = pc_marker; | |
178 } | |
179 | |
180 uword sp() { | |
siva
2014/05/02 20:43:37
const
| |
181 return sp_; | |
182 } | |
183 | |
184 void set_sp(uword sp) { | |
185 sp_ = sp; | |
186 } | |
187 | |
188 uword fp() { | |
siva
2014/05/02 20:43:37
const
| |
189 return fp_; | |
190 } | |
191 | |
192 void set_fp(uword fp) { | |
193 fp_ = fp; | |
194 } | |
195 | |
196 void InsertCallerForTopFrame(uword pc) { | |
197 // Shift all entries down. | |
siva
2014/05/02 20:43:37
Maybe you should add a comment here indicating wha
| |
198 for (intptr_t i = 1; i < kSampleFramesSize - 1; i++) { | |
199 pcs_[i + 1] = pcs_[i]; | |
200 } | |
201 pcs_[1] = pc; | |
202 } | |
203 | |
204 bool processed() const { | |
205 return ProcessedBit::decode(state_); | |
206 } | |
207 | |
208 void set_processed(bool processed) { | |
209 state_ = ProcessedBit::update(processed, state_); | |
210 } | |
211 | |
212 bool leaf_frame_is_dart() const { | |
213 return LeafFrameIsDart::decode(state_); | |
214 } | |
215 | |
216 void set_leaf_frame_is_dart(bool leaf_frame_is_dart) { | |
217 state_ = LeafFrameIsDart::update(leaf_frame_is_dart, state_); | |
218 } | |
219 | |
168 private: | 220 private: |
221 class ProcessedBit : public BitField<bool, 0, 1> {}; | |
222 class LeafFrameIsDart : public BitField<bool, 1, 1> {}; | |
siva
2014/05/02 20:43:37
it would be more readable to enumerate the bits, e
| |
169 int64_t timestamp_; | 223 int64_t timestamp_; |
170 ThreadId tid_; | 224 ThreadId tid_; |
171 Isolate* isolate_; | 225 Isolate* isolate_; |
226 uword pc_marker_; | |
172 uword vm_tag_; | 227 uword vm_tag_; |
173 uword user_tag_; | 228 uword user_tag_; |
229 uword sp_; | |
230 uword fp_; | |
231 uword state_; | |
174 uword pcs_[kSampleFramesSize]; | 232 uword pcs_[kSampleFramesSize]; |
175 }; | 233 }; |
176 | 234 |
177 | 235 |
178 // Ring buffer of Samples that is (usually) shared by many isolates. | 236 // Ring buffer of Samples that is (usually) shared by many isolates. |
179 class SampleBuffer { | 237 class SampleBuffer { |
180 public: | 238 public: |
181 static const intptr_t kDefaultBufferCapacity = 120000; // 2 minutes @ 1000hz. | 239 static const intptr_t kDefaultBufferCapacity = 120000; // 2 minutes @ 1000hz. |
182 | 240 |
183 explicit SampleBuffer(intptr_t capacity = kDefaultBufferCapacity) { | 241 explicit SampleBuffer(intptr_t capacity = kDefaultBufferCapacity) { |
(...skipping 16 matching lines...) Expand all Loading... | |
200 Sample* ReserveSample(); | 258 Sample* ReserveSample(); |
201 | 259 |
202 Sample* At(intptr_t idx) const { | 260 Sample* At(intptr_t idx) const { |
203 ASSERT(idx >= 0); | 261 ASSERT(idx >= 0); |
204 ASSERT(idx < capacity_); | 262 ASSERT(idx < capacity_); |
205 return &samples_[idx]; | 263 return &samples_[idx]; |
206 } | 264 } |
207 | 265 |
208 void VisitSamples(SampleVisitor* visitor) { | 266 void VisitSamples(SampleVisitor* visitor) { |
209 ASSERT(visitor != NULL); | 267 ASSERT(visitor != NULL); |
210 Sample sample; | |
211 const intptr_t length = capacity(); | 268 const intptr_t length = capacity(); |
212 for (intptr_t i = 0; i < length; i++) { | 269 for (intptr_t i = 0; i < length; i++) { |
213 // Copy the sample. | 270 Sample* sample = At(i); |
214 sample = *At(i); | 271 if (sample->isolate() != visitor->isolate()) { |
215 if (sample.isolate() != visitor->isolate()) { | |
216 // Another isolate. | 272 // Another isolate. |
217 continue; | 273 continue; |
218 } | 274 } |
219 if (sample.timestamp() == 0) { | 275 if (sample->timestamp() == 0) { |
220 // Empty. | 276 // Empty. |
221 continue; | 277 continue; |
222 } | 278 } |
223 if (sample.At(0) == 0) { | 279 if (sample->At(0) == 0) { |
224 // No frames. | 280 // No frames. |
225 continue; | 281 continue; |
226 } | 282 } |
227 visitor->IncrementVisited(); | 283 visitor->IncrementVisited(); |
228 visitor->VisitSample(&sample); | 284 visitor->VisitSample(sample); |
229 } | 285 } |
230 } | 286 } |
231 | 287 |
232 private: | 288 private: |
233 Sample* samples_; | 289 Sample* samples_; |
234 intptr_t capacity_; | 290 intptr_t capacity_; |
235 uintptr_t cursor_; | 291 uintptr_t cursor_; |
236 | 292 |
237 DISALLOW_COPY_AND_ASSIGN(SampleBuffer); | 293 DISALLOW_COPY_AND_ASSIGN(SampleBuffer); |
238 }; | 294 }; |
239 | 295 |
240 | 296 |
241 } // namespace dart | 297 } // namespace dart |
242 | 298 |
243 #endif // VM_PROFILER_H_ | 299 #endif // VM_PROFILER_H_ |
OLD | NEW |