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

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

Issue 1296353002: Add --timing (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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/thread_registry.h ('k') | runtime/vm/timeline.h » ('j') | 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 "vm/thread_registry.h" 5 #include "vm/thread_registry.h"
6 6
7 #include "vm/isolate.h" 7 #include "vm/isolate.h"
8 #include "vm/lockers.h" 8 #include "vm/lockers.h"
9 9
10 namespace dart { 10 namespace dart {
11 11
12 ThreadRegistry::~ThreadRegistry() { 12 ThreadRegistry::~ThreadRegistry() {
13 { 13 CloseAllTimelineBlocks();
14 // Each thread that is scheduled in this isolate may have a cached timeline
15 // block. Mark these timeline blocks as finished.
16 MonitorLocker ml(monitor_);
17 TimelineEventRecorder* recorder = Timeline::recorder();
18 if (recorder != NULL) {
19 MutexLocker recorder_lock(&recorder->lock_);
20 for (intptr_t i = 0; i < entries_.length(); i++) {
21 // NOTE: It is only safe to access |entry.state| here.
22 const Entry& entry = entries_.At(i);
23 if (entry.state.timeline_block != NULL) {
24 entry.state.timeline_block->Finish();
25 }
26 }
27 }
28 }
29
30 // Delete monitor. 14 // Delete monitor.
31 delete monitor_; 15 delete monitor_;
32 } 16 }
33 17
34 18
35 void ThreadRegistry::SafepointThreads() { 19 void ThreadRegistry::SafepointThreads() {
36 MonitorLocker ml(monitor_); 20 MonitorLocker ml(monitor_);
37 // First wait for any older rounds that are still in progress. 21 // First wait for any older rounds that are still in progress.
38 while (in_rendezvous_) { 22 while (in_rendezvous_) {
39 // Assert we are not the organizer trying to nest calls to SafepointThreads. 23 // Assert we are not the organizer trying to nest calls to SafepointThreads.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 intptr_t found_index = -1; 60 intptr_t found_index = -1;
77 for (intptr_t index = 0; index < length; index++) { 61 for (intptr_t index = 0; index < length; index++) {
78 if (entries_.At(index).thread == thread) { 62 if (entries_.At(index).thread == thread) {
79 found_index = index; 63 found_index = index;
80 break; 64 break;
81 } 65 }
82 } 66 }
83 if (found_index < 0) { 67 if (found_index < 0) {
84 return; 68 return;
85 } 69 }
70 {
71 TimelineEventRecorder* recorder = Timeline::recorder();
72 if (recorder != NULL) {
73 MutexLocker recorder_lock(&recorder->lock_);
74 // Cleanup entry.
75 Entry& entry_to_remove = entries_[found_index];
76 CloseTimelineBlockLocked(&entry_to_remove);
77 }
78 }
86 if (found_index != (length - 1)) { 79 if (found_index != (length - 1)) {
87 // Swap with last entry. 80 // Swap with last entry.
88 entries_.Swap(found_index, length - 1); 81 entries_.Swap(found_index, length - 1);
89 } 82 }
90 entries_.RemoveLast(); 83 entries_.RemoveLast();
91 } 84 }
92 85
93 86
87 void ThreadRegistry::CloseAllTimelineBlocks() {
88 // Each thread that is scheduled in this isolate may have a cached timeline
89 // block. Mark these timeline blocks as finished.
90 MonitorLocker ml(monitor_);
91 TimelineEventRecorder* recorder = Timeline::recorder();
92 if (recorder != NULL) {
93 MutexLocker recorder_lock(&recorder->lock_);
94 for (intptr_t i = 0; i < entries_.length(); i++) {
95 // NOTE: It is only safe to access |entry.state| here.
96 Entry& entry = entries_[i];
97 CloseTimelineBlockLocked(&entry);
98 }
99 }
100 }
101
102
103 void ThreadRegistry::CloseTimelineBlockLocked(Entry* entry) {
104 if ((entry != NULL) && !entry->scheduled &&
105 (entry->state.timeline_block != NULL)) {
106 entry->state.timeline_block->Finish();
107 entry->state.timeline_block = NULL;
108 }
109 }
110
111
94 ThreadRegistry::EntryIterator::EntryIterator(ThreadRegistry* registry) 112 ThreadRegistry::EntryIterator::EntryIterator(ThreadRegistry* registry)
95 : index_(0), 113 : index_(0),
96 registry_(NULL) { 114 registry_(NULL) {
97 Reset(registry); 115 Reset(registry);
98 } 116 }
99 117
100 118
101 ThreadRegistry::EntryIterator::~EntryIterator() { 119 ThreadRegistry::EntryIterator::~EntryIterator() {
102 Reset(NULL); 120 Reset(NULL);
103 } 121 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 for (int i = 0; i < entries_.length(); ++i) { 184 for (int i = 0; i < entries_.length(); ++i) {
167 const Entry& entry = entries_[i]; 185 const Entry& entry = entries_[i];
168 if (entry.scheduled) { 186 if (entry.scheduled) {
169 ++count; 187 ++count;
170 } 188 }
171 } 189 }
172 return count; 190 return count;
173 } 191 }
174 192
175 } // namespace dart 193 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/thread_registry.h ('k') | runtime/vm/timeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698