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

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

Issue 1897963002: Add --timeline-recorder= flag and fix --timeline-dir flag (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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/log.cc ('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 15 matching lines...) Expand all
26 "Trace timeline analysis backend"); 26 "Trace timeline analysis backend");
27 DEFINE_FLAG(bool, timing, false, 27 DEFINE_FLAG(bool, timing, false,
28 "Dump isolate timing information from timeline."); 28 "Dump isolate timing information from timeline.");
29 DEFINE_FLAG(charp, timeline_dir, NULL, 29 DEFINE_FLAG(charp, timeline_dir, NULL,
30 "Enable all timeline trace streams and output VM global trace " 30 "Enable all timeline trace streams and output VM global trace "
31 "into specified directory."); 31 "into specified directory.");
32 DEFINE_FLAG(charp, timeline_streams, NULL, 32 DEFINE_FLAG(charp, timeline_streams, NULL,
33 "Comma separated list of timeline streams to record. " 33 "Comma separated list of timeline streams to record. "
34 "Valid values: all, API, Compiler, Dart, Debugger, Embedder, " 34 "Valid values: all, API, Compiler, Dart, Debugger, Embedder, "
35 "GC, Isolate, and VM."); 35 "GC, Isolate, and VM.");
36 DEFINE_FLAG(charp, timeline_recorder, "ring",
37 "Select the timeline recorder used. "
38 "Valid values: ring, endless, and startup.")
36 39
37 // Implementation notes: 40 // Implementation notes:
38 // 41 //
39 // Writing events: 42 // Writing events:
40 // |TimelineEvent|s are written into |TimelineEventBlock|s. Each |Thread| caches 43 // |TimelineEvent|s are written into |TimelineEventBlock|s. Each |Thread| caches
41 // a |TimelineEventBlock| object so that it can write events without 44 // a |TimelineEventBlock| object so that it can write events without
42 // synchronizing with other threads in the system. Even though the |Thread| owns 45 // synchronizing with other threads in the system. Even though the |Thread| owns
43 // the |TimelineEventBlock| the block may need to be reclaimed by the reporting 46 // the |TimelineEventBlock| the block may need to be reclaimed by the reporting
44 // system. To support that, a |Thread| must hold its |timeline_block_lock_| 47 // system. To support that, a |Thread| must hold its |timeline_block_lock_|
45 // when operating on the |TimelineEventBlock|. This lock will only ever be 48 // when operating on the |TimelineEventBlock|. This lock will only ever be
(...skipping 24 matching lines...) Expand all
70 // - |Thread::thread_list_lock_| This lock is held when iterating over 73 // - |Thread::thread_list_lock_| This lock is held when iterating over
71 // |Thread|s. 74 // |Thread|s.
72 // 75 //
73 // Locks must always be taken in the following order: 76 // Locks must always be taken in the following order:
74 // |Thread::thread_list_lock_| 77 // |Thread::thread_list_lock_|
75 // |Thread::timeline_block_lock_| 78 // |Thread::timeline_block_lock_|
76 // |TimelineEventRecorder::lock_| 79 // |TimelineEventRecorder::lock_|
77 // 80 //
78 81
79 82
83 static TimelineEventRecorder* CreateTimelineRecorder() {
84 // Some flags require that we use the endless recorder.
85 const bool use_endless_recorder =
86 (FLAG_timeline_dir != NULL) || FLAG_timing || FLAG_complete_timeline;
87
88 const char* flag = FLAG_timeline_recorder;
89
90 if (use_endless_recorder || (flag != NULL)) {
91 if (use_endless_recorder || strcmp("endless", flag) == 0) {
92 if (FLAG_trace_timeline) {
93 THR_Print("Using the endless timeline recorder.\n");
94 }
95 return new TimelineEventEndlessRecorder();
96 }
97
98 if (strcmp("startup", flag) == 0) {
99 if (FLAG_trace_timeline) {
100 THR_Print("Using the startup recorder.\n");
101 }
102 return new TimelineEventStartupRecorder();
103 }
104 }
105
106 if (FLAG_trace_timeline) {
107 THR_Print("Using the ring timeline recorder.\n");
108 }
109
110 // Always fall back to the ring recorder.
111 return new TimelineEventRingRecorder();
112 }
113
114
80 // Returns a caller freed array of stream names in FLAG_timeline_streams. 115 // Returns a caller freed array of stream names in FLAG_timeline_streams.
81 static MallocGrowableArray<char*>* GetEnabledByDefaultTimelineStreams() { 116 static MallocGrowableArray<char*>* GetEnabledByDefaultTimelineStreams() {
82 MallocGrowableArray<char*>* result = new MallocGrowableArray<char*>(); 117 MallocGrowableArray<char*>* result = new MallocGrowableArray<char*>();
83 if (FLAG_timeline_streams == NULL) { 118 if (FLAG_timeline_streams == NULL) {
84 // Nothing set. 119 // Nothing set.
85 return result; 120 return result;
86 } 121 }
87 char* save_ptr; // Needed for strtok_r. 122 char* save_ptr; // Needed for strtok_r.
88 // strtok modifies arg 1 so we make a copy of it. 123 // strtok modifies arg 1 so we make a copy of it.
89 char* streams = strdup(FLAG_timeline_streams); 124 char* streams = strdup(FLAG_timeline_streams);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 (strstr(checked_stream, stream) != NULL)) { 157 (strstr(checked_stream, stream) != NULL)) {
123 return true; 158 return true;
124 } 159 }
125 } 160 }
126 return false; 161 return false;
127 } 162 }
128 163
129 164
130 void Timeline::InitOnce() { 165 void Timeline::InitOnce() {
131 ASSERT(recorder_ == NULL); 166 ASSERT(recorder_ == NULL);
132 // Default to ring recorder being enabled. 167 recorder_ = CreateTimelineRecorder();
133 const bool use_ring_recorder = true; 168 ASSERT(recorder_ != NULL);
134 // Some flags require that we use the endless recorder.
135 const bool use_endless_recorder =
136 (FLAG_timeline_dir != NULL) || FLAG_timing || FLAG_complete_timeline;
137 if (use_endless_recorder) {
138 recorder_ = new TimelineEventEndlessRecorder();
139 } else if (FLAG_startup_timeline) {
rmacnak 2016/04/19 17:30:56 FLAG_startup_timeline is now ignored but not remov
140 recorder_ = new TimelineEventStartupRecorder();
141 } else if (use_ring_recorder) {
142 recorder_ = new TimelineEventRingRecorder();
143 }
144 enabled_streams_ = GetEnabledByDefaultTimelineStreams(); 169 enabled_streams_ = GetEnabledByDefaultTimelineStreams();
145 // Global overrides. 170 // Global overrides.
146 #define TIMELINE_STREAM_FLAG_DEFAULT(name, not_used) \ 171 #define TIMELINE_STREAM_FLAG_DEFAULT(name, not_used) \
147 stream_##name##_enabled_ = HasStream(enabled_streams_, #name); \ 172 stream_##name##_enabled_ = HasStream(enabled_streams_, #name); \
148 stream_##name##_.Init(#name, \ 173 stream_##name##_.Init(#name, \
149 stream_##name##_enabled_, \ 174 stream_##name##_enabled_, \
150 &stream_##name##_enabled_); 175 &stream_##name##_enabled_);
151 TIMELINE_STREAM_LIST(TIMELINE_STREAM_FLAG_DEFAULT) 176 TIMELINE_STREAM_LIST(TIMELINE_STREAM_FLAG_DEFAULT)
152 #undef TIMELINE_STREAM_FLAG_DEFAULT 177 #undef TIMELINE_STREAM_FLAG_DEFAULT
153 178
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 void TimelineEventRecorder::WriteTo(const char* directory) { 1058 void TimelineEventRecorder::WriteTo(const char* directory) {
1034 if (!FLAG_support_service) { 1059 if (!FLAG_support_service) {
1035 return; 1060 return;
1036 } 1061 }
1037 Dart_FileOpenCallback file_open = Dart::file_open_callback(); 1062 Dart_FileOpenCallback file_open = Dart::file_open_callback();
1038 Dart_FileWriteCallback file_write = Dart::file_write_callback(); 1063 Dart_FileWriteCallback file_write = Dart::file_write_callback();
1039 Dart_FileCloseCallback file_close = Dart::file_close_callback(); 1064 Dart_FileCloseCallback file_close = Dart::file_close_callback();
1040 if ((file_open == NULL) || (file_write == NULL) || (file_close == NULL)) { 1065 if ((file_open == NULL) || (file_write == NULL) || (file_close == NULL)) {
1041 return; 1066 return;
1042 } 1067 }
1043 Thread* T = Thread::Current();
1044 StackZone zone(T);
1045 1068
1046 Timeline::ReclaimCachedBlocksFromThreads(); 1069 Timeline::ReclaimCachedBlocksFromThreads();
1047 1070
1048 intptr_t pid = OS::ProcessId(); 1071 intptr_t pid = OS::ProcessId();
1049 char* filename = OS::SCreate(NULL, 1072 char* filename = OS::SCreate(NULL,
1050 "%s/dart-timeline-%" Pd ".json", directory, pid); 1073 "%s/dart-timeline-%" Pd ".json", directory, pid);
1051 void* file = (*file_open)(filename, true); 1074 void* file = (*file_open)(filename, true);
1052 if (file == NULL) { 1075 if (file == NULL) {
1053 OS::Print("Failed to write timeline file: %s\n", filename); 1076 OS::Print("Failed to write timeline file: %s\n", filename);
1054 free(filename); 1077 free(filename);
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 TimelineEventBlock* TimelineEventBlockIterator::Next() { 1583 TimelineEventBlock* TimelineEventBlockIterator::Next() {
1561 ASSERT(current_ != NULL); 1584 ASSERT(current_ != NULL);
1562 TimelineEventBlock* r = current_; 1585 TimelineEventBlock* r = current_;
1563 current_ = current_->next(); 1586 current_ = current_->next();
1564 return r; 1587 return r;
1565 } 1588 }
1566 1589
1567 #endif // !PRODUCT 1590 #endif // !PRODUCT
1568 1591
1569 } // namespace dart 1592 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/log.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698