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

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

Issue 1975203003: Cleanup timeline stream enabled flag so that it can be easily tested from an intrinsic (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
« 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/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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 166 }
167 167
168 168
169 void Timeline::InitOnce() { 169 void Timeline::InitOnce() {
170 ASSERT(recorder_ == NULL); 170 ASSERT(recorder_ == NULL);
171 recorder_ = CreateTimelineRecorder(); 171 recorder_ = CreateTimelineRecorder();
172 ASSERT(recorder_ != NULL); 172 ASSERT(recorder_ != NULL);
173 enabled_streams_ = GetEnabledByDefaultTimelineStreams(); 173 enabled_streams_ = GetEnabledByDefaultTimelineStreams();
174 // Global overrides. 174 // Global overrides.
175 #define TIMELINE_STREAM_FLAG_DEFAULT(name, not_used) \ 175 #define TIMELINE_STREAM_FLAG_DEFAULT(name, not_used) \
176 stream_##name##_enabled_ = HasStream(enabled_streams_, #name); \
177 stream_##name##_.Init(#name, \ 176 stream_##name##_.Init(#name, \
178 stream_##name##_enabled_, \ 177 HasStream(enabled_streams_, #name));
179 &stream_##name##_enabled_);
180 TIMELINE_STREAM_LIST(TIMELINE_STREAM_FLAG_DEFAULT) 178 TIMELINE_STREAM_LIST(TIMELINE_STREAM_FLAG_DEFAULT)
181 #undef TIMELINE_STREAM_FLAG_DEFAULT 179 #undef TIMELINE_STREAM_FLAG_DEFAULT
182 180
183 if (stream_Embedder_enabled_ && 181 if (Timeline::stream_Embedder_.enabled() &&
184 (Timeline::get_start_recording_cb() != NULL)) { 182 (Timeline::get_start_recording_cb() != NULL)) {
185 Timeline::get_start_recording_cb()(); 183 Timeline::get_start_recording_cb()();
186 } 184 }
187 } 185 }
188 186
189 187
190 void Timeline::StreamStateChange(const char* stream_name, 188 void Timeline::StreamStateChange(const char* stream_name,
191 bool prev, 189 bool prev,
192 bool curr) { 190 bool curr) {
193 if (prev == curr) { 191 if (prev == curr) {
194 return; 192 return;
195 } 193 }
196 if (strcmp(stream_name, "Embedder") == 0) { 194 if (strcmp(stream_name, "Embedder") == 0) {
197 if (curr && (Timeline::get_start_recording_cb() != NULL)) { 195 if (curr && (Timeline::get_start_recording_cb() != NULL)) {
198 Timeline::get_start_recording_cb()(); 196 Timeline::get_start_recording_cb()();
199 } else if (!curr && (Timeline::get_stop_recording_cb() != NULL)) { 197 } else if (!curr && (Timeline::get_stop_recording_cb() != NULL)) {
200 Timeline::get_stop_recording_cb()(); 198 Timeline::get_stop_recording_cb()();
201 } 199 }
202 } 200 }
203 } 201 }
204 202
205 203
206 void Timeline::Shutdown() { 204 void Timeline::Shutdown() {
207 ASSERT(recorder_ != NULL); 205 ASSERT(recorder_ != NULL);
208 206
209 if (stream_Embedder_enabled_ && 207 if (Timeline::stream_Embedder_.enabled() &&
210 (Timeline::get_stop_recording_cb() != NULL)) { 208 (Timeline::get_stop_recording_cb() != NULL)) {
211 Timeline::get_stop_recording_cb()(); 209 Timeline::get_stop_recording_cb()();
212 } 210 }
213 211
214 if (FLAG_timeline_dir != NULL) { 212 if (FLAG_timeline_dir != NULL) {
215 recorder_->WriteTo(FLAG_timeline_dir); 213 recorder_->WriteTo(FLAG_timeline_dir);
216 } 214 }
217 215
218 // Disable global streams. 216 // Disable global streams.
219 #define TIMELINE_STREAM_DISABLE(name, not_used) \ 217 #define TIMELINE_STREAM_DISABLE(name, not_used) \
220 stream_##name##_enabled_ = false; 218 Timeline::stream_##name##_.set_enabled(false);
221 TIMELINE_STREAM_LIST(TIMELINE_STREAM_DISABLE) 219 TIMELINE_STREAM_LIST(TIMELINE_STREAM_DISABLE)
222 #undef TIMELINE_STREAM_DISABLE 220 #undef TIMELINE_STREAM_DISABLE
223 delete recorder_; 221 delete recorder_;
224 recorder_ = NULL; 222 recorder_ = NULL;
225 if (enabled_streams_ != NULL) { 223 if (enabled_streams_ != NULL) {
226 FreeEnabledByDefaultTimelineStreams(enabled_streams_); 224 FreeEnabledByDefaultTimelineStreams(enabled_streams_);
227 enabled_streams_ = NULL; 225 enabled_streams_ = NULL;
228 } 226 }
229 } 227 }
230 228
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 { 266 {
269 JSONArray availableStreams(&obj, "availableStreams"); 267 JSONArray availableStreams(&obj, "availableStreams");
270 #define ADD_STREAM_NAME(name, not_used) \ 268 #define ADD_STREAM_NAME(name, not_used) \
271 availableStreams.AddValue(#name); 269 availableStreams.AddValue(#name);
272 TIMELINE_STREAM_LIST(ADD_STREAM_NAME); 270 TIMELINE_STREAM_LIST(ADD_STREAM_NAME);
273 #undef ADD_STREAM_NAME 271 #undef ADD_STREAM_NAME
274 } 272 }
275 { 273 {
276 JSONArray recordedStreams(&obj, "recordedStreams"); 274 JSONArray recordedStreams(&obj, "recordedStreams");
277 #define ADD_RECORDED_STREAM_NAME(name, not_used) \ 275 #define ADD_RECORDED_STREAM_NAME(name, not_used) \
278 if (stream_##name##_enabled_) { \ 276 if (stream_##name##_.enabled()) { \
279 recordedStreams.AddValue(#name); \ 277 recordedStreams.AddValue(#name); \
280 } 278 }
281 TIMELINE_STREAM_LIST(ADD_RECORDED_STREAM_NAME); 279 TIMELINE_STREAM_LIST(ADD_RECORDED_STREAM_NAME);
282 #undef ADD_RECORDED_STREAM_NAME 280 #undef ADD_RECORDED_STREAM_NAME
283 } 281 }
284 } 282 }
285 283
286 284
287 void Timeline::Clear() { 285 void Timeline::Clear() {
288 TimelineEventRecorder* recorder = Timeline::recorder(); 286 TimelineEventRecorder* recorder = Timeline::recorder();
289 if (recorder == NULL) { 287 if (recorder == NULL) {
290 return; 288 return;
291 } 289 }
292 ReclaimCachedBlocksFromThreads(); 290 ReclaimCachedBlocksFromThreads();
293 recorder->Clear(); 291 recorder->Clear();
294 } 292 }
295 293
296 294
297 TimelineEventRecorder* Timeline::recorder_ = NULL; 295 TimelineEventRecorder* Timeline::recorder_ = NULL;
298 MallocGrowableArray<char*>* Timeline::enabled_streams_ = NULL; 296 MallocGrowableArray<char*>* Timeline::enabled_streams_ = NULL;
299 Dart_EmbedderTimelineStartRecording Timeline::start_recording_cb_ = NULL; 297 Dart_EmbedderTimelineStartRecording Timeline::start_recording_cb_ = NULL;
300 Dart_EmbedderTimelineStopRecording Timeline::stop_recording_cb_ = NULL; 298 Dart_EmbedderTimelineStopRecording Timeline::stop_recording_cb_ = NULL;
301 299
302 #define TIMELINE_STREAM_DEFINE(name, enabled_by_default) \ 300 #define TIMELINE_STREAM_DEFINE(name, enabled_by_default) \
303 bool Timeline::stream_##name##_enabled_ = enabled_by_default; \
304 TimelineStream Timeline::stream_##name##_; 301 TimelineStream Timeline::stream_##name##_;
305 TIMELINE_STREAM_LIST(TIMELINE_STREAM_DEFINE) 302 TIMELINE_STREAM_LIST(TIMELINE_STREAM_DEFINE)
306 #undef TIMELINE_STREAM_DEFINE 303 #undef TIMELINE_STREAM_DEFINE
307 304
308 TimelineEvent::TimelineEvent() 305 TimelineEvent::TimelineEvent()
309 : timestamp0_(0), 306 : timestamp0_(0),
310 timestamp1_(0), 307 timestamp1_(0),
311 thread_timestamp0_(-1), 308 thread_timestamp0_(-1),
312 thread_timestamp1_(-1), 309 thread_timestamp1_(-1),
313 arguments_(NULL), 310 arguments_(NULL),
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 if (thread_timestamp1_ == -1) { 717 if (thread_timestamp1_ == -1) {
721 // This duration is still open, use current time as end. 718 // This duration is still open, use current time as end.
722 return OS::GetCurrentThreadCPUMicros() - thread_timestamp0_; 719 return OS::GetCurrentThreadCPUMicros() - thread_timestamp0_;
723 } 720 }
724 return thread_timestamp1_ - thread_timestamp0_; 721 return thread_timestamp1_ - thread_timestamp0_;
725 } 722 }
726 723
727 724
728 TimelineStream::TimelineStream() 725 TimelineStream::TimelineStream()
729 : name_(NULL), 726 : name_(NULL),
730 enabled_(false), 727 enabled_(false) {
731 globally_enabled_(NULL) {
732 } 728 }
733 729
734 730
735 void TimelineStream::Init(const char* name, 731 void TimelineStream::Init(const char* name,
736 bool enabled, 732 bool enabled) {
737 const bool* globally_enabled) {
738 name_ = name; 733 name_ = name;
739 enabled_ = enabled; 734 enabled_ = enabled;
740 globally_enabled_ = globally_enabled;
741 } 735 }
742 736
743 737
744 TimelineEvent* TimelineStream::StartEvent() { 738 TimelineEvent* TimelineStream::StartEvent() {
745 TimelineEventRecorder* recorder = Timeline::recorder(); 739 TimelineEventRecorder* recorder = Timeline::recorder();
746 if (!Enabled() || (recorder == NULL)) { 740 if (!enabled() || (recorder == NULL)) {
747 return NULL; 741 return NULL;
748 } 742 }
749 ASSERT(name_ != NULL); 743 ASSERT(name_ != NULL);
750 TimelineEvent* event = recorder->StartEvent(); 744 TimelineEvent* event = recorder->StartEvent();
751 if (event != NULL) { 745 if (event != NULL) {
752 event->StreamInit(this); 746 event->StreamInit(this);
753 } 747 }
754 return event; 748 return event;
755 } 749 }
756 750
(...skipping 25 matching lines...) Expand all
782 776
783 TimelineEventScope::~TimelineEventScope() { 777 TimelineEventScope::~TimelineEventScope() {
784 FreeArguments(); 778 FreeArguments();
785 } 779 }
786 780
787 781
788 void TimelineEventScope::Init() { 782 void TimelineEventScope::Init() {
789 ASSERT(enabled_ == false); 783 ASSERT(enabled_ == false);
790 ASSERT(label_ != NULL); 784 ASSERT(label_ != NULL);
791 ASSERT(stream_ != NULL); 785 ASSERT(stream_ != NULL);
792 if (!stream_->Enabled()) { 786 if (!stream_->enabled()) {
793 // Stream is not enabled, do nothing. 787 // Stream is not enabled, do nothing.
794 return; 788 return;
795 } 789 }
796 enabled_ = true; 790 enabled_ = true;
797 } 791 }
798 792
799 793
800 void TimelineEventScope::SetNumArguments(intptr_t length) { 794 void TimelineEventScope::SetNumArguments(intptr_t length) {
801 if (!enabled()) { 795 if (!enabled()) {
802 return; 796 return;
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 TimelineEventBlock* TimelineEventBlockIterator::Next() { 1688 TimelineEventBlock* TimelineEventBlockIterator::Next() {
1695 ASSERT(current_ != NULL); 1689 ASSERT(current_ != NULL);
1696 TimelineEventBlock* r = current_; 1690 TimelineEventBlock* r = current_;
1697 current_ = current_->next(); 1691 current_ = current_->next();
1698 return r; 1692 return r;
1699 } 1693 }
1700 1694
1701 #endif // !PRODUCT 1695 #endif // !PRODUCT
1702 1696
1703 } // namespace dart 1697 } // 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