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 #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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 thread_ = OSThread::kInvalidThreadId; | 182 thread_ = OSThread::kInvalidThreadId; |
183 isolate_id_ = ILLEGAL_PORT; | 183 isolate_id_ = ILLEGAL_PORT; |
184 category_ = ""; | 184 category_ = ""; |
185 label_ = NULL; | 185 label_ = NULL; |
186 FreeArguments(); | 186 FreeArguments(); |
187 } | 187 } |
188 | 188 |
189 | 189 |
190 void TimelineEvent::AsyncBegin(const char* label, int64_t async_id) { | 190 void TimelineEvent::AsyncBegin(const char* label, int64_t async_id) { |
191 Init(kAsyncBegin, label); | 191 Init(kAsyncBegin, label); |
192 timestamp0_ = OS::GetCurrentMonotonicMicros(); | 192 set_timestamp0(OS::GetCurrentMonotonicMicros()); |
193 // Overload timestamp1_ with the async_id. | 193 // Overload timestamp1_ with the async_id. |
194 timestamp1_ = async_id; | 194 set_timestamp1(async_id); |
195 } | 195 } |
196 | 196 |
197 | 197 |
198 void TimelineEvent::AsyncInstant(const char* label, | 198 void TimelineEvent::AsyncInstant(const char* label, |
199 int64_t async_id) { | 199 int64_t async_id) { |
200 Init(kAsyncInstant, label); | 200 Init(kAsyncInstant, label); |
201 timestamp0_ = OS::GetCurrentMonotonicMicros(); | 201 set_timestamp0(OS::GetCurrentMonotonicMicros()); |
202 // Overload timestamp1_ with the async_id. | 202 // Overload timestamp1_ with the async_id. |
203 timestamp1_ = async_id; | 203 set_timestamp1(async_id); |
204 } | 204 } |
205 | 205 |
206 | 206 |
207 void TimelineEvent::AsyncEnd(const char* label, | 207 void TimelineEvent::AsyncEnd(const char* label, |
208 int64_t async_id) { | 208 int64_t async_id) { |
209 Init(kAsyncEnd, label); | 209 Init(kAsyncEnd, label); |
210 timestamp0_ = OS::GetCurrentMonotonicMicros(); | 210 set_timestamp0(OS::GetCurrentMonotonicMicros()); |
211 // Overload timestamp1_ with the async_id. | 211 // Overload timestamp1_ with the async_id. |
212 timestamp1_ = async_id; | 212 set_timestamp1(async_id); |
213 } | 213 } |
214 | 214 |
215 | 215 |
216 void TimelineEvent::DurationBegin(const char* label) { | 216 void TimelineEvent::DurationBegin(const char* label) { |
217 Init(kDuration, label); | 217 Init(kDuration, label); |
218 timestamp0_ = OS::GetCurrentMonotonicMicros(); | 218 set_timestamp0(OS::GetCurrentMonotonicMicros()); |
219 } | 219 } |
220 | 220 |
221 | 221 |
222 void TimelineEvent::DurationEnd() { | 222 void TimelineEvent::DurationEnd() { |
223 timestamp1_ = OS::GetCurrentMonotonicMicros(); | 223 ASSERT(timestamp1_ == 0); |
| 224 set_timestamp1(OS::GetCurrentMonotonicMicros()); |
224 } | 225 } |
225 | 226 |
226 | 227 |
227 void TimelineEvent::Instant(const char* label) { | 228 void TimelineEvent::Instant(const char* label) { |
228 Init(kInstant, label); | 229 Init(kInstant, label); |
229 timestamp0_ = OS::GetCurrentMonotonicMicros(); | 230 set_timestamp0(OS::GetCurrentMonotonicMicros()); |
230 } | 231 } |
231 | 232 |
232 | 233 |
233 void TimelineEvent::Duration(const char* label, | 234 void TimelineEvent::Duration(const char* label, |
234 int64_t start_micros, | 235 int64_t start_micros, |
235 int64_t end_micros) { | 236 int64_t end_micros) { |
236 Init(kDuration, label); | 237 Init(kDuration, label); |
237 timestamp0_ = start_micros; | 238 set_timestamp0(start_micros); |
238 timestamp1_ = end_micros; | 239 set_timestamp1(end_micros); |
239 } | 240 } |
240 | 241 |
241 | 242 |
242 void TimelineEvent::Begin(const char* label, | 243 void TimelineEvent::Begin(const char* label, |
243 int64_t micros) { | 244 int64_t micros) { |
244 Init(kBegin, label); | 245 Init(kBegin, label); |
245 timestamp0_ = micros; | 246 set_timestamp0(micros); |
246 } | 247 } |
247 | 248 |
248 | 249 |
249 void TimelineEvent::End(const char* label, | 250 void TimelineEvent::End(const char* label, |
250 int64_t micros) { | 251 int64_t micros) { |
251 Init(kEnd, label); | 252 Init(kEnd, label); |
252 timestamp0_ = micros; | 253 set_timestamp0(micros); |
253 } | 254 } |
254 | 255 |
255 | 256 |
256 void TimelineEvent::SerializedJSON(const char* json) { | 257 void TimelineEvent::SerializedJSON(const char* json) { |
257 Init(kSerializedJSON, "Dart"); | 258 Init(kSerializedJSON, "Dart"); |
258 SetNumArguments(1); | 259 SetNumArguments(1); |
259 CopyArgument(0, "Dart", json); | 260 CopyArgument(0, "Dart", json); |
260 } | 261 } |
261 | 262 |
262 | 263 |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 | 669 |
669 TimelineEvent* TimelineEventRecorder::ThreadBlockStartEvent() { | 670 TimelineEvent* TimelineEventRecorder::ThreadBlockStartEvent() { |
670 // Grab the current thread. | 671 // Grab the current thread. |
671 OSThread* thread = OSThread::Current(); | 672 OSThread* thread = OSThread::Current(); |
672 ASSERT(thread != NULL); | 673 ASSERT(thread != NULL); |
673 Mutex* thread_block_lock = thread->timeline_block_lock(); | 674 Mutex* thread_block_lock = thread->timeline_block_lock(); |
674 ASSERT(thread_block_lock != NULL); | 675 ASSERT(thread_block_lock != NULL); |
675 // We are accessing the thread's timeline block- so take the lock here. | 676 // We are accessing the thread's timeline block- so take the lock here. |
676 // This lock will be held until the call to |CompleteEvent| is made. | 677 // This lock will be held until the call to |CompleteEvent| is made. |
677 thread_block_lock->Lock(); | 678 thread_block_lock->Lock(); |
| 679 #if defined(DEBUG) |
| 680 Thread* T = Thread::Current(); |
| 681 if (T != NULL) { |
| 682 T->IncrementNoSafepointScopeDepth(); |
| 683 } |
| 684 #endif // defined(DEBUG) |
678 | 685 |
679 TimelineEventBlock* thread_block = thread->timeline_block(); | 686 TimelineEventBlock* thread_block = thread->timeline_block(); |
680 | 687 |
681 if ((thread_block != NULL) && thread_block->IsFull()) { | 688 if ((thread_block != NULL) && thread_block->IsFull()) { |
682 MutexLocker ml(&lock_); | 689 MutexLocker ml(&lock_); |
683 // Thread has a block and it is full: | 690 // Thread has a block and it is full: |
684 // 1) Mark it as finished. | 691 // 1) Mark it as finished. |
685 thread_block->Finish(); | 692 thread_block->Finish(); |
686 // 2) Allocate a new block. | 693 // 2) Allocate a new block. |
687 thread_block = GetNewBlockLocked(); | 694 thread_block = GetNewBlockLocked(); |
688 thread->set_timeline_block(thread_block); | 695 thread->set_timeline_block(thread_block); |
689 } else if (thread_block == NULL) { | 696 } else if (thread_block == NULL) { |
690 MutexLocker ml(&lock_); | 697 MutexLocker ml(&lock_); |
691 // Thread has no block. Attempt to allocate one. | 698 // Thread has no block. Attempt to allocate one. |
692 thread_block = GetNewBlockLocked(); | 699 thread_block = GetNewBlockLocked(); |
693 thread->set_timeline_block(thread_block); | 700 thread->set_timeline_block(thread_block); |
694 } | 701 } |
695 if (thread_block != NULL) { | 702 if (thread_block != NULL) { |
696 // NOTE: We are exiting this function with the thread's block lock held. | 703 // NOTE: We are exiting this function with the thread's block lock held. |
697 ASSERT(!thread_block->IsFull()); | 704 ASSERT(!thread_block->IsFull()); |
698 TimelineEvent* event = thread_block->StartEvent(); | 705 TimelineEvent* event = thread_block->StartEvent(); |
699 return event; | 706 return event; |
700 } | 707 } |
701 // Drop lock here as no event is being handed out. | 708 // Drop lock here as no event is being handed out. |
| 709 #if defined(DEBUG) |
| 710 if (T != NULL) { |
| 711 T->DecrementNoSafepointScopeDepth(); |
| 712 } |
| 713 #endif // defined(DEBUG) |
702 thread_block_lock->Unlock(); | 714 thread_block_lock->Unlock(); |
703 return NULL; | 715 return NULL; |
704 } | 716 } |
705 | 717 |
706 | 718 |
707 void TimelineEventRecorder::ThreadBlockCompleteEvent(TimelineEvent* event) { | 719 void TimelineEventRecorder::ThreadBlockCompleteEvent(TimelineEvent* event) { |
708 if (event == NULL) { | 720 if (event == NULL) { |
709 return; | 721 return; |
710 } | 722 } |
711 // Grab the current thread. | 723 // Grab the current thread. |
712 OSThread* thread = OSThread::Current(); | 724 OSThread* thread = OSThread::Current(); |
713 ASSERT(thread != NULL); | 725 ASSERT(thread != NULL); |
714 // Unlock the thread's block lock. | 726 // Unlock the thread's block lock. |
715 Mutex* thread_block_lock = thread->timeline_block_lock(); | 727 Mutex* thread_block_lock = thread->timeline_block_lock(); |
716 ASSERT(thread_block_lock != NULL); | 728 ASSERT(thread_block_lock != NULL); |
| 729 #if defined(DEBUG) |
| 730 Thread* T = Thread::Current(); |
| 731 if (T != NULL) { |
| 732 T->DecrementNoSafepointScopeDepth(); |
| 733 } |
| 734 #endif // defined(DEBUG) |
717 thread_block_lock->Unlock(); | 735 thread_block_lock->Unlock(); |
718 } | 736 } |
719 | 737 |
720 | 738 |
721 void TimelineEventRecorder::WriteTo(const char* directory) { | 739 void TimelineEventRecorder::WriteTo(const char* directory) { |
722 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); | 740 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); |
723 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); | 741 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); |
724 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); | 742 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); |
725 if ((file_open == NULL) || (file_write == NULL) || (file_close == NULL)) { | 743 if ((file_open == NULL) || (file_write == NULL) || (file_close == NULL)) { |
726 return; | 744 return; |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 | 1187 |
1170 | 1188 |
1171 TimelineEventBlock* TimelineEventBlockIterator::Next() { | 1189 TimelineEventBlock* TimelineEventBlockIterator::Next() { |
1172 ASSERT(current_ != NULL); | 1190 ASSERT(current_ != NULL); |
1173 TimelineEventBlock* r = current_; | 1191 TimelineEventBlock* r = current_; |
1174 current_ = current_->next(); | 1192 current_ = current_->next(); |
1175 return r; | 1193 return r; |
1176 } | 1194 } |
1177 | 1195 |
1178 } // namespace dart | 1196 } // namespace dart |
OLD | NEW |