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

Side by Side Diff: runtime/vm/timeline.cc

Issue 1275113003: Endless thread safe timeline recorder (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
« runtime/vm/timeline.h ('K') | « runtime/vm/timeline.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <cstdlib> 5 #include <cstdlib>
6 6
7 #include "vm/isolate.h" 7 #include "vm/isolate.h"
8 #include "vm/json_stream.h" 8 #include "vm/json_stream.h"
9 #include "vm/lockers.h"
9 #include "vm/object.h" 10 #include "vm/object.h"
10 #include "vm/thread.h" 11 #include "vm/thread.h"
11 #include "vm/timeline.h" 12 #include "vm/timeline.h"
12 13
13 namespace dart { 14 namespace dart {
14 15
15 DEFINE_FLAG(bool, trace_timeline, false, "Timeline trace"); 16 DEFINE_FLAG(bool, trace_timeline, false, "Timeline trace");
17 // TODO(johnmccutchan): Flip this to false before committing.
18 DEFINE_FLAG(bool, complete_timeline, true, "Record the complete timeline");
16 19
17 TimelineEvent::TimelineEvent() 20 TimelineEvent::TimelineEvent()
18 : timestamp0_(0), 21 : timestamp0_(0),
19 timestamp1_(0), 22 timestamp1_(0),
20 arguments_(NULL), 23 arguments_(NULL),
21 arguments_length_(0), 24 arguments_length_(0),
22 state_(0), 25 state_(0),
23 label_(NULL), 26 label_(NULL),
24 stream_(NULL), 27 stream_(NULL),
25 thread_(NULL) { 28 thread_(NULL) {
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 425
423 void TimelineEventRingRecorder::PrintJSONEvents(JSONArray* events) const { 426 void TimelineEventRingRecorder::PrintJSONEvents(JSONArray* events) const {
424 for (intptr_t i = 0; i < capacity_; i++) { 427 for (intptr_t i = 0; i < capacity_; i++) {
425 if (events_[i].IsValid()) { 428 if (events_[i].IsValid()) {
426 events->AddValue(&events_[i]); 429 events->AddValue(&events_[i]);
427 } 430 }
428 } 431 }
429 } 432 }
430 433
431 434
432 void TimelineEventRingRecorder::PrintJSON(JSONStream* js) const { 435 void TimelineEventRingRecorder::PrintJSON(JSONStream* js) {
433 JSONObject topLevel(js); 436 JSONObject topLevel(js);
434 topLevel.AddProperty("type", "_Timeline"); 437 topLevel.AddProperty("type", "_Timeline");
435 { 438 {
436 JSONArray events(&topLevel, "traceEvents"); 439 JSONArray events(&topLevel, "traceEvents");
437 PrintJSONMeta(&events); 440 PrintJSONMeta(&events);
438 PrintJSONEvents(&events); 441 PrintJSONEvents(&events);
439 } 442 }
440 } 443 }
441 444
442 445
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 477
475 478
476 TimelineEventStreamingRecorder::TimelineEventStreamingRecorder() { 479 TimelineEventStreamingRecorder::TimelineEventStreamingRecorder() {
477 } 480 }
478 481
479 482
480 TimelineEventStreamingRecorder::~TimelineEventStreamingRecorder() { 483 TimelineEventStreamingRecorder::~TimelineEventStreamingRecorder() {
481 } 484 }
482 485
483 486
484 void TimelineEventStreamingRecorder::PrintJSON(JSONStream* js) const { 487 void TimelineEventStreamingRecorder::PrintJSON(JSONStream* js) {
485 JSONObject topLevel(js); 488 JSONObject topLevel(js);
486 topLevel.AddProperty("type", "_Timeline"); 489 topLevel.AddProperty("type", "_Timeline");
487 { 490 {
488 JSONArray events(&topLevel, "traceEvents"); 491 JSONArray events(&topLevel, "traceEvents");
489 PrintJSONMeta(&events); 492 PrintJSONMeta(&events);
490 } 493 }
491 } 494 }
492 495
493 void TimelineEventStreamingRecorder::VisitObjectPointers( 496 void TimelineEventStreamingRecorder::VisitObjectPointers(
494 ObjectPointerVisitor* visitor) { 497 ObjectPointerVisitor* visitor) {
(...skipping 12 matching lines...) Expand all
507 TimelineEvent* event = new TimelineEvent(); 510 TimelineEvent* event = new TimelineEvent();
508 return event; 511 return event;
509 } 512 }
510 513
511 514
512 void TimelineEventStreamingRecorder::CompleteEvent(TimelineEvent* event) { 515 void TimelineEventStreamingRecorder::CompleteEvent(TimelineEvent* event) {
513 StreamEvent(event); 516 StreamEvent(event);
514 delete event; 517 delete event;
515 } 518 }
516 519
520
521 TimelineEventEndlessRecorder::TimelineEventEndlessRecorder()
522 : head_(NULL) {
523 GetNewBlock();
524 }
525
526
527 void TimelineEventEndlessRecorder::PrintJSON(JSONStream* js) {
528 MutexLocker ml(&lock_);
529 JSONObject topLevel(js);
530 topLevel.AddProperty("type", "_Timeline");
531 {
532 JSONArray events(&topLevel, "traceEvents");
533 PrintJSONMeta(&events);
534 PrintJSONEvents(&events);
535 }
536 }
537
538
539 TimelineEventBlock* TimelineEventEndlessRecorder::GetNewBlock() {
540 MutexLocker ml(&lock_);
541 return GetNewBlockLocked();
542 }
543
544
545 void TimelineEventEndlessRecorder::VisitObjectPointers(
546 ObjectPointerVisitor* visitor) {
547 // no-op.
548 }
549
550
551 TimelineEvent* TimelineEventEndlessRecorder::StartEvent(const Object& object) {
552 return StartEvent();
553 }
554
555
556 TimelineEvent* TimelineEventEndlessRecorder::StartEvent() {
557 // Grab the thread's timeline event block.
558 Thread* thread = Thread::Current();
559 TimelineEventBlock* thread_block = thread->current_block();
560 if (thread_block == NULL) {
561 return NULL;
562 }
563 ASSERT(thread_block != NULL);
564 if (thread_block->IsFull()) {
565 // If it is full, request a new block.
566 thread_block = GetNewBlock();
567 thread->set_current_block(thread_block);
568 }
569 ASSERT(!thread_block->IsFull());
570 return thread_block->StartEvent();
571 }
572
573
574 void TimelineEventEndlessRecorder::CompleteEvent(TimelineEvent* event) {
575 // no-op.
576 }
577
578
579 TimelineEventBlock* TimelineEventEndlessRecorder::GetNewBlockLocked() {
580 TimelineEventBlock* block = new TimelineEventBlock();
581 block->set_next(head_);
582 head_ = block;
583 return head_;
584 }
585
586
587 void TimelineEventEndlessRecorder::PrintJSONEvents(JSONArray* events) const {
koda 2015/08/07 01:09:54 Since you don't lock here and in StartEvent, how d
Cutch 2015/08/07 16:47:42 Acknowledged.
588 TimelineEventBlock* current = head_;
589 while (current != NULL) {
590 intptr_t length = current->length();
591 for (intptr_t i = 0; i < length; i++) {
592 TimelineEvent* event = current->At(i);
593 if (!event->IsValid()) {
594 continue;
595 }
596 events->AddValue(event);
597 }
598 current = current->next();
599 }
600 }
601
602
603 TimelineEventBlock::TimelineEventBlock()
604 : next_(NULL),
605 length_(0) {
606 }
607
608
609 TimelineEvent* TimelineEventBlock::StartEvent() {
610 ASSERT(!IsFull());
611 return &events_[length_++];
612 }
613
517 } // namespace dart 614 } // namespace dart
OLDNEW
« runtime/vm/timeline.h ('K') | « runtime/vm/timeline.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698