Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: runtime/vm/profiler.h

Issue 264933006: Fix edge case where profiler would miss the caller of the top frame (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/profiler.cc » ('j') | runtime/vm/profiler.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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() {
181 return sp_;
182 }
183
184 void set_sp(uword sp) {
185 sp_ = sp;
186 }
187
188 uword fp() {
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.
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> {};
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 14 matching lines...) Expand all
198 intptr_t capacity() const { return capacity_; } 256 intptr_t capacity() const { return capacity_; }
199 257
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) {
srdjan 2014/05/02 18:20:29 Remove one of VisitSamples/VisitSamplesByReference
Cutch 2014/05/02 18:37:03 Done.
209 ASSERT(visitor != NULL); 267 ASSERT(visitor != NULL);
210 Sample sample; 268 Sample sample;
211 const intptr_t length = capacity(); 269 const intptr_t length = capacity();
212 for (intptr_t i = 0; i < length; i++) { 270 for (intptr_t i = 0; i < length; i++) {
213 // Copy the sample. 271 // Copy the sample.
214 sample = *At(i); 272 sample = *At(i);
215 if (sample.isolate() != visitor->isolate()) { 273 if (sample.isolate() != visitor->isolate()) {
216 // Another isolate. 274 // Another isolate.
217 continue; 275 continue;
218 } 276 }
219 if (sample.timestamp() == 0) { 277 if (sample.timestamp() == 0) {
220 // Empty. 278 // Empty.
221 continue; 279 continue;
222 } 280 }
223 if (sample.At(0) == 0) { 281 if (sample.At(0) == 0) {
224 // No frames. 282 // No frames.
225 continue; 283 continue;
226 } 284 }
227 visitor->IncrementVisited(); 285 visitor->IncrementVisited();
228 visitor->VisitSample(&sample); 286 visitor->VisitSample(&sample);
229 } 287 }
230 } 288 }
231 289
290 void VisitSamplesByReference(SampleVisitor* visitor) {
291 ASSERT(visitor != NULL);
292 Sample* sample;
293 const intptr_t length = capacity();
294 for (intptr_t i = 0; i < length; i++) {
295 sample = At(i);
srdjan 2014/05/02 18:20:29 You can put Sample* sample = At(i); here. OR const
Cutch 2014/05/02 18:37:03 Done.
296 if (sample->isolate() != visitor->isolate()) {
297 // Another isolate.
298 continue;
299 }
300 if (sample->timestamp() == 0) {
301 // Empty.
302 continue;
303 }
304 if (sample->At(0) == 0) {
305 // No frames.
306 continue;
307 }
308 visitor->IncrementVisited();
309 visitor->VisitSample(sample);
310 }
311 }
312
232 private: 313 private:
233 Sample* samples_; 314 Sample* samples_;
234 intptr_t capacity_; 315 intptr_t capacity_;
235 uintptr_t cursor_; 316 uintptr_t cursor_;
236 317
237 DISALLOW_COPY_AND_ASSIGN(SampleBuffer); 318 DISALLOW_COPY_AND_ASSIGN(SampleBuffer);
238 }; 319 };
239 320
240 321
241 } // namespace dart 322 } // namespace dart
242 323
243 #endif // VM_PROFILER_H_ 324 #endif // VM_PROFILER_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/profiler.cc » ('j') | runtime/vm/profiler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698