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

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

Issue 2977513002: [Fuchsia] Routes timeline events to Fuchsia's tracing app (Closed)
Patch Set: Address comments Created 3 years, 5 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 "platform/globals.h"
5 #ifndef PRODUCT 6 #ifndef PRODUCT
6 7
7 #include <errno.h> 8 #include <errno.h>
8 #include <fcntl.h> 9 #include <fcntl.h>
9 #include <cstdlib> 10 #include <cstdlib>
10 11
12 #if defined(HOST_OS_FUCHSIA)
13 #include "apps/tracing/lib/trace/event.h"
14 #endif
15
11 #include "vm/atomic.h" 16 #include "vm/atomic.h"
12 #include "vm/isolate.h" 17 #include "vm/isolate.h"
13 #include "vm/json_stream.h" 18 #include "vm/json_stream.h"
14 #include "vm/lockers.h" 19 #include "vm/lockers.h"
15 #include "vm/log.h" 20 #include "vm/log.h"
16 #include "vm/object.h" 21 #include "vm/object.h"
17 #include "vm/service_event.h" 22 #include "vm/service_event.h"
18 #include "vm/thread.h" 23 #include "vm/thread.h"
19 #include "vm/timeline.h" 24 #include "vm/timeline.h"
20 25
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 const bool use_startup_recorder = FLAG_startup_timeline; 105 const bool use_startup_recorder = FLAG_startup_timeline;
101 const bool use_systrace_recorder = FLAG_systrace_timeline; 106 const bool use_systrace_recorder = FLAG_systrace_timeline;
102 107
103 const char* flag = FLAG_timeline_recorder; 108 const char* flag = FLAG_timeline_recorder;
104 109
105 if (use_systrace_recorder || (flag != NULL)) { 110 if (use_systrace_recorder || (flag != NULL)) {
106 if (use_systrace_recorder || (strcmp("systrace", flag) == 0)) { 111 if (use_systrace_recorder || (strcmp("systrace", flag) == 0)) {
107 if (FLAG_trace_timeline) { 112 if (FLAG_trace_timeline) {
108 THR_Print("Using the Systrace timeline recorder.\n"); 113 THR_Print("Using the Systrace timeline recorder.\n");
109 } 114 }
115 #if defined(HOST_OS_FUCHSIA)
116 return new TimelineEventFuchsiaRecorder();
117 #else
110 return new TimelineEventSystraceRecorder(); 118 return new TimelineEventSystraceRecorder();
119 #endif
111 } 120 }
112 } 121 }
113 122
114 if (use_endless_recorder || (flag != NULL)) { 123 if (use_endless_recorder || (flag != NULL)) {
115 if (use_endless_recorder || (strcmp("endless", flag) == 0)) { 124 if (use_endless_recorder || (strcmp("endless", flag) == 0)) {
116 if (FLAG_trace_timeline) { 125 if (FLAG_trace_timeline) {
117 THR_Print("Using the endless timeline recorder.\n"); 126 THR_Print("Using the endless timeline recorder.\n");
118 } 127 }
119 return new TimelineEventEndlessRecorder(); 128 return new TimelineEventEndlessRecorder();
120 } 129 }
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 518 }
510 519
511 520
512 void TimelineEvent::StealArguments(intptr_t arguments_length, 521 void TimelineEvent::StealArguments(intptr_t arguments_length,
513 TimelineEventArgument* arguments) { 522 TimelineEventArgument* arguments) {
514 arguments_length_ = arguments_length; 523 arguments_length_ = arguments_length;
515 arguments_ = arguments; 524 arguments_ = arguments;
516 } 525 }
517 526
518 527
528 #if defined(HOST_OS_FUCHSIA)
529
530 // TODO(zra): The functions below emit Dart's timeline events all as category
531 // "dart". Instead, we could have finer-grained categories that make use of
532 // the name of the timeline stream, e.g. "VM", "GC", etc.
533
534 #define FUCHSIA_EVENT_ARGS_LIST(V) \
535 V(Begin, TRACE_DURATION_BEGIN) \
536 V(End, TRACE_DURATION_END)
537
538 #define EMIT_FUCHSIA_EVENT(__name, __macro) \
539 static void EmitFuchsia##__name##Event(const char* label, \
540 TimelineEventArgument* arguments, \
541 intptr_t arguments_length) { \
542 if (arguments_length == 0) { \
543 __macro("dart", label); \
544 } else if (arguments_length == 1) { \
545 __macro("dart", label, arguments[0].name, \
546 const_cast<const char*>(arguments[0].value)); \
547 } else { \
548 __macro("dart", label, arguments[0].name, \
549 const_cast<const char*>(arguments[0].value), \
550 arguments[1].name, \
551 const_cast<const char*>(arguments[1].value)); \
552 } \
553 }
554
555 FUCHSIA_EVENT_ARGS_LIST(EMIT_FUCHSIA_EVENT)
556 #undef EMIT_FUCHSIA_EVENT
557
558 #define FUCHSIA_EVENT_ID_ARGS_LIST(V) \
559 V(Instant, TRACE_INSTANT, ::tracing::EventScope) \
560 V(AsyncBegin, TRACE_ASYNC_BEGIN, int64_t) \
561 V(AsyncEnd, TRACE_ASYNC_END, int64_t) \
562 V(AsyncInstant, TRACE_ASYNC_INSTANT, int64_t)
563
564 #define EMIT_FUCHSIA_EVENT(__name, __macro, __id_typ) \
565 static void EmitFuchsia##__name##Event(const char* label, \
566 __id_typ id, \
567 TimelineEventArgument* arguments, \
568 intptr_t arguments_length) { \
569 if (arguments_length == 0) { \
570 __macro("dart", label, id); \
571 } else if (arguments_length == 1) { \
572 __macro("dart", label, id, arguments[0].name, \
573 const_cast<const char*>(arguments[0].value)); \
574 } else { \
575 __macro("dart", label, id, arguments[0].name, \
576 const_cast<const char*>(arguments[0].value), \
577 arguments[1].name, \
578 const_cast<const char*>(arguments[1].value)); \
579 } \
580 }
581
582 FUCHSIA_EVENT_ID_ARGS_LIST(EMIT_FUCHSIA_EVENT)
583 #undef EMIT_FUCHSIA_EVENT
584
585
586 void TimelineEvent::EmitFuchsiaEvent() {
587 switch (event_type()) {
588 case kBegin:
589 EmitFuchsiaBeginEvent(label_, arguments_, arguments_length_);
590 break;
591 case kEnd:
592 EmitFuchsiaEndEvent(label_, arguments_, arguments_length_);
593 break;
594 case kInstant:
595 EmitFuchsiaInstantEvent(
596 label_, TRACE_SCOPE_THREAD, arguments_, arguments_length_);
597 break;
598 case kAsyncBegin:
599 EmitFuchsiaAsyncBeginEvent(
600 label_, AsyncId(), arguments_, arguments_length_);
601 break;
602 case kAsyncEnd:
603 EmitFuchsiaAsyncEndEvent(
604 label_, AsyncId(), arguments_, arguments_length_);
605 break;
606 case kAsyncInstant:
607 EmitFuchsiaAsyncInstantEvent(
608 label_, AsyncId(), arguments_, arguments_length_);
609 break;
610 default:
611 // TODO(zra): Figure out what to do with kDuration, kCounter, and
612 // kMetadata.
613 break;
614 }
615 }
616 #endif
617
618
519 intptr_t TimelineEvent::PrintSystrace(char* buffer, intptr_t buffer_size) { 619 intptr_t TimelineEvent::PrintSystrace(char* buffer, intptr_t buffer_size) {
520 ASSERT(buffer != NULL); 620 ASSERT(buffer != NULL);
521 ASSERT(buffer_size > 0); 621 ASSERT(buffer_size > 0);
522 buffer[0] = '\0'; 622 buffer[0] = '\0';
523 intptr_t length = 0; 623 intptr_t length = 0;
524 int64_t pid = OS::ProcessId(); 624 int64_t pid = OS::ProcessId();
525 switch (event_type()) { 625 switch (event_type()) {
526 case kBegin: { 626 case kBegin: {
527 length = OS::SNPrint(buffer, buffer_size, "B|%" Pd64 "|%s", pid, label()); 627 length = OS::SNPrint(buffer, buffer_size, "B|%" Pd64 "|%s", pid, label());
528 } break; 628 } break;
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 arguments_ = NULL; 1006 arguments_ = NULL;
907 } 1007 }
908 1008
909 1009
910 TimelineDurationScope::TimelineDurationScope(TimelineStream* stream, 1010 TimelineDurationScope::TimelineDurationScope(TimelineStream* stream,
911 const char* label) 1011 const char* label)
912 : TimelineEventScope(stream, label) { 1012 : TimelineEventScope(stream, label) {
913 if (!FLAG_support_timeline || !enabled()) { 1013 if (!FLAG_support_timeline || !enabled()) {
914 return; 1014 return;
915 } 1015 }
1016 #if defined(HOST_OS_FUCHSIA)
1017 TRACE_DURATION_BEGIN("dart", label);
1018 #else
916 timestamp_ = OS::GetCurrentMonotonicMicros(); 1019 timestamp_ = OS::GetCurrentMonotonicMicros();
917 thread_timestamp_ = OS::GetCurrentThreadCPUMicros(); 1020 thread_timestamp_ = OS::GetCurrentThreadCPUMicros();
1021 #endif
918 } 1022 }
919 1023
920 1024
921 TimelineDurationScope::TimelineDurationScope(Thread* thread, 1025 TimelineDurationScope::TimelineDurationScope(Thread* thread,
922 TimelineStream* stream, 1026 TimelineStream* stream,
923 const char* label) 1027 const char* label)
924 : TimelineEventScope(thread, stream, label) { 1028 : TimelineEventScope(thread, stream, label) {
925 if (!FLAG_support_timeline || !enabled()) { 1029 if (!FLAG_support_timeline || !enabled()) {
926 return; 1030 return;
927 } 1031 }
1032 #if defined(HOST_OS_FUCHSIA)
1033 TRACE_DURATION_BEGIN("dart", label);
1034 #else
928 timestamp_ = OS::GetCurrentMonotonicMicros(); 1035 timestamp_ = OS::GetCurrentMonotonicMicros();
929 thread_timestamp_ = OS::GetCurrentThreadCPUMicros(); 1036 thread_timestamp_ = OS::GetCurrentThreadCPUMicros();
1037 #endif
930 } 1038 }
931 1039
932 1040
933 TimelineDurationScope::~TimelineDurationScope() { 1041 TimelineDurationScope::~TimelineDurationScope() {
934 if (!FLAG_support_timeline) { 1042 if (!FLAG_support_timeline) {
935 return; 1043 return;
936 } 1044 }
937 if (!ShouldEmitEvent()) { 1045 if (!ShouldEmitEvent()) {
938 return; 1046 return;
939 } 1047 }
1048 #if defined(HOST_OS_FUCHSIA)
1049 EmitFuchsiaEndEvent(label(), arguments(), arguments_length());
1050 #else
940 TimelineEvent* event = stream()->StartEvent(); 1051 TimelineEvent* event = stream()->StartEvent();
941 if (event == NULL) { 1052 if (event == NULL) {
942 // Stream is now disabled. 1053 // Stream is now disabled.
943 return; 1054 return;
944 } 1055 }
945 ASSERT(event != NULL); 1056 ASSERT(event != NULL);
946 // Emit a duration event. 1057 // Emit a duration event.
947 event->Duration(label(), timestamp_, OS::GetCurrentMonotonicMicros(), 1058 event->Duration(label(), timestamp_, OS::GetCurrentMonotonicMicros(),
948 thread_timestamp_, OS::GetCurrentThreadCPUMicros()); 1059 thread_timestamp_, OS::GetCurrentThreadCPUMicros());
949 StealArguments(event); 1060 StealArguments(event);
950 event->Complete(); 1061 event->Complete();
1062 #endif
951 } 1063 }
952 1064
953 1065
954 TimelineBeginEndScope::TimelineBeginEndScope(TimelineStream* stream, 1066 TimelineBeginEndScope::TimelineBeginEndScope(TimelineStream* stream,
955 const char* label) 1067 const char* label)
956 : TimelineEventScope(stream, label) { 1068 : TimelineEventScope(stream, label) {
957 if (!FLAG_support_timeline) { 1069 if (!FLAG_support_timeline) {
958 return; 1070 return;
959 } 1071 }
960 EmitBegin(); 1072 EmitBegin();
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 do { 1541 do {
1430 __result = write(systrace_fd_, buffer, event_length); 1542 __result = write(systrace_fd_, buffer, event_length);
1431 } while ((__result == -1L) && (errno == EINTR)); 1543 } while ((__result == -1L) && (errno == EINTR));
1432 } 1544 }
1433 } 1545 }
1434 #endif 1546 #endif
1435 ThreadBlockCompleteEvent(event); 1547 ThreadBlockCompleteEvent(event);
1436 } 1548 }
1437 1549
1438 1550
1551 #if defined(HOST_OS_FUCHSIA)
1552 TimelineEventFuchsiaRecorder::TimelineEventFuchsiaRecorder(intptr_t capacity)
1553 : TimelineEventFixedBufferRecorder(capacity) {
1554 }
1555
1556
1557 TimelineEventBlock* TimelineEventFuchsiaRecorder::GetNewBlockLocked() {
1558 // TODO(johnmccutchan): This function should only hand out blocks
1559 // which have been marked as finished.
1560 if (block_cursor_ == num_blocks_) {
1561 block_cursor_ = 0;
1562 }
1563 TimelineEventBlock* block = blocks_[block_cursor_++];
1564 block->Reset();
1565 block->Open();
1566 return block;
1567 }
1568
1569
1570 void TimelineEventFuchsiaRecorder::CompleteEvent(TimelineEvent* event) {
1571 if (event == NULL) {
1572 return;
1573 }
1574 event->EmitFuchsiaEvent();
1575 ThreadBlockCompleteEvent(event);
1576 }
1577 #endif // defined(HOST_OS_FUCHSIA)
1578
1579
1439 TimelineEventBlock* TimelineEventRingRecorder::GetNewBlockLocked() { 1580 TimelineEventBlock* TimelineEventRingRecorder::GetNewBlockLocked() {
1440 // TODO(johnmccutchan): This function should only hand out blocks 1581 // TODO(johnmccutchan): This function should only hand out blocks
1441 // which have been marked as finished. 1582 // which have been marked as finished.
1442 if (block_cursor_ == num_blocks_) { 1583 if (block_cursor_ == num_blocks_) {
1443 block_cursor_ = 0; 1584 block_cursor_ = 0;
1444 } 1585 }
1445 TimelineEventBlock* block = blocks_[block_cursor_++]; 1586 TimelineEventBlock* block = blocks_[block_cursor_++];
1446 block->Reset(); 1587 block->Reset();
1447 block->Open(); 1588 block->Open();
1448 return block; 1589 return block;
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 TimelineEventBlock* TimelineEventBlockIterator::Next() { 1915 TimelineEventBlock* TimelineEventBlockIterator::Next() {
1775 ASSERT(current_ != NULL); 1916 ASSERT(current_ != NULL);
1776 TimelineEventBlock* r = current_; 1917 TimelineEventBlock* r = current_;
1777 current_ = current_->next(); 1918 current_ = current_->next();
1778 return r; 1919 return r;
1779 } 1920 }
1780 1921
1781 } // namespace dart 1922 } // namespace dart
1782 1923
1783 #endif // !PRODUCT 1924 #endif // !PRODUCT
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