| OLD | NEW |
| 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 #include "vm/os.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 TimelineEvent(); | 108 TimelineEvent(); |
| 109 ~TimelineEvent(); | 109 ~TimelineEvent(); |
| 110 | 110 |
| 111 void Reset(); | 111 void Reset(); |
| 112 | 112 |
| 113 bool IsValid() const { | 113 bool IsValid() const { |
| 114 return (event_type() > kNone) && (event_type() < kNumEventTypes); | 114 return (event_type() > kNone) && (event_type() < kNumEventTypes); |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Marks the beginning of an asynchronous operation with |async_id|. | 117 // Marks the beginning of an asynchronous operation with |async_id|. |
| 118 void AsyncBegin(const char* label, int64_t async_id); | 118 void AsyncBegin(const char* label, |
| 119 int64_t async_id, |
| 120 int64_t micros = OS::GetCurrentMonotonicMicros()); |
| 119 // Marks an instantaneous event associated with |async_id|. | 121 // Marks an instantaneous event associated with |async_id|. |
| 120 void AsyncInstant(const char* label, | 122 void AsyncInstant(const char* label, |
| 121 int64_t async_id); | 123 int64_t async_id, |
| 124 int64_t micros = OS::GetCurrentMonotonicMicros()); |
| 122 // Marks the end of an asynchronous operation associated with |async_id|. | 125 // Marks the end of an asynchronous operation associated with |async_id|. |
| 123 void AsyncEnd(const char* label, | 126 void AsyncEnd(const char* label, |
| 124 int64_t async_id); | 127 int64_t async_id, |
| 128 int64_t micros = OS::GetCurrentMonotonicMicros()); |
| 125 | 129 |
| 126 void DurationBegin(const char* label); | 130 void DurationBegin(const char* label, |
| 127 void DurationEnd(); | 131 int64_t micros = OS::GetCurrentMonotonicMicros()); |
| 128 void Instant(const char* label); | 132 void DurationEnd(int64_t micros = OS::GetCurrentMonotonicMicros()); |
| 133 void Instant(const char* label, |
| 134 int64_t micros = OS::GetCurrentMonotonicMicros()); |
| 129 | 135 |
| 130 void Duration(const char* label, | 136 void Duration(const char* label, |
| 131 int64_t start_micros, | 137 int64_t start_micros, |
| 132 int64_t end_micros); | 138 int64_t end_micros); |
| 133 | 139 |
| 134 void Begin(const char* label, | 140 void Begin(const char* label, |
| 135 int64_t micros = OS::GetCurrentMonotonicMicros()); | 141 int64_t micros = OS::GetCurrentMonotonicMicros()); |
| 136 | 142 |
| 137 void End(const char* label, | 143 void End(const char* label, |
| 138 int64_t micros = OS::GetCurrentMonotonicMicros()); | 144 int64_t micros = OS::GetCurrentMonotonicMicros()); |
| 139 | 145 |
| 140 void SerializedJSON(const char* json, | 146 // Completes this event with pre-serialized JSON. Copies |json|. |
| 141 int64_t timestamp0, | 147 void CompleteWithPreSerializedJSON(const char* json); |
| 142 int64_t timestamp1); | |
| 143 | 148 |
| 144 // Set the number of arguments in the event. | 149 // Set the number of arguments in the event. |
| 145 void SetNumArguments(intptr_t length); | 150 void SetNumArguments(intptr_t length); |
| 146 // |name| must be a compile time constant. Takes ownership of |argument|. | 151 // |name| must be a compile time constant. Takes ownership of |argument|. |
| 147 void SetArgument(intptr_t i, const char* name, char* argument); | 152 void SetArgument(intptr_t i, const char* name, char* argument); |
| 148 // |name| must be a compile time constant. Copies |argument|. | 153 // |name| must be a compile time constant. Copies |argument|. |
| 149 void CopyArgument(intptr_t i, const char* name, const char* argument); | 154 void CopyArgument(intptr_t i, const char* name, const char* argument); |
| 150 // |name| must be a compile time constant. | 155 // |name| must be a compile time constant. |
| 151 void FormatArgument(intptr_t i, | 156 void FormatArgument(intptr_t i, |
| 152 const char* name, | 157 const char* name, |
| 153 const char* fmt, ...) PRINTF_ATTRIBUTE(4, 5); | 158 const char* fmt, ...) PRINTF_ATTRIBUTE(4, 5); |
| 154 | 159 |
| 155 void StealArguments(intptr_t arguments_length, | 160 void StealArguments(intptr_t arguments_length, |
| 156 TimelineEventArgument* arguments); | 161 TimelineEventArgument* arguments); |
| 157 // Mandatory to call when this event is completely filled out. | 162 // Mandatory to call when this event is completely filled out. |
| 158 void Complete(); | 163 void Complete(); |
| 159 | 164 |
| 160 EventType event_type() const { | 165 EventType event_type() const { |
| 161 return EventTypeField::decode(state_); | 166 return EventTypeField::decode(state_); |
| 162 } | 167 } |
| 163 | 168 |
| 164 bool IsFinishedDuration() const { | 169 bool IsFinishedDuration() const { |
| 165 return (SerializedJSONIsDuration() || (event_type() == kDuration)) && | 170 return (event_type() == kDuration) && (timestamp1_ > timestamp0_); |
| 166 (timestamp1_ > timestamp0_); | |
| 167 } | 171 } |
| 168 | 172 |
| 169 int64_t TimeOrigin() const; | 173 int64_t TimeOrigin() const; |
| 170 int64_t AsyncId() const; | 174 int64_t AsyncId() const; |
| 171 int64_t TimeDuration() const; | 175 int64_t TimeDuration() const; |
| 172 int64_t TimeEnd() const { | 176 int64_t TimeEnd() const { |
| 173 ASSERT(IsFinishedDuration()); | 177 ASSERT(IsFinishedDuration()); |
| 174 return timestamp1_; | 178 return timestamp1_; |
| 175 } | 179 } |
| 176 | 180 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 } | 241 } |
| 238 return true; | 242 return true; |
| 239 } | 243 } |
| 240 } | 244 } |
| 241 | 245 |
| 242 bool Within(int64_t time_origin_micros, | 246 bool Within(int64_t time_origin_micros, |
| 243 int64_t time_extent_micros); | 247 int64_t time_extent_micros); |
| 244 | 248 |
| 245 const char* GetSerializedJSON() const; | 249 const char* GetSerializedJSON() const; |
| 246 | 250 |
| 247 void SetSerializedJSONIsDuration(bool duration) { | |
| 248 state_ = SerializedJSONIsDurationField::update(duration, state_); | |
| 249 } | |
| 250 | |
| 251 bool SerializedJSONIsDuration() const { | |
| 252 return SerializedJSONIsDurationField::decode(state_); | |
| 253 } | |
| 254 | |
| 255 private: | 251 private: |
| 256 void FreeArguments(); | 252 void FreeArguments(); |
| 257 | 253 |
| 258 void StreamInit(TimelineStream* stream); | 254 void StreamInit(TimelineStream* stream); |
| 259 void Init(EventType event_type, const char* label); | 255 void Init(EventType event_type, const char* label); |
| 260 | 256 |
| 261 void set_event_type(EventType event_type) { | 257 void set_event_type(EventType event_type) { |
| 262 // We only reserve 4 bits to hold the event type. | 258 // We only reserve 4 bits to hold the event type. |
| 263 COMPILE_ASSERT(kNumEventTypes < 16); | 259 COMPILE_ASSERT(kNumEventTypes < 16); |
| 264 state_ = EventTypeField::update(event_type, state_); | 260 state_ = EventTypeField::update(event_type, state_); |
| 265 } | 261 } |
| 266 | 262 |
| 267 void set_timestamp0(int64_t value) { | 263 void set_timestamp0(int64_t value) { |
| 268 ASSERT(timestamp0_ == 0); | 264 ASSERT(timestamp0_ == 0); |
| 269 timestamp0_ = value; | 265 timestamp0_ = value; |
| 270 } | 266 } |
| 271 void set_timestamp1(int64_t value) { | 267 void set_timestamp1(int64_t value) { |
| 272 ASSERT(timestamp1_ == 0); | 268 ASSERT(timestamp1_ == 0); |
| 273 timestamp1_ = value; | 269 timestamp1_ = value; |
| 274 } | 270 } |
| 275 | 271 |
| 272 bool pre_serialized_json() const { |
| 273 return PreSerializedJSON::decode(state_); |
| 274 } |
| 275 |
| 276 void set_pre_serialized_json(bool pre_serialized_json) { |
| 277 state_ = PreSerializedJSON::update(pre_serialized_json, state_); |
| 278 } |
| 279 |
| 276 enum StateBits { | 280 enum StateBits { |
| 277 kEventTypeBit = 0, // reserve 4 bits for type. | 281 kEventTypeBit = 0, // reserve 4 bits for type. |
| 278 kSerializedJSONIsDuration = 4, | 282 kPreSerializedJSON = 4, |
| 279 kNextBit = 5, | 283 kNextBit = 5, |
| 280 }; | 284 }; |
| 281 | 285 |
| 282 class EventTypeField : public BitField<EventType, kEventTypeBit, 4> {}; | 286 class EventTypeField : public BitField<EventType, kEventTypeBit, 4> {}; |
| 283 class SerializedJSONIsDurationField : | 287 class PreSerializedJSON : |
| 284 public BitField<bool, kSerializedJSONIsDuration, 1> {}; | 288 public BitField<bool, kPreSerializedJSON, 1> {}; |
| 285 | 289 |
| 286 int64_t timestamp0_; | 290 int64_t timestamp0_; |
| 287 int64_t timestamp1_; | 291 int64_t timestamp1_; |
| 288 TimelineEventArgument* arguments_; | 292 TimelineEventArgument* arguments_; |
| 289 intptr_t arguments_length_; | 293 intptr_t arguments_length_; |
| 290 uword state_; | 294 uword state_; |
| 291 const char* label_; | 295 const char* label_; |
| 292 const char* category_; | 296 const char* category_; |
| 293 ThreadId thread_; | 297 ThreadId thread_; |
| 294 Dart_Port isolate_id_; | 298 Dart_Port isolate_id_; |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 | 743 |
| 740 private: | 744 private: |
| 741 TimelineEventBlock* current_; | 745 TimelineEventBlock* current_; |
| 742 TimelineEventRecorder* recorder_; | 746 TimelineEventRecorder* recorder_; |
| 743 }; | 747 }; |
| 744 | 748 |
| 745 | 749 |
| 746 } // namespace dart | 750 } // namespace dart |
| 747 | 751 |
| 748 #endif // VM_TIMELINE_H_ | 752 #endif // VM_TIMELINE_H_ |
| OLD | NEW |