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

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

Issue 1395803002: Stop holding onto TimelineEvents (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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 | « no previous file | runtime/vm/timeline.cc » ('j') | runtime/vm/timeline.cc » ('J')
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 #ifndef VM_TIMELINE_H_ 5 #ifndef VM_TIMELINE_H_
6 #define VM_TIMELINE_H_ 6 #define VM_TIMELINE_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/bitfield.h" 9 #include "vm/bitfield.h"
10 #include "vm/os.h"
10 11
11 namespace dart { 12 namespace dart {
12 13
13 class JSONArray; 14 class JSONArray;
14 class JSONObject; 15 class JSONObject;
15 class JSONStream; 16 class JSONStream;
16 class Object; 17 class Object;
17 class ObjectPointerVisitor; 18 class ObjectPointerVisitor;
18 class Isolate; 19 class Isolate;
19 class RawArray; 20 class RawArray;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 #define ISOLATE_TIMELINE_STREAM_DECLARE_FLAG(name, not_used) \ 75 #define ISOLATE_TIMELINE_STREAM_DECLARE_FLAG(name, not_used) \
75 static bool stream_##name##_enabled_; 76 static bool stream_##name##_enabled_;
76 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_DECLARE_FLAG) 77 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_DECLARE_FLAG)
77 #undef ISOLATE_TIMELINE_STREAM_DECLARE_FLAG 78 #undef ISOLATE_TIMELINE_STREAM_DECLARE_FLAG
78 79
79 friend class TimelineRecorderOverride; 80 friend class TimelineRecorderOverride;
80 friend class ReclaimBlocksIsolateVisitor; 81 friend class ReclaimBlocksIsolateVisitor;
81 }; 82 };
82 83
83 84
85 struct TimelineEventArgument {
86 const char* name;
87 char* value;
88 };
89
90
84 // You should get a |TimelineEvent| from a |TimelineStream|. 91 // You should get a |TimelineEvent| from a |TimelineStream|.
85 class TimelineEvent { 92 class TimelineEvent {
86 public: 93 public:
87 // Keep in sync with StateBits below. 94 // Keep in sync with StateBits below.
88 enum EventType { 95 enum EventType {
89 kNone, 96 kNone,
90 kBegin, 97 kBegin,
91 kEnd, 98 kEnd,
92 kDuration, 99 kDuration,
93 kInstant, 100 kInstant,
(...skipping 23 matching lines...) Expand all
117 124
118 void DurationBegin(const char* label); 125 void DurationBegin(const char* label);
119 void DurationEnd(); 126 void DurationEnd();
120 void Instant(const char* label); 127 void Instant(const char* label);
121 128
122 void Duration(const char* label, 129 void Duration(const char* label,
123 int64_t start_micros, 130 int64_t start_micros,
124 int64_t end_micros); 131 int64_t end_micros);
125 132
126 void Begin(const char* label, 133 void Begin(const char* label,
127 int64_t micros); 134 int64_t micros = OS::GetCurrentTraceMicros());
128 135
129 void End(const char* label, 136 void End(const char* label,
130 int64_t micros); 137 int64_t micros = OS::GetCurrentTraceMicros());
131 138
132 // Set the number of arguments in the event. 139 // Set the number of arguments in the event.
133 void SetNumArguments(intptr_t length); 140 void SetNumArguments(intptr_t length);
134 // |name| must be a compile time constant. Takes ownership of |argumentp|. 141 // |name| must be a compile time constant. Takes ownership of |argumentp|.
135 void SetArgument(intptr_t i, const char* name, char* argument); 142 void SetArgument(intptr_t i, const char* name, char* argument);
136 // |name| must be a compile time constant. Copies |argument|. 143 // |name| must be a compile time constant. Copies |argument|.
137 void CopyArgument(intptr_t i, const char* name, const char* argument); 144 void CopyArgument(intptr_t i, const char* name, const char* argument);
138 // |name| must be a compile time constant. 145 // |name| must be a compile time constant.
139 void FormatArgument(intptr_t i, 146 void FormatArgument(intptr_t i,
140 const char* name, 147 const char* name,
141 const char* fmt, ...) PRINTF_ATTRIBUTE(4, 5); 148 const char* fmt, ...) PRINTF_ATTRIBUTE(4, 5);
142 149
150 void StealArguments(intptr_t arguments_length,
151 TimelineEventArgument* arguments);
143 // Mandatory to call when this event is completely filled out. 152 // Mandatory to call when this event is completely filled out.
144 void Complete(); 153 void Complete();
145 154
146 EventType event_type() const { 155 EventType event_type() const {
147 return EventTypeField::decode(state_); 156 return EventTypeField::decode(state_);
148 } 157 }
149 158
150 bool IsFinishedDuration() const { 159 bool IsFinishedDuration() const {
151 return (event_type() == kDuration) && (timestamp1_ > timestamp0_); 160 return (event_type() == kDuration) && (timestamp1_ > timestamp0_);
152 } 161 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 return false; 223 return false;
215 } 224 }
216 if (other->TimeEnd() > TimeEnd()) { 225 if (other->TimeEnd() > TimeEnd()) {
217 return false; 226 return false;
218 } 227 }
219 return true; 228 return true;
220 } 229 }
221 } 230 }
222 231
223 private: 232 private:
224 struct TimelineEventArgument {
225 const char* name;
226 char* value;
227 };
228
229 int64_t timestamp0_; 233 int64_t timestamp0_;
230 int64_t timestamp1_; 234 int64_t timestamp1_;
231 TimelineEventArgument* arguments_; 235 TimelineEventArgument* arguments_;
232 intptr_t arguments_length_; 236 intptr_t arguments_length_;
233 uword state_; 237 uword state_;
234 const char* label_; 238 const char* label_;
235 const char* category_; 239 const char* category_;
236 ThreadId thread_; 240 ThreadId thread_;
237 Isolate* isolate_; 241 Isolate* isolate_;
238 242
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 bool enabled() const { 287 bool enabled() const {
284 return enabled_; 288 return enabled_;
285 } 289 }
286 290
287 void set_enabled(bool enabled) { 291 void set_enabled(bool enabled) {
288 enabled_ = enabled; 292 enabled_ = enabled;
289 } 293 }
290 294
291 // Records an event. Will return |NULL| if not enabled. The returned 295 // Records an event. Will return |NULL| if not enabled. The returned
292 // |TimelineEvent| is in an undefined state and must be initialized. 296 // |TimelineEvent| is in an undefined state and must be initialized.
297 // NOTE: It is not allowed to call StartEvent again without completing
298 // the first event.
293 TimelineEvent* StartEvent(); 299 TimelineEvent* StartEvent();
294 300
295 private: 301 private:
296 const char* name_; 302 const char* name_;
297 bool enabled_; 303 bool enabled_;
298 const bool* globally_enabled_; 304 const bool* globally_enabled_;
299 }; 305 };
300 306
301 #define TIMELINE_FUNCTION_COMPILATION_DURATION(thread, suffix, function) \ 307 #define TIMELINE_FUNCTION_COMPILATION_DURATION(thread, suffix, function) \
302 TimelineDurationScope tds(thread, \ 308 TimelineDurationScope tds(thread, \
303 thread->isolate()->GetCompilerStream(), \ 309 thread->isolate()->GetCompilerStream(), \
304 "Compile" suffix); \ 310 "Compile" suffix); \
305 if (tds.enabled()) { \ 311 if (tds.enabled()) { \
306 tds.SetNumArguments(1); \ 312 tds.SetNumArguments(1); \
307 tds.CopyArgument( \ 313 tds.CopyArgument( \
308 0, \ 314 0, \
309 "function", \ 315 "function", \
310 const_cast<char*>(function.ToLibNamePrefixedQualifiedCString())); \ 316 const_cast<char*>(function.ToLibNamePrefixedQualifiedCString())); \
311 } 317 }
312 318
313 319
314 // TODO(johnmccutchan): TimelineDurationScope should only allocate the
315 // event when complete.
316 class TimelineDurationScope : public StackResource { 320 class TimelineDurationScope : public StackResource {
317 public: 321 public:
318 TimelineDurationScope(Isolate* isolate, 322 TimelineDurationScope(Isolate* isolate,
319 TimelineStream* stream, 323 TimelineStream* stream,
320 const char* label) 324 const char* label)
321 : StackResource(isolate) { 325 : StackResource(isolate),
322 Init(stream, label); 326 stream_(stream),
327 label_(label),
328 arguments_(NULL),
329 arguments_length_(0),
330 enabled_(false) {
331 Init();
323 } 332 }
324 333
325 TimelineDurationScope(Thread* thread, 334 TimelineDurationScope(Thread* thread,
326 TimelineStream* stream, 335 TimelineStream* stream,
327 const char* label) 336 const char* label)
328 : StackResource(thread) { 337 : StackResource(thread),
329 Init(stream, label); 338 stream_(stream),
339 label_(label),
340 arguments_(NULL),
341 arguments_length_(0),
342 enabled_(false) {
343 Init();
330 } 344 }
331 345
332 TimelineDurationScope(TimelineStream* stream, 346 TimelineDurationScope(TimelineStream* stream,
333 const char* label) 347 const char* label)
334 : StackResource(reinterpret_cast<Thread*>(NULL)) { 348 : StackResource(reinterpret_cast<Thread*>(NULL)),
335 Init(stream, label); 349 stream_(stream),
350 label_(label),
351 arguments_(NULL),
352 arguments_length_(0),
353 enabled_(false) {
354 Init();
336 } 355 }
337 356
338 void Init(TimelineStream* stream, const char* label) { 357 ~TimelineDurationScope();
339 event_ = stream->StartEvent(); 358
340 if (event_ == NULL) { 359 bool enabled() const {
341 return; 360 return enabled_;
342 }
343 event_->DurationBegin(label);
344 } 361 }
345 362
346 bool enabled() const { 363 void SetNumArguments(intptr_t length);
347 return event_ != NULL;
348 }
349 364
350 void SetNumArguments(intptr_t length) { 365 void SetArgument(intptr_t i, const char* name, char* argument);
351 if (event_ == NULL) {
352 return;
353 }
354 event_->SetNumArguments(length);
355 }
356 366
357 void SetArgument(intptr_t i, const char* name, char* argument) { 367 void CopyArgument(intptr_t i, const char* name, const char* argument);
358 if (event_ == NULL) {
359 return;
360 }
361 event_->SetArgument(i, name, argument);
362 }
363
364 void CopyArgument(intptr_t i, const char* name, const char* argument) {
365 if (event_ == NULL) {
366 return;
367 }
368 event_->CopyArgument(i, name, argument);
369 }
370 368
371 void FormatArgument(intptr_t i, 369 void FormatArgument(intptr_t i,
372 const char* name, 370 const char* name,
373 const char* fmt, ...) PRINTF_ATTRIBUTE(4, 5); 371 const char* fmt, ...) PRINTF_ATTRIBUTE(4, 5);
374 372
375 ~TimelineDurationScope() { 373 private:
376 if (event_ == NULL) { 374 void Init();
377 return; 375 void FreeArguments();
378 }
379 event_->DurationEnd();
380 event_->Complete();
381 }
382 376
383 private: 377 TimelineStream* stream_;
384 TimelineEvent* event_; 378 const char* label_;
379 TimelineEventArgument* arguments_;
380 intptr_t arguments_length_;
381 bool enabled_;
385 }; 382 };
386 383
387 384
388 // A block of |TimelineEvent|s. Not thread safe. 385 // A block of |TimelineEvent|s. Not thread safe.
389 class TimelineEventBlock { 386 class TimelineEventBlock {
390 public: 387 public:
391 static const intptr_t kBlockSize = 64; 388 static const intptr_t kBlockSize = 64;
392 389
393 explicit TimelineEventBlock(intptr_t index); 390 explicit TimelineEventBlock(intptr_t index);
394 ~TimelineEventBlock(); 391 ~TimelineEventBlock();
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 virtual void CompleteEvent(TimelineEvent* event) = 0; 577 virtual void CompleteEvent(TimelineEvent* event) = 0;
581 virtual TimelineEventBlock* GetHeadBlockLocked() = 0; 578 virtual TimelineEventBlock* GetHeadBlockLocked() = 0;
582 virtual TimelineEventBlock* GetNewBlockLocked(Isolate* isolate) = 0; 579 virtual TimelineEventBlock* GetNewBlockLocked(Isolate* isolate) = 0;
583 virtual intptr_t NumDartEventsLocked() = 0; 580 virtual intptr_t NumDartEventsLocked() = 0;
584 virtual DartTimelineEvent* DartEventAtLocked(intptr_t i) = 0; 581 virtual DartTimelineEvent* DartEventAtLocked(intptr_t i) = 0;
585 582
586 // Utility method(s). 583 // Utility method(s).
587 void PrintJSONMeta(JSONArray* array) const; 584 void PrintJSONMeta(JSONArray* array) const;
588 TimelineEvent* ThreadBlockStartEvent(); 585 TimelineEvent* ThreadBlockStartEvent();
589 TimelineEvent* GlobalBlockStartEvent(); 586 TimelineEvent* GlobalBlockStartEvent();
587 void ThreadBlockCompleteEvent(TimelineEvent* event);
588 void GlobalBlockCompleteEvent(TimelineEvent* event);
590 589
591 Mutex lock_; 590 Mutex lock_;
592 // Only accessed under |lock_|. 591 // Only accessed under |lock_|.
593 TimelineEventBlock* global_block_; 592 TimelineEventBlock* global_block_;
594 void ReclaimGlobalBlock(); 593 void ReclaimGlobalBlock();
595 594
596 uintptr_t async_id_; 595 uintptr_t async_id_;
597 596
598 friend class DartTimelineEventIterator; 597 friend class DartTimelineEventIterator;
599 friend class TimelineEvent; 598 friend class TimelineEvent;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 749
751 private: 750 private:
752 intptr_t cursor_; 751 intptr_t cursor_;
753 intptr_t num_events_; 752 intptr_t num_events_;
754 TimelineEventRecorder* recorder_; 753 TimelineEventRecorder* recorder_;
755 }; 754 };
756 755
757 } // namespace dart 756 } // namespace dart
758 757
759 #endif // VM_TIMELINE_H_ 758 #endif // VM_TIMELINE_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/timeline.cc » ('j') | runtime/vm/timeline.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698