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

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
« no previous file with comments | « 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, "Trace timeline code.");
17 DEFINE_FLAG(bool, complete_timeline, false, "Record the complete timeline");
16 18
17 TimelineEvent::TimelineEvent() 19 TimelineEvent::TimelineEvent()
18 : timestamp0_(0), 20 : timestamp0_(0),
19 timestamp1_(0), 21 timestamp1_(0),
20 arguments_(NULL), 22 arguments_(NULL),
21 arguments_length_(0), 23 arguments_length_(0),
22 state_(0), 24 state_(0),
23 label_(NULL), 25 label_(NULL),
24 stream_(NULL), 26 stream_(NULL),
25 thread_(NULL) { 27 thread_(NULL) {
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 424
423 void TimelineEventRingRecorder::PrintJSONEvents(JSONArray* events) const { 425 void TimelineEventRingRecorder::PrintJSONEvents(JSONArray* events) const {
424 for (intptr_t i = 0; i < capacity_; i++) { 426 for (intptr_t i = 0; i < capacity_; i++) {
425 if (events_[i].IsValid()) { 427 if (events_[i].IsValid()) {
426 events->AddValue(&events_[i]); 428 events->AddValue(&events_[i]);
427 } 429 }
428 } 430 }
429 } 431 }
430 432
431 433
432 void TimelineEventRingRecorder::PrintJSON(JSONStream* js) const { 434 void TimelineEventRingRecorder::PrintJSON(JSONStream* js) {
433 JSONObject topLevel(js); 435 JSONObject topLevel(js);
434 topLevel.AddProperty("type", "_Timeline"); 436 topLevel.AddProperty("type", "_Timeline");
435 { 437 {
436 JSONArray events(&topLevel, "traceEvents"); 438 JSONArray events(&topLevel, "traceEvents");
437 PrintJSONMeta(&events); 439 PrintJSONMeta(&events);
438 PrintJSONEvents(&events); 440 PrintJSONEvents(&events);
439 } 441 }
440 } 442 }
441 443
442 444
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 476
475 477
476 TimelineEventStreamingRecorder::TimelineEventStreamingRecorder() { 478 TimelineEventStreamingRecorder::TimelineEventStreamingRecorder() {
477 } 479 }
478 480
479 481
480 TimelineEventStreamingRecorder::~TimelineEventStreamingRecorder() { 482 TimelineEventStreamingRecorder::~TimelineEventStreamingRecorder() {
481 } 483 }
482 484
483 485
484 void TimelineEventStreamingRecorder::PrintJSON(JSONStream* js) const { 486 void TimelineEventStreamingRecorder::PrintJSON(JSONStream* js) {
485 JSONObject topLevel(js); 487 JSONObject topLevel(js);
486 topLevel.AddProperty("type", "_Timeline"); 488 topLevel.AddProperty("type", "_Timeline");
487 { 489 {
488 JSONArray events(&topLevel, "traceEvents"); 490 JSONArray events(&topLevel, "traceEvents");
489 PrintJSONMeta(&events); 491 PrintJSONMeta(&events);
490 } 492 }
491 } 493 }
492 494
493 void TimelineEventStreamingRecorder::VisitObjectPointers( 495 void TimelineEventStreamingRecorder::VisitObjectPointers(
494 ObjectPointerVisitor* visitor) { 496 ObjectPointerVisitor* visitor) {
(...skipping 12 matching lines...) Expand all
507 TimelineEvent* event = new TimelineEvent(); 509 TimelineEvent* event = new TimelineEvent();
508 return event; 510 return event;
509 } 511 }
510 512
511 513
512 void TimelineEventStreamingRecorder::CompleteEvent(TimelineEvent* event) { 514 void TimelineEventStreamingRecorder::CompleteEvent(TimelineEvent* event) {
513 StreamEvent(event); 515 StreamEvent(event);
514 delete event; 516 delete event;
515 } 517 }
516 518
519
520 TimelineEventEndlessRecorder::TimelineEventEndlessRecorder()
521 : head_(NULL) {
522 GetNewBlock();
523 }
524
525
526 void TimelineEventEndlessRecorder::PrintJSON(JSONStream* js) {
527 MutexLocker ml(&lock_);
528 JSONObject topLevel(js);
529 topLevel.AddProperty("type", "_Timeline");
530 {
531 JSONArray events(&topLevel, "traceEvents");
532 PrintJSONMeta(&events);
533 PrintJSONEvents(&events);
534 }
535 }
536
537
538 TimelineEventBlock* TimelineEventEndlessRecorder::GetNewBlock() {
539 MutexLocker ml(&lock_);
540 return GetNewBlockLocked();
541 }
542
543
544 void TimelineEventEndlessRecorder::VisitObjectPointers(
545 ObjectPointerVisitor* visitor) {
546 // no-op.
547 }
548
549
550 TimelineEvent* TimelineEventEndlessRecorder::StartEvent(const Object& object) {
551 return StartEvent();
552 }
553
554
555 TimelineEvent* TimelineEventEndlessRecorder::StartEvent() {
556 // Grab the thread's timeline event block.
557 Thread* thread = Thread::Current();
558 TimelineEventBlock* thread_block = thread->timeline_block();
559 if (thread_block == NULL) {
560 return NULL;
561 }
562 ASSERT(thread_block != NULL);
563 if (thread_block->IsFull()) {
564 // If it is full, request a new block.
565 thread_block = GetNewBlock();
566 thread->set_timeline_block(thread_block);
567 }
568 ASSERT(!thread_block->IsFull());
569 return thread_block->StartEvent();
570 }
571
572
573 void TimelineEventEndlessRecorder::CompleteEvent(TimelineEvent* event) {
574 // no-op.
575 }
576
577
578 TimelineEventBlock* TimelineEventEndlessRecorder::GetNewBlockLocked() {
579 TimelineEventBlock* block = new TimelineEventBlock();
580 block->set_next(head_);
581 head_ = block;
582 return head_;
583 }
584
585
586 void TimelineEventEndlessRecorder::PrintJSONEvents(JSONArray* events) const {
587 TimelineEventBlock* current = head_;
588 while (current != NULL) {
589 intptr_t length = current->length();
590 for (intptr_t i = 0; i < length; i++) {
591 TimelineEvent* event = current->At(i);
592 if (!event->IsValid()) {
593 continue;
594 }
595 events->AddValue(event);
596 }
597 current = current->next();
598 }
599 }
600
601
602 TimelineEventBlock::TimelineEventBlock()
603 : next_(NULL),
604 length_(0) {
605 }
606
607
608 TimelineEvent* TimelineEventBlock::StartEvent() {
609 ASSERT(!IsFull());
610 return &events_[length_++];
611 }
612
517 } // namespace dart 613 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/timeline.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698