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

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

Issue 1960483002: Include thread CPU time in Timeline (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« runtime/vm/os_macos.cc ('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/atomic.h" 7 #include "vm/atomic.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/json_stream.h" 9 #include "vm/json_stream.h"
10 #include "vm/lockers.h" 10 #include "vm/lockers.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 301
302 #define TIMELINE_STREAM_DEFINE(name, enabled_by_default) \ 302 #define TIMELINE_STREAM_DEFINE(name, enabled_by_default) \
303 bool Timeline::stream_##name##_enabled_ = enabled_by_default; \ 303 bool Timeline::stream_##name##_enabled_ = enabled_by_default; \
304 TimelineStream Timeline::stream_##name##_; 304 TimelineStream Timeline::stream_##name##_;
305 TIMELINE_STREAM_LIST(TIMELINE_STREAM_DEFINE) 305 TIMELINE_STREAM_LIST(TIMELINE_STREAM_DEFINE)
306 #undef TIMELINE_STREAM_DEFINE 306 #undef TIMELINE_STREAM_DEFINE
307 307
308 TimelineEvent::TimelineEvent() 308 TimelineEvent::TimelineEvent()
309 : timestamp0_(0), 309 : timestamp0_(0),
310 timestamp1_(0), 310 timestamp1_(0),
311 thread_timestamp0_(-1),
312 thread_timestamp1_(-1),
311 arguments_(NULL), 313 arguments_(NULL),
312 arguments_length_(0), 314 arguments_length_(0),
313 state_(0), 315 state_(0),
314 label_(NULL), 316 label_(NULL),
315 category_(""), 317 category_(""),
316 thread_(OSThread::kInvalidThreadId), 318 thread_(OSThread::kInvalidThreadId),
317 isolate_id_(ILLEGAL_PORT) { 319 isolate_id_(ILLEGAL_PORT) {
318 } 320 }
319 321
320 322
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 int64_t async_id, 365 int64_t async_id,
364 int64_t micros) { 366 int64_t micros) {
365 Init(kAsyncEnd, label); 367 Init(kAsyncEnd, label);
366 set_timestamp0(micros); 368 set_timestamp0(micros);
367 // Overload timestamp1_ with the async_id. 369 // Overload timestamp1_ with the async_id.
368 set_timestamp1(async_id); 370 set_timestamp1(async_id);
369 } 371 }
370 372
371 373
372 void TimelineEvent::DurationBegin(const char* label, 374 void TimelineEvent::DurationBegin(const char* label,
373 int64_t micros) { 375 int64_t micros,
376 int64_t thread_micros) {
374 Init(kDuration, label); 377 Init(kDuration, label);
375 set_timestamp0(micros); 378 set_timestamp0(micros);
379 set_thread_timestamp0(thread_micros);
376 } 380 }
377 381
378 382
379 void TimelineEvent::DurationEnd(int64_t micros) { 383 void TimelineEvent::DurationEnd(int64_t micros,
384 int64_t thread_micros) {
380 ASSERT(timestamp1_ == 0); 385 ASSERT(timestamp1_ == 0);
381 set_timestamp1(micros); 386 set_timestamp1(micros);
387 set_thread_timestamp1(thread_micros);
382 } 388 }
383 389
384 390
385 void TimelineEvent::Instant(const char* label, 391 void TimelineEvent::Instant(const char* label,
386 int64_t micros) { 392 int64_t micros) {
387 Init(kInstant, label); 393 Init(kInstant, label);
388 set_timestamp0(micros); 394 set_timestamp0(micros);
389 } 395 }
390 396
391 397
392 void TimelineEvent::Duration(const char* label, 398 void TimelineEvent::Duration(const char* label,
393 int64_t start_micros, 399 int64_t start_micros,
394 int64_t end_micros) { 400 int64_t end_micros,
401 int64_t thread_start_micros,
402 int64_t thread_end_micros) {
395 Init(kDuration, label); 403 Init(kDuration, label);
396 set_timestamp0(start_micros); 404 set_timestamp0(start_micros);
397 set_timestamp1(end_micros); 405 set_timestamp1(end_micros);
406 set_thread_timestamp0(thread_start_micros);
407 set_thread_timestamp1(thread_end_micros);
398 } 408 }
399 409
400 410
401 void TimelineEvent::Begin(const char* label, 411 void TimelineEvent::Begin(const char* label,
402 int64_t micros) { 412 int64_t micros,
413 int64_t thread_micros) {
403 Init(kBegin, label); 414 Init(kBegin, label);
404 set_timestamp0(micros); 415 set_timestamp0(micros);
416 set_thread_timestamp0(thread_micros);
405 } 417 }
406 418
407 419
408 void TimelineEvent::End(const char* label, 420 void TimelineEvent::End(const char* label,
409 int64_t micros) { 421 int64_t micros,
422 int64_t thread_micros) {
410 Init(kEnd, label); 423 Init(kEnd, label);
411 set_timestamp0(micros); 424 set_timestamp0(micros);
425 set_thread_timestamp0(thread_micros);
412 } 426 }
413 427
414 428
415 void TimelineEvent::Counter(const char* label, int64_t micros) { 429 void TimelineEvent::Counter(const char* label, int64_t micros) {
416 Init(kCounter, label); 430 Init(kCounter, label);
417 set_timestamp0(micros); 431 set_timestamp0(micros);
418 } 432 }
419 433
420 434
421 void TimelineEvent::Metadata(const char* label, int64_t micros) { 435 void TimelineEvent::Metadata(const char* label, int64_t micros) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 } 529 }
516 } 530 }
517 531
518 532
519 void TimelineEvent::Init(EventType event_type, 533 void TimelineEvent::Init(EventType event_type,
520 const char* label) { 534 const char* label) {
521 ASSERT(label != NULL); 535 ASSERT(label != NULL);
522 state_ = 0; 536 state_ = 0;
523 timestamp0_ = 0; 537 timestamp0_ = 0;
524 timestamp1_ = 0; 538 timestamp1_ = 0;
539 thread_timestamp0_ = -1;
540 thread_timestamp1_ = -1;
525 OSThread* os_thread = OSThread::Current(); 541 OSThread* os_thread = OSThread::Current();
526 ASSERT(os_thread != NULL); 542 ASSERT(os_thread != NULL);
527 thread_ = os_thread->trace_id(); 543 thread_ = os_thread->trace_id();
528 Isolate* isolate = Isolate::Current(); 544 Isolate* isolate = Isolate::Current();
529 if (isolate != NULL) { 545 if (isolate != NULL) {
530 isolate_id_ = isolate->main_port(); 546 isolate_id_ = isolate->main_port();
531 } else { 547 } else {
532 isolate_id_ = ILLEGAL_PORT; 548 isolate_id_ = ILLEGAL_PORT;
533 } 549 }
534 label_ = label; 550 label_ = label;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 return; 597 return;
582 } 598 }
583 JSONObject obj(stream); 599 JSONObject obj(stream);
584 int64_t pid = OS::ProcessId(); 600 int64_t pid = OS::ProcessId();
585 int64_t tid = OSThread::ThreadIdToIntPtr(thread_); 601 int64_t tid = OSThread::ThreadIdToIntPtr(thread_);
586 obj.AddProperty("name", label_); 602 obj.AddProperty("name", label_);
587 obj.AddProperty("cat", category_); 603 obj.AddProperty("cat", category_);
588 obj.AddProperty64("tid", tid); 604 obj.AddProperty64("tid", tid);
589 obj.AddProperty64("pid", pid); 605 obj.AddProperty64("pid", pid);
590 obj.AddPropertyTimeMicros("ts", TimeOrigin()); 606 obj.AddPropertyTimeMicros("ts", TimeOrigin());
591 607 if (HasThreadCPUTime()) {
608 obj.AddPropertyTimeMicros("tts", ThreadCPUTimeOrigin());
609 }
592 switch (event_type()) { 610 switch (event_type()) {
593 case kBegin: { 611 case kBegin: {
594 obj.AddProperty("ph", "B"); 612 obj.AddProperty("ph", "B");
595 } 613 }
596 break; 614 break;
597 case kEnd: { 615 case kEnd: {
598 obj.AddProperty("ph", "E"); 616 obj.AddProperty("ph", "E");
599 } 617 }
600 break; 618 break;
601 case kDuration: { 619 case kDuration: {
602 obj.AddProperty("ph", "X"); 620 obj.AddProperty("ph", "X");
603 obj.AddPropertyTimeMicros("dur", TimeDuration()); 621 obj.AddPropertyTimeMicros("dur", TimeDuration());
622 if (HasThreadCPUTime()) {
623 obj.AddPropertyTimeMicros("tdur", ThreadCPUTimeDuration());
624 }
604 } 625 }
605 break; 626 break;
606 case kInstant: { 627 case kInstant: {
607 obj.AddProperty("ph", "i"); 628 obj.AddProperty("ph", "i");
608 obj.AddProperty("s", "p"); 629 obj.AddProperty("s", "p");
609 } 630 }
610 break; 631 break;
611 case kAsyncBegin: { 632 case kAsyncBegin: {
612 obj.AddProperty("ph", "b"); 633 obj.AddProperty("ph", "b");
613 obj.AddPropertyF("id", "%" Px64 "", AsyncId()); 634 obj.AddPropertyF("id", "%" Px64 "", AsyncId());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 682
662 int64_t TimelineEvent::TimeDuration() const { 683 int64_t TimelineEvent::TimeDuration() const {
663 if (timestamp1_ == 0) { 684 if (timestamp1_ == 0) {
664 // This duration is still open, use current time as end. 685 // This duration is still open, use current time as end.
665 return OS::GetCurrentMonotonicMicros() - timestamp0_; 686 return OS::GetCurrentMonotonicMicros() - timestamp0_;
666 } 687 }
667 return timestamp1_ - timestamp0_; 688 return timestamp1_ - timestamp0_;
668 } 689 }
669 690
670 691
692 bool TimelineEvent::HasThreadCPUTime() const {
693 return (thread_timestamp0_ != -1);
694 }
695
696
697
698 int64_t TimelineEvent::ThreadCPUTimeOrigin() const {
699 ASSERT(HasThreadCPUTime());
700 return thread_timestamp0_;
701 }
702
703
704 int64_t TimelineEvent::ThreadCPUTimeDuration() const {
705 ASSERT(HasThreadCPUTime());
706 if (thread_timestamp1_ == -1) {
707 // This duration is still open, use current time as end.
708 return OS::GetCurrentThreadCPUMicros() - thread_timestamp0_;
709 }
710 return thread_timestamp1_ - thread_timestamp0_;
711 }
712
713
671 TimelineStream::TimelineStream() 714 TimelineStream::TimelineStream()
672 : name_(NULL), 715 : name_(NULL),
673 enabled_(false), 716 enabled_(false),
674 globally_enabled_(NULL) { 717 globally_enabled_(NULL) {
675 } 718 }
676 719
677 720
678 void TimelineStream::Init(const char* name, 721 void TimelineStream::Init(const char* name,
679 bool enabled, 722 bool enabled,
680 const bool* globally_enabled) { 723 const bool* globally_enabled) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 } 867 }
825 868
826 869
827 TimelineDurationScope::TimelineDurationScope(TimelineStream* stream, 870 TimelineDurationScope::TimelineDurationScope(TimelineStream* stream,
828 const char* label) 871 const char* label)
829 : TimelineEventScope(stream, label) { 872 : TimelineEventScope(stream, label) {
830 if (!FLAG_support_timeline) { 873 if (!FLAG_support_timeline) {
831 return; 874 return;
832 } 875 }
833 timestamp_ = OS::GetCurrentMonotonicMicros(); 876 timestamp_ = OS::GetCurrentMonotonicMicros();
877 thread_timestamp_ = OS::GetCurrentThreadCPUMicros();
834 } 878 }
835 879
836 880
837 TimelineDurationScope::TimelineDurationScope(Thread* thread, 881 TimelineDurationScope::TimelineDurationScope(Thread* thread,
838 TimelineStream* stream, 882 TimelineStream* stream,
839 const char* label) 883 const char* label)
840 : TimelineEventScope(thread, stream, label) { 884 : TimelineEventScope(thread, stream, label) {
841 if (!FLAG_support_timeline) { 885 if (!FLAG_support_timeline) {
842 return; 886 return;
843 } 887 }
844 timestamp_ = OS::GetCurrentMonotonicMicros(); 888 timestamp_ = OS::GetCurrentMonotonicMicros();
889 thread_timestamp_ = OS::GetCurrentThreadCPUMicros();
845 } 890 }
846 891
847 892
848 TimelineDurationScope::~TimelineDurationScope() { 893 TimelineDurationScope::~TimelineDurationScope() {
849 if (!FLAG_support_timeline) { 894 if (!FLAG_support_timeline) {
850 return; 895 return;
851 } 896 }
852 if (!ShouldEmitEvent()) { 897 if (!ShouldEmitEvent()) {
853 return; 898 return;
854 } 899 }
855 TimelineEvent* event = stream()->StartEvent(); 900 TimelineEvent* event = stream()->StartEvent();
856 if (event == NULL) { 901 if (event == NULL) {
857 // Stream is now disabled. 902 // Stream is now disabled.
858 return; 903 return;
859 } 904 }
860 ASSERT(event != NULL); 905 ASSERT(event != NULL);
861 // Emit a duration event. 906 // Emit a duration event.
862 event->Duration(label(), timestamp_, OS::GetCurrentMonotonicMicros()); 907 event->Duration(label(),
908 timestamp_,
909 OS::GetCurrentMonotonicMicros(),
910 thread_timestamp_,
911 OS::GetCurrentThreadCPUMicros());
863 StealArguments(event); 912 StealArguments(event);
864 event->Complete(); 913 event->Complete();
865 } 914 }
866 915
867 916
868 TimelineBeginEndScope::TimelineBeginEndScope(TimelineStream* stream, 917 TimelineBeginEndScope::TimelineBeginEndScope(TimelineStream* stream,
869 const char* label) 918 const char* label)
870 : TimelineEventScope(stream, label) { 919 : TimelineEventScope(stream, label) {
871 if (!FLAG_support_timeline) { 920 if (!FLAG_support_timeline) {
872 return; 921 return;
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 TimelineEventBlock* TimelineEventBlockIterator::Next() { 1636 TimelineEventBlock* TimelineEventBlockIterator::Next() {
1588 ASSERT(current_ != NULL); 1637 ASSERT(current_ != NULL);
1589 TimelineEventBlock* r = current_; 1638 TimelineEventBlock* r = current_;
1590 current_ = current_->next(); 1639 current_ = current_->next();
1591 return r; 1640 return r;
1592 } 1641 }
1593 1642
1594 #endif // !PRODUCT 1643 #endif // !PRODUCT
1595 1644
1596 } // namespace dart 1645 } // namespace dart
OLDNEW
« runtime/vm/os_macos.cc ('K') | « runtime/vm/timeline.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698