| OLD | NEW |
| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 // Notes on stack frame walking: | 62 // Notes on stack frame walking: |
| 63 // | 63 // |
| 64 // The sampling profiler will collect up to Sample::kNumStackFrames stack frames | 64 // The sampling profiler will collect up to Sample::kNumStackFrames stack frames |
| 65 // The stack frame walking code uses the frame pointer to traverse the stack. | 65 // The stack frame walking code uses the frame pointer to traverse the stack. |
| 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, false, "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 bool ProfilerManager::thread_running_ = false; |
| 77 Monitor* ProfilerManager::monitor_ = NULL; | 77 Monitor* ProfilerManager::monitor_ = NULL; |
| 78 Monitor* ProfilerManager::start_stop_monitor_ = NULL; | 78 Monitor* ProfilerManager::start_stop_monitor_ = NULL; |
| 79 Isolate** ProfilerManager::isolates_ = NULL; | 79 Isolate** ProfilerManager::isolates_ = NULL; |
| 80 intptr_t ProfilerManager::isolates_capacity_ = 0; | 80 intptr_t ProfilerManager::isolates_capacity_ = 0; |
| 81 intptr_t ProfilerManager::isolates_size_ = 0; | 81 intptr_t ProfilerManager::isolates_size_ = 0; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 NativeSymbolResolver::ShutdownOnce(); | 136 NativeSymbolResolver::ShutdownOnce(); |
| 137 { | 137 { |
| 138 ScopedMonitor shutdown_lock(start_stop_monitor_); | 138 ScopedMonitor shutdown_lock(start_stop_monitor_); |
| 139 while (thread_running_) { | 139 while (thread_running_) { |
| 140 // Wait until profiler thread has exited. | 140 // Wait until profiler thread has exited. |
| 141 shutdown_lock.Wait(); | 141 shutdown_lock.Wait(); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 initialized_ = false; | |
| 145 if (FLAG_trace_profiled_isolates) { | 144 if (FLAG_trace_profiled_isolates) { |
| 146 OS::Print("ProfilerManager shut down (%" Pd ").\n", size_at_shutdown); | 145 OS::Print("ProfilerManager shut down (%" Pd ").\n", size_at_shutdown); |
| 147 } | 146 } |
| 148 } | 147 } |
| 149 | 148 |
| 150 | 149 |
| 151 void ProfilerManager::SetupIsolateForProfiling(Isolate* isolate) { | 150 void ProfilerManager::SetupIsolateForProfiling(Isolate* isolate) { |
| 152 if (!FLAG_profile) { | 151 if (!FLAG_profile) { |
| 153 return; | 152 return; |
| 154 } | 153 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 { | 204 { |
| 206 ScopedSignalBlocker ssb; | 205 ScopedSignalBlocker ssb; |
| 207 FreeIsolateProfilingData(isolate); | 206 FreeIsolateProfilingData(isolate); |
| 208 } | 207 } |
| 209 } | 208 } |
| 210 | 209 |
| 211 | 210 |
| 212 void ProfilerManager::ScheduleIsolateHelper(Isolate* isolate) { | 211 void ProfilerManager::ScheduleIsolateHelper(Isolate* isolate) { |
| 213 ScopedMonitor lock(monitor_); | 212 ScopedMonitor lock(monitor_); |
| 214 { | 213 { |
| 214 if (shutdown_) { |
| 215 // Shutdown. |
| 216 return; |
| 217 } |
| 215 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex()); | 218 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex()); |
| 216 IsolateProfilerData* profiler_data = isolate->profiler_data(); | 219 IsolateProfilerData* profiler_data = isolate->profiler_data(); |
| 217 if (profiler_data == NULL) { | 220 if (profiler_data == NULL) { |
| 218 return; | 221 return; |
| 219 } | 222 } |
| 220 profiler_data->Scheduled(OS::GetCurrentTimeMicros(), | 223 profiler_data->Scheduled(OS::GetCurrentTimeMicros(), |
| 221 Thread::GetCurrentThreadId()); | 224 Thread::GetCurrentThreadId()); |
| 222 } | 225 } |
| 223 intptr_t i = FindIsolate(isolate); | 226 intptr_t i = FindIsolate(isolate); |
| 224 if (i >= 0) { | 227 if (i >= 0) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 253 void ProfilerManager::DescheduleIsolate(Isolate* isolate) { | 256 void ProfilerManager::DescheduleIsolate(Isolate* isolate) { |
| 254 if (!FLAG_profile) { | 257 if (!FLAG_profile) { |
| 255 return; | 258 return; |
| 256 } | 259 } |
| 257 ASSERT(initialized_); | 260 ASSERT(initialized_); |
| 258 ASSERT(isolate != NULL); | 261 ASSERT(isolate != NULL); |
| 259 { | 262 { |
| 260 ScopedSignalBlocker ssb; | 263 ScopedSignalBlocker ssb; |
| 261 { | 264 { |
| 262 ScopedMonitor lock(monitor_); | 265 ScopedMonitor lock(monitor_); |
| 266 if (shutdown_) { |
| 267 // Shutdown. |
| 268 return; |
| 269 } |
| 263 intptr_t i = FindIsolate(isolate); | 270 intptr_t i = FindIsolate(isolate); |
| 264 if (i < 0) { | 271 if (i < 0) { |
| 265 // Not scheduled. | 272 // Not scheduled. |
| 266 return; | 273 return; |
| 267 } | 274 } |
| 268 { | 275 { |
| 269 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex()); | 276 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex()); |
| 270 IsolateProfilerData* profiler_data = isolate->profiler_data(); | 277 IsolateProfilerData* profiler_data = isolate->profiler_data(); |
| 271 if (profiler_data != NULL) { | 278 if (profiler_data != NULL) { |
| 272 profiler_data->Descheduled(); | 279 profiler_data->Descheduled(); |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 return false; | 694 return false; |
| 688 } | 695 } |
| 689 uintptr_t cursor = reinterpret_cast<uintptr_t>(fp); | 696 uintptr_t cursor = reinterpret_cast<uintptr_t>(fp); |
| 690 cursor += sizeof(fp); | 697 cursor += sizeof(fp); |
| 691 bool r = cursor >= lower_bound_ && cursor < stack_upper_; | 698 bool r = cursor >= lower_bound_ && cursor < stack_upper_; |
| 692 return r; | 699 return r; |
| 693 } | 700 } |
| 694 | 701 |
| 695 | 702 |
| 696 } // namespace dart | 703 } // namespace dart |
| OLD | NEW |