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

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

Issue 86793002: Ensure profiler manager thread has shutdown before main thread (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/profiler.h ('k') | runtime/vm/profiler_android.cc » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 <cstdio> 5 #include <cstdio>
6 6
7 #include "platform/utils.h" 7 #include "platform/utils.h"
8 8
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/json_stream.h" 10 #include "vm/json_stream.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // If the VM is compiled without frame pointers (which is the default on 66 // If the VM is compiled without frame pointers (which is the default on
67 // recent GCC versions with optimizing enabled) the stack walking code will 67 // recent GCC versions with optimizing enabled) the stack walking code will
68 // fail (sometimes leading to a crash). 68 // fail (sometimes leading to a crash).
69 // 69 //
70 70
71 DEFINE_FLAG(bool, profile, true, "Enable Sampling Profiler"); 71 DEFINE_FLAG(bool, profile, true, "Enable Sampling Profiler");
72 DEFINE_FLAG(bool, trace_profiled_isolates, false, "Trace profiled isolates."); 72 DEFINE_FLAG(bool, trace_profiled_isolates, false, "Trace profiled isolates.");
73 73
74 bool ProfilerManager::initialized_ = false; 74 bool ProfilerManager::initialized_ = false;
75 bool ProfilerManager::shutdown_ = false; 75 bool ProfilerManager::shutdown_ = false;
76 bool ProfilerManager::thread_running_ = false;
76 Monitor* ProfilerManager::monitor_ = NULL; 77 Monitor* ProfilerManager::monitor_ = NULL;
78 Monitor* ProfilerManager::start_stop_monitor_ = NULL;
77 Isolate** ProfilerManager::isolates_ = NULL; 79 Isolate** ProfilerManager::isolates_ = NULL;
78 intptr_t ProfilerManager::isolates_capacity_ = 0; 80 intptr_t ProfilerManager::isolates_capacity_ = 0;
79 intptr_t ProfilerManager::isolates_size_ = 0; 81 intptr_t ProfilerManager::isolates_size_ = 0;
80 82
81 83
82 void ProfilerManager::InitOnce() { 84 void ProfilerManager::InitOnce() {
83 #if defined(USING_SIMULATOR) 85 #if defined(USING_SIMULATOR)
84 // Force disable of profiling on simulator. 86 // Force disable of profiling on simulator.
85 FLAG_profile = false; 87 FLAG_profile = false;
86 #endif 88 #endif
87 if (!FLAG_profile) { 89 if (!FLAG_profile) {
88 return; 90 return;
89 } 91 }
90 NativeSymbolResolver::InitOnce(); 92 NativeSymbolResolver::InitOnce();
91 ASSERT(!initialized_); 93 ASSERT(!initialized_);
92 monitor_ = new Monitor(); 94 monitor_ = new Monitor();
95 start_stop_monitor_ = new Monitor();
93 initialized_ = true; 96 initialized_ = true;
94 ResizeIsolates(16); 97 ResizeIsolates(16);
95 Thread::Start(ThreadMain, 0); 98 if (FLAG_trace_profiled_isolates) {
99 OS::Print("ProfilerManager starting up.\n");
100 }
101 {
102 ScopedMonitor startup_lock(start_stop_monitor_);
103 Thread::Start(ThreadMain, 0);
104 while (!thread_running_) {
105 // Wait until profiler thread has started up.
106 startup_lock.Wait();
107 }
108 }
109 if (FLAG_trace_profiled_isolates) {
110 OS::Print("ProfilerManager running.\n");
111 }
96 } 112 }
97 113
98 114
99 void ProfilerManager::Shutdown() { 115 void ProfilerManager::Shutdown() {
100 if (!FLAG_profile) { 116 if (!FLAG_profile) {
101 return; 117 return;
102 } 118 }
103 ASSERT(initialized_); 119 ASSERT(initialized_);
120 if (FLAG_trace_profiled_isolates) {
121 OS::Print("ProfilerManager shutting down.\n");
122 }
123 intptr_t size_at_shutdown = 0;
104 { 124 {
105 ScopedSignalBlocker ssb; 125 ScopedSignalBlocker ssb;
106 { 126 {
107 ScopedMonitor lock(monitor_); 127 ScopedMonitor lock(monitor_);
108 shutdown_ = true; 128 shutdown_ = true;
129 size_at_shutdown = isolates_size_;
109 isolates_size_ = 0; 130 isolates_size_ = 0;
110 free(isolates_); 131 free(isolates_);
111 isolates_ = NULL; 132 isolates_ = NULL;
112 lock.Notify(); 133 lock.Notify();
113 } 134 }
114 } 135 }
115 NativeSymbolResolver::ShutdownOnce(); 136 NativeSymbolResolver::ShutdownOnce();
137 {
138 ScopedMonitor shutdown_lock(start_stop_monitor_);
139 while (thread_running_) {
140 // Wait until profiler thread has exited.
141 shutdown_lock.Wait();
142 }
143 }
144 initialized_ = false;
145 if (FLAG_trace_profiled_isolates) {
146 OS::Print("ProfilerManager shut down (%" Pd ").\n", size_at_shutdown);
147 }
116 } 148 }
117 149
118 150
119 void ProfilerManager::SetupIsolateForProfiling(Isolate* isolate) { 151 void ProfilerManager::SetupIsolateForProfiling(Isolate* isolate) {
120 if (!FLAG_profile) { 152 if (!FLAG_profile) {
121 return; 153 return;
122 } 154 }
123 ASSERT(isolate != NULL); 155 ASSERT(isolate != NULL);
124 { 156 {
125 ScopedSignalBlocker ssb; 157 ScopedSignalBlocker ssb;
126 { 158 {
127 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex()); 159 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex());
128 SampleBuffer* sample_buffer = new SampleBuffer(); 160 SampleBuffer* sample_buffer = new SampleBuffer();
129 ASSERT(sample_buffer != NULL); 161 ASSERT(sample_buffer != NULL);
130 IsolateProfilerData* profiler_data = 162 IsolateProfilerData* profiler_data =
131 new IsolateProfilerData(isolate, sample_buffer); 163 new IsolateProfilerData(isolate, sample_buffer);
132 ASSERT(profiler_data != NULL); 164 ASSERT(profiler_data != NULL);
133 profiler_data->set_sample_interval_micros(1000); 165 profiler_data->set_sample_interval_micros(1000);
134 isolate->set_profiler_data(profiler_data); 166 isolate->set_profiler_data(profiler_data);
135 if (FLAG_trace_profiled_isolates) { 167 if (FLAG_trace_profiled_isolates) {
136 OS::Print("PROF SETUP %p %s %p\n", 168 OS::Print("ProfilerManager Setup Isolate %p %s %p\n",
137 isolate, 169 isolate,
138 isolate->name(), 170 isolate->name(),
139 reinterpret_cast<void*>(Thread::GetCurrentThreadId())); 171 reinterpret_cast<void*>(Thread::GetCurrentThreadId()));
140 } 172 }
141 } 173 }
142 } 174 }
143 } 175 }
144 176
145 177
146 void ProfilerManager::FreeIsolateProfilingData(Isolate* isolate) { 178 void ProfilerManager::FreeIsolateProfilingData(Isolate* isolate) {
147 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex()); 179 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex());
148 IsolateProfilerData* profiler_data = isolate->profiler_data(); 180 IsolateProfilerData* profiler_data = isolate->profiler_data();
149 if (profiler_data == NULL) { 181 if (profiler_data == NULL) {
150 // Already freed. 182 // Already freed.
151 return; 183 return;
152 } 184 }
153 isolate->set_profiler_data(NULL); 185 isolate->set_profiler_data(NULL);
154 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); 186 SampleBuffer* sample_buffer = profiler_data->sample_buffer();
155 ASSERT(sample_buffer != NULL); 187 ASSERT(sample_buffer != NULL);
156 profiler_data->set_sample_buffer(NULL); 188 profiler_data->set_sample_buffer(NULL);
157 delete sample_buffer; 189 delete sample_buffer;
158 delete profiler_data; 190 delete profiler_data;
159 if (FLAG_trace_profiled_isolates) { 191 if (FLAG_trace_profiled_isolates) {
160 OS::Print("PROF SHUTDOWN %p %s %p\n", isolate, 192 OS::Print("ProfilerManager Shutdown Isolate %p %s %p\n",
161 isolate->name(), reinterpret_cast<void*>(Thread::GetCurrentThreadId())); 193 isolate,
194 isolate->name(),
195 reinterpret_cast<void*>(Thread::GetCurrentThreadId()));
162 } 196 }
163 } 197 }
164 198
165 199
166 void ProfilerManager::ShutdownIsolateForProfiling(Isolate* isolate) { 200 void ProfilerManager::ShutdownIsolateForProfiling(Isolate* isolate) {
167 ASSERT(isolate != NULL); 201 ASSERT(isolate != NULL);
168 if (!FLAG_profile) { 202 if (!FLAG_profile) {
169 return; 203 return;
170 } 204 }
171 { 205 {
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 return false; 687 return false;
654 } 688 }
655 uintptr_t cursor = reinterpret_cast<uintptr_t>(fp); 689 uintptr_t cursor = reinterpret_cast<uintptr_t>(fp);
656 cursor += sizeof(fp); 690 cursor += sizeof(fp);
657 bool r = cursor >= lower_bound_ && cursor < stack_upper_; 691 bool r = cursor >= lower_bound_ && cursor < stack_upper_;
658 return r; 692 return r;
659 } 693 }
660 694
661 695
662 } // namespace dart 696 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/profiler.h ('k') | runtime/vm/profiler_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698