| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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_TIMELINE_H_ | 5 #ifndef VM_TIMELINE_H_ |
| 6 #define VM_TIMELINE_H_ | 6 #define VM_TIMELINE_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" |
| 8 #include "vm/bitfield.h" | 9 #include "vm/bitfield.h" |
| 9 | 10 |
| 10 namespace dart { | 11 namespace dart { |
| 11 | 12 |
| 13 class JSONArray; |
| 14 class JSONObject; |
| 12 class JSONStream; | 15 class JSONStream; |
| 13 class Object; | 16 class Object; |
| 17 class ObjectPointerVisitor; |
| 14 class RawArray; | 18 class RawArray; |
| 15 class Thread; | 19 class Thread; |
| 16 class TimelineEvent; | 20 class TimelineEvent; |
| 17 class TimelineEventBlock; | 21 class TimelineEventBlock; |
| 18 class TimelineEventRecorder; | 22 class TimelineEventRecorder; |
| 19 class TimelineStream; | 23 class TimelineStream; |
| 20 | 24 |
| 21 // You should get a |TimelineEvent| from a |TimelineStream|. | 25 // You should get a |TimelineEvent| from a |TimelineStream|. |
| 22 class TimelineEvent { | 26 class TimelineEvent { |
| 23 public: | 27 public: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 EventType event_type() const { | 80 EventType event_type() const { |
| 77 return EventTypeField::decode(state_); | 81 return EventTypeField::decode(state_); |
| 78 } | 82 } |
| 79 | 83 |
| 80 int64_t TimeOrigin() const; | 84 int64_t TimeOrigin() const; |
| 81 int64_t AsyncId() const; | 85 int64_t AsyncId() const; |
| 82 int64_t TimeDuration() const; | 86 int64_t TimeDuration() const; |
| 83 | 87 |
| 84 void PrintJSON(JSONStream* stream) const; | 88 void PrintJSON(JSONStream* stream) const; |
| 85 | 89 |
| 90 ThreadId thread() const { |
| 91 return thread_; |
| 92 } |
| 93 |
| 86 private: | 94 private: |
| 87 struct TimelineEventArgument { | 95 struct TimelineEventArgument { |
| 88 const char* name; | 96 const char* name; |
| 89 char* value; | 97 char* value; |
| 90 }; | 98 }; |
| 91 | 99 |
| 92 int64_t timestamp0_; | 100 int64_t timestamp0_; |
| 93 int64_t timestamp1_; | 101 int64_t timestamp1_; |
| 94 TimelineEventArgument* arguments_; | 102 TimelineEventArgument* arguments_; |
| 95 intptr_t arguments_length_; | 103 intptr_t arguments_length_; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 return next_; | 277 return next_; |
| 270 } | 278 } |
| 271 void set_next(TimelineEventBlock* next) { | 279 void set_next(TimelineEventBlock* next) { |
| 272 next_ = next; | 280 next_ = next; |
| 273 } | 281 } |
| 274 | 282 |
| 275 intptr_t length() const { | 283 intptr_t length() const { |
| 276 return length_; | 284 return length_; |
| 277 } | 285 } |
| 278 | 286 |
| 287 bool IsEmpty() const { |
| 288 return length_ == 0; |
| 289 } |
| 290 |
| 279 bool IsFull() const { | 291 bool IsFull() const { |
| 280 return length_ == kBlockSize; | 292 return length_ == kBlockSize; |
| 281 } | 293 } |
| 282 | 294 |
| 283 TimelineEvent* At(intptr_t index) { | 295 TimelineEvent* At(intptr_t index) { |
| 284 ASSERT(index >= 0); | 296 ASSERT(index >= 0); |
| 285 ASSERT(index < kBlockSize); | 297 ASSERT(index < kBlockSize); |
| 286 return &events_[index]; | 298 return &events_[index]; |
| 287 } | 299 } |
| 288 | 300 |
| 301 // Attempt to sniff a thread id from the first event. |
| 302 ThreadId thread() const; |
| 303 // Attempt to sniff the timestamp from the first event. |
| 304 int64_t LowerTimeBound() const; |
| 305 |
| 306 // Returns false if |this| violates any of the following invariants: |
| 307 // - events in the block come from one thread. |
| 308 // - events have monotonically increasing timestamps. |
| 309 bool CheckBlock(); |
| 310 |
| 289 protected: | 311 protected: |
| 290 TimelineEvent* StartEvent(); | 312 TimelineEvent* StartEvent(); |
| 291 | 313 |
| 292 TimelineEvent events_[kBlockSize]; | 314 TimelineEvent events_[kBlockSize]; |
| 293 TimelineEventBlock* next_; | 315 TimelineEventBlock* next_; |
| 294 intptr_t length_; | 316 intptr_t length_; |
| 295 | 317 |
| 296 friend class TimelineEventEndlessRecorder; | 318 friend class TimelineEventEndlessRecorder; |
| 319 friend class TimelineTestHelper; |
| 297 | 320 |
| 298 private: | 321 private: |
| 299 DISALLOW_COPY_AND_ASSIGN(TimelineEventBlock); | 322 DISALLOW_COPY_AND_ASSIGN(TimelineEventBlock); |
| 300 }; | 323 }; |
| 301 | 324 |
| 302 | 325 |
| 303 // Recorder of |TimelineEvent|s. | 326 // Recorder of |TimelineEvent|s. |
| 304 class TimelineEventRecorder { | 327 class TimelineEventRecorder { |
| 305 public: | 328 public: |
| 306 TimelineEventRecorder(); | 329 TimelineEventRecorder(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 329 friend class TimelineStream; | 352 friend class TimelineStream; |
| 330 friend class Isolate; | 353 friend class Isolate; |
| 331 | 354 |
| 332 private: | 355 private: |
| 333 DISALLOW_COPY_AND_ASSIGN(TimelineEventRecorder); | 356 DISALLOW_COPY_AND_ASSIGN(TimelineEventRecorder); |
| 334 }; | 357 }; |
| 335 | 358 |
| 336 | 359 |
| 337 // A recorder that stores events in a ring buffer of fixed capacity. | 360 // A recorder that stores events in a ring buffer of fixed capacity. |
| 338 // This recorder does track Dart objects. | 361 // This recorder does track Dart objects. |
| 362 // TODO(johnmccutchan): Make this recorder use event blocks too. |
| 339 class TimelineEventRingRecorder : public TimelineEventRecorder { | 363 class TimelineEventRingRecorder : public TimelineEventRecorder { |
| 340 public: | 364 public: |
| 341 static const intptr_t kDefaultCapacity = 8192; | 365 static const intptr_t kDefaultCapacity = 8192; |
| 342 | 366 |
| 343 static intptr_t SizeForCapacity(intptr_t capacity); | 367 static intptr_t SizeForCapacity(intptr_t capacity); |
| 344 | 368 |
| 345 explicit TimelineEventRingRecorder(intptr_t capacity = kDefaultCapacity); | 369 explicit TimelineEventRingRecorder(intptr_t capacity = kDefaultCapacity); |
| 346 ~TimelineEventRingRecorder(); | 370 ~TimelineEventRingRecorder(); |
| 347 | 371 |
| 348 void PrintJSON(JSONStream* js); | 372 void PrintJSON(JSONStream* js); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 434 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
| 411 TimelineEvent* StartEvent(const Object& object); | 435 TimelineEvent* StartEvent(const Object& object); |
| 412 TimelineEvent* StartEvent(); | 436 TimelineEvent* StartEvent(); |
| 413 void CompleteEvent(TimelineEvent* event); | 437 void CompleteEvent(TimelineEvent* event); |
| 414 | 438 |
| 415 TimelineEventBlock* GetNewBlockLocked(); | 439 TimelineEventBlock* GetNewBlockLocked(); |
| 416 void PrintJSONEvents(JSONArray* array) const; | 440 void PrintJSONEvents(JSONArray* array) const; |
| 417 | 441 |
| 418 Mutex lock_; | 442 Mutex lock_; |
| 419 TimelineEventBlock* head_; | 443 TimelineEventBlock* head_; |
| 444 |
| 445 friend class TimelineEventBlockIterator; |
| 446 }; |
| 447 |
| 448 |
| 449 // An iterator for blocks. |
| 450 class TimelineEventBlockIterator { |
| 451 public: |
| 452 explicit TimelineEventBlockIterator(TimelineEventEndlessRecorder* recorder); |
| 453 ~TimelineEventBlockIterator(); |
| 454 |
| 455 void Reset(); |
| 456 bool Next(); |
| 457 |
| 458 TimelineEventBlock* current() const { |
| 459 return current_; |
| 460 } |
| 461 |
| 462 private: |
| 463 TimelineEventBlock* current_; |
| 464 TimelineEventEndlessRecorder* recorder_; |
| 420 }; | 465 }; |
| 421 | 466 |
| 422 } // namespace dart | 467 } // namespace dart |
| 423 | 468 |
| 424 #endif // VM_TIMELINE_H_ | 469 #endif // VM_TIMELINE_H_ |
| OLD | NEW |