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

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

Issue 83093004: Fix shutdown races and move signal blocking into profiler (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
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 "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
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/profiler.h" 10 #include "vm/profiler.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 return; 48 return;
49 } 49 }
50 // Thread owns no profiler locks at this point. 50 // Thread owns no profiler locks at this point.
51 { 51 {
52 // Thread owns isolate profiler data mutex. 52 // Thread owns isolate profiler data mutex.
53 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex()); 53 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex());
54 IsolateProfilerData* profiler_data = isolate->profiler_data(); 54 IsolateProfilerData* profiler_data = isolate->profiler_data();
55 if (profiler_data == NULL) { 55 if (profiler_data == NULL) {
56 return; 56 return;
57 } 57 }
58 if (!profiler_data->CanExpire()) {
59 // Descheduled.
60 return;
61 }
58 62
59 uintptr_t stack_lower = 0; 63 uintptr_t stack_lower = 0;
60 uintptr_t stack_upper = 0; 64 uintptr_t stack_upper = 0;
61 isolate->GetStackBounds(&stack_lower, &stack_upper); 65 isolate->GetStackBounds(&stack_lower, &stack_upper);
62 uintptr_t PC = SignalHandler::GetProgramCounter(mcontext); 66 uintptr_t PC = SignalHandler::GetProgramCounter(mcontext);
63 uintptr_t FP = SignalHandler::GetFramePointer(mcontext); 67 uintptr_t FP = SignalHandler::GetFramePointer(mcontext);
64 uintptr_t SP = SignalHandler::GetStackPointer(mcontext); 68 uintptr_t SP = SignalHandler::GetStackPointer(mcontext);
65 int64_t sample_time = OS::GetCurrentTimeMicros(); 69 int64_t sample_time = OS::GetCurrentTimeMicros();
66 profiler_data->SampledAt(sample_time); 70 profiler_data->SampledAt(sample_time);
67 CollectSample(profiler_data, PC, FP, SP, stack_lower, stack_upper); 71 CollectSample(profiler_data, PC, FP, SP, stack_lower, stack_upper);
68 } 72 }
69 // Thread owns no profiler locks at this point. 73 // Thread owns no profiler locks at this point.
70 // This call will acquire both ProfilerManager::monitor and the 74 // This call will acquire both ProfilerManager::monitor and the
71 // isolate's profiler data mutex. 75 // isolate's profiler data mutex.
72 ProfilerManager::ScheduleIsolate(isolate); 76 ProfilerManager::ScheduleIsolate(isolate, true);
73 } 77 }
74 78
75 79
76 int64_t ProfilerManager::SampleAndRescheduleIsolates(int64_t current_time) { 80 int64_t ProfilerManager::SampleAndRescheduleIsolates(int64_t current_time) {
77 if (isolates_size_ == 0) { 81 if (isolates_size_ == 0) {
78 return 0; 82 return 0;
79 } 83 }
80 static const int64_t max_time = 0x7fffffffffffffffLL; 84 static const int64_t max_time = 0x7fffffffffffffffLL;
81 int64_t lowest = max_time; 85 int64_t lowest = max_time;
82 intptr_t i = 0; 86 intptr_t i = 0;
83 while (i < isolates_size_) { 87 while (i < isolates_size_) {
84 Isolate* isolate = isolates_[i]; 88 Isolate* isolate = isolates_[i];
85 ScopedMutex isolate_lock(isolate->profiler_data_mutex()); 89 ScopedMutex isolate_lock(isolate->profiler_data_mutex());
86 IsolateProfilerData* profiler_data = isolate->profiler_data(); 90 IsolateProfilerData* profiler_data = isolate->profiler_data();
91 if (profiler_data == NULL) {
92 // Isolate has been shutdown for profiling.
93 RemoveIsolate(i);
94 // Remove moves the last element into i, do not increment i.
95 continue;
96 }
87 ASSERT(profiler_data != NULL); 97 ASSERT(profiler_data != NULL);
88 if (profiler_data->ShouldSample(current_time)) { 98 if (profiler_data->ShouldSample(current_time)) {
89 pthread_kill(profiler_data->thread_id(), SIGPROF); 99 pthread_kill(profiler_data->thread_id(), SIGPROF);
90 RemoveIsolate(i); 100 RemoveIsolate(i);
91 // Remove moves the last element into i, do not increment i. 101 // Remove moves the last element into i, do not increment i.
92 continue; 102 continue;
93 } 103 }
94 if (profiler_data->CanExpire()) { 104 if (profiler_data->CanExpire()) {
95 int64_t isolate_time_left = 105 int64_t isolate_time_left =
96 profiler_data->TimeUntilExpiration(current_time); 106 profiler_data->TimeUntilExpiration(current_time);
(...skipping 27 matching lines...) Expand all
124 int64_t current_time = OS::GetCurrentTimeMicros(); 134 int64_t current_time = OS::GetCurrentTimeMicros();
125 int64_t next_sample = SampleAndRescheduleIsolates(current_time); 135 int64_t next_sample = SampleAndRescheduleIsolates(current_time);
126 lock.WaitMicros(next_sample); 136 lock.WaitMicros(next_sample);
127 } 137 }
128 } 138 }
129 139
130 140
131 } // namespace dart 141 } // namespace dart
132 142
133 #endif // defined(TARGET_OS_LINUX) 143 #endif // defined(TARGET_OS_LINUX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698