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

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

Issue 1439483003: - Add an OSThread structure which is the generic TLS structure for all C++ (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: tweak-comment Created 5 years, 1 month 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
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 119 }
120 120
121 121
122 void Timeline::ReclaimCachedBlocksFromThreads() { 122 void Timeline::ReclaimCachedBlocksFromThreads() {
123 TimelineEventRecorder* recorder = Timeline::recorder(); 123 TimelineEventRecorder* recorder = Timeline::recorder();
124 if (recorder == NULL) { 124 if (recorder == NULL) {
125 return; 125 return;
126 } 126 }
127 127
128 // Iterate over threads. 128 // Iterate over threads.
129 ThreadIterator it; 129 OSThreadIterator it;
130 while (it.HasNext()) { 130 while (it.HasNext()) {
131 Thread* thread = it.Next(); 131 OSThread* thread = it.Next();
132 MutexLocker ml(thread->timeline_block_lock()); 132 MutexLocker ml(thread->timeline_block_lock());
133 // Grab block and clear it. 133 // Grab block and clear it.
134 TimelineEventBlock* block = thread->timeline_block(); 134 TimelineEventBlock* block = thread->timeline_block();
135 thread->set_timeline_block(NULL); 135 thread->set_timeline_block(NULL);
136 // TODO(johnmccutchan): Consider dropping the timeline_block_lock here 136 // TODO(johnmccutchan): Consider dropping the timeline_block_lock here
137 // if we can do it everywhere. This would simplify the lock ordering 137 // if we can do it everywhere. This would simplify the lock ordering
138 // requirements. 138 // requirements.
139 recorder->FinishBlock(block); 139 recorder->FinishBlock(block);
140 } 140 }
141 } 141 }
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 : isolate_id_(isolate_id) { 634 : isolate_id_(isolate_id) {
635 } 635 }
636 636
637 637
638 TimelineEventRecorder::TimelineEventRecorder() 638 TimelineEventRecorder::TimelineEventRecorder()
639 : async_id_(0) { 639 : async_id_(0) {
640 } 640 }
641 641
642 642
643 void TimelineEventRecorder::PrintJSONMeta(JSONArray* events) const { 643 void TimelineEventRecorder::PrintJSONMeta(JSONArray* events) const {
644 ThreadIterator it; 644 OSThreadIterator it;
645 while (it.HasNext()) { 645 while (it.HasNext()) {
646 Thread* thread = it.Next(); 646 OSThread* thread = it.Next();
647 const char* thread_name = thread->name(); 647 const char* thread_name = thread->name();
648 if (thread_name == NULL) { 648 if (thread_name == NULL) {
649 // Only emit a thread name if one was set. 649 // Only emit a thread name if one was set.
650 continue; 650 continue;
651 } 651 }
652 JSONObject obj(events); 652 JSONObject obj(events);
653 int64_t pid = OS::ProcessId(); 653 int64_t pid = OS::ProcessId();
654 int64_t tid = OSThread::ThreadIdToIntPtr(thread->trace_id()); 654 int64_t tid = OSThread::ThreadIdToIntPtr(thread->trace_id());
655 obj.AddProperty("name", "thread_name"); 655 obj.AddProperty("name", "thread_name");
656 obj.AddProperty("ph", "M"); 656 obj.AddProperty("ph", "M");
657 obj.AddProperty64("pid", pid); 657 obj.AddProperty64("pid", pid);
658 obj.AddProperty64("tid", tid); 658 obj.AddProperty64("tid", tid);
659 { 659 {
660 JSONObject args(&obj, "args"); 660 JSONObject args(&obj, "args");
661 args.AddPropertyF("name", "%s (%" Pd64 ")", thread_name, tid); 661 args.AddPropertyF("name", "%s (%" Pd64 ")", thread_name, tid);
662 } 662 }
663 } 663 }
664 } 664 }
665 665
666 666
667 TimelineEvent* TimelineEventRecorder::ThreadBlockStartEvent() { 667 TimelineEvent* TimelineEventRecorder::ThreadBlockStartEvent() {
668 // Grab the current thread. 668 // Grab the current thread.
669 Thread* thread = Thread::Current(); 669 OSThread* thread = OSThread::Current();
670 ASSERT(thread != NULL); 670 ASSERT(thread != NULL);
671 Mutex* thread_block_lock = thread->timeline_block_lock(); 671 Mutex* thread_block_lock = thread->timeline_block_lock();
672 ASSERT(thread_block_lock != NULL); 672 ASSERT(thread_block_lock != NULL);
673 // We are accessing the thread's timeline block- so take the lock here. 673 // We are accessing the thread's timeline block- so take the lock here.
674 // This lock will be held until the call to |CompleteEvent| is made. 674 // This lock will be held until the call to |CompleteEvent| is made.
675 thread_block_lock->Lock(); 675 thread_block_lock->Lock();
676 676
677 TimelineEventBlock* thread_block = thread->timeline_block(); 677 TimelineEventBlock* thread_block = thread->timeline_block();
678 678
679 if ((thread_block != NULL) && thread_block->IsFull()) { 679 if ((thread_block != NULL) && thread_block->IsFull()) {
(...skipping 20 matching lines...) Expand all
700 thread_block_lock->Unlock(); 700 thread_block_lock->Unlock();
701 return NULL; 701 return NULL;
702 } 702 }
703 703
704 704
705 void TimelineEventRecorder::ThreadBlockCompleteEvent(TimelineEvent* event) { 705 void TimelineEventRecorder::ThreadBlockCompleteEvent(TimelineEvent* event) {
706 if (event == NULL) { 706 if (event == NULL) {
707 return; 707 return;
708 } 708 }
709 // Grab the current thread. 709 // Grab the current thread.
710 Thread* thread = Thread::Current(); 710 OSThread* thread = OSThread::Current();
711 ASSERT(thread != NULL); 711 ASSERT(thread != NULL);
712 // Unlock the thread's block lock. 712 // Unlock the thread's block lock.
713 Mutex* thread_block_lock = thread->timeline_block_lock(); 713 Mutex* thread_block_lock = thread->timeline_block_lock();
714 ASSERT(thread_block_lock != NULL); 714 ASSERT(thread_block_lock != NULL);
715 thread_block_lock->Unlock(); 715 thread_block_lock->Unlock();
716 } 716 }
717 717
718 718
719 void TimelineEventRecorder::WriteTo(const char* directory) { 719 void TimelineEventRecorder::WriteTo(const char* directory) {
720 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); 720 Dart_FileOpenCallback file_open = Isolate::file_open_callback();
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 if (block->LowerTimeBound() < earliest_time) { 894 if (block->LowerTimeBound() < earliest_time) {
895 earliest_time = block->LowerTimeBound(); 895 earliest_time = block->LowerTimeBound();
896 earliest_index = block_idx; 896 earliest_index = block_idx;
897 } 897 }
898 } 898 }
899 return earliest_index; 899 return earliest_index;
900 } 900 }
901 901
902 902
903 TimelineEvent* TimelineEventRingRecorder::StartEvent() { 903 TimelineEvent* TimelineEventRingRecorder::StartEvent() {
904 // Grab the current thread.
905 Thread* thread = Thread::Current();
906 ASSERT(thread != NULL);
907 return ThreadBlockStartEvent(); 904 return ThreadBlockStartEvent();
908 } 905 }
909 906
910 907
911 void TimelineEventRingRecorder::CompleteEvent(TimelineEvent* event) { 908 void TimelineEventRingRecorder::CompleteEvent(TimelineEvent* event) {
912 if (event == NULL) { 909 if (event == NULL) {
913 return; 910 return;
914 } 911 }
915 ThreadBlockCompleteEvent(event); 912 ThreadBlockCompleteEvent(event);
916 } 913 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 PrintJSONEvents(&events, filter); 976 PrintJSONEvents(&events, filter);
980 } 977 }
981 978
982 979
983 TimelineEventBlock* TimelineEventEndlessRecorder::GetHeadBlockLocked() { 980 TimelineEventBlock* TimelineEventEndlessRecorder::GetHeadBlockLocked() {
984 return head_; 981 return head_;
985 } 982 }
986 983
987 984
988 TimelineEvent* TimelineEventEndlessRecorder::StartEvent() { 985 TimelineEvent* TimelineEventEndlessRecorder::StartEvent() {
989 // Grab the current thread.
990 Thread* thread = Thread::Current();
991 ASSERT(thread != NULL);
992 return ThreadBlockStartEvent(); 986 return ThreadBlockStartEvent();
993 } 987 }
994 988
995 989
996 void TimelineEventEndlessRecorder::CompleteEvent(TimelineEvent* event) { 990 void TimelineEventEndlessRecorder::CompleteEvent(TimelineEvent* event) {
997 if (event == NULL) { 991 if (event == NULL) {
998 return; 992 return;
999 } 993 }
1000 ThreadBlockCompleteEvent(event); 994 ThreadBlockCompleteEvent(event);
1001 } 995 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 1032
1039 void TimelineEventEndlessRecorder::Clear() { 1033 void TimelineEventEndlessRecorder::Clear() {
1040 TimelineEventBlock* current = head_; 1034 TimelineEventBlock* current = head_;
1041 while (current != NULL) { 1035 while (current != NULL) {
1042 TimelineEventBlock* next = current->next(); 1036 TimelineEventBlock* next = current->next();
1043 delete current; 1037 delete current;
1044 current = next; 1038 current = next;
1045 } 1039 }
1046 head_ = NULL; 1040 head_ = NULL;
1047 block_index_ = 0; 1041 block_index_ = 0;
1048 Thread* thread = Thread::Current(); 1042 OSThread* thread = OSThread::Current();
1049 thread->set_timeline_block(NULL); 1043 thread->set_timeline_block(NULL);
1050 } 1044 }
1051 1045
1052 1046
1053 TimelineEventBlock::TimelineEventBlock(intptr_t block_index) 1047 TimelineEventBlock::TimelineEventBlock(intptr_t block_index)
1054 : next_(NULL), 1048 : next_(NULL),
1055 length_(0), 1049 length_(0),
1056 block_index_(block_index), 1050 block_index_(block_index),
1057 thread_id_(OSThread::kInvalidThreadId), 1051 thread_id_(OSThread::kInvalidThreadId),
1058 in_use_(false) { 1052 in_use_(false) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 1163
1170 1164
1171 TimelineEventBlock* TimelineEventBlockIterator::Next() { 1165 TimelineEventBlock* TimelineEventBlockIterator::Next() {
1172 ASSERT(current_ != NULL); 1166 ASSERT(current_ != NULL);
1173 TimelineEventBlock* r = current_; 1167 TimelineEventBlock* r = current_;
1174 current_ = current_->next(); 1168 current_ = current_->next();
1175 return r; 1169 return r;
1176 } 1170 }
1177 1171
1178 } // namespace dart 1172 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698