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

Side by Side Diff: runtime/vm/profiler_android.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, 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 | 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_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
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 13 matching lines...) Expand all
24 return; 24 return;
25 } 25 }
26 // Thread owns no profiler locks at this point. 26 // Thread owns no profiler locks at this point.
27 { 27 {
28 // Thread owns isolate profiler data mutex. 28 // Thread owns isolate profiler data mutex.
29 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex()); 29 ScopedMutex profiler_data_lock(isolate->profiler_data_mutex());
30 IsolateProfilerData* profiler_data = isolate->profiler_data(); 30 IsolateProfilerData* profiler_data = isolate->profiler_data();
31 if (profiler_data == NULL) { 31 if (profiler_data == NULL) {
32 return; 32 return;
33 } 33 }
34 if (!profiler_data->CanExpire()) {
35 // Descheduled.
36 return;
37 }
34 } 38 }
35 // Thread owns no profiler locks at this point. 39 // Thread owns no profiler locks at this point.
36 // This call will acquire both ProfilerManager::monitor and the 40 // This call will acquire both ProfilerManager::monitor and the
37 // isolate's profiler data mutex. 41 // isolate's profiler data mutex.
38 ProfilerManager::ScheduleIsolate(isolate); 42 ProfilerManager::ScheduleIsolate(isolate, true);
39 } 43 }
40 44
41 45
42 int64_t ProfilerManager::SampleAndRescheduleIsolates(int64_t current_time) { 46 int64_t ProfilerManager::SampleAndRescheduleIsolates(int64_t current_time) {
43 if (isolates_size_ == 0) { 47 if (isolates_size_ == 0) {
44 return 0; 48 return 0;
45 } 49 }
46 static const int64_t max_time = 0x7fffffffffffffffLL; 50 static const int64_t max_time = 0x7fffffffffffffffLL;
47 int64_t lowest = max_time; 51 int64_t lowest = max_time;
48 intptr_t i = 0; 52 intptr_t i = 0;
49 while (i < isolates_size_) { 53 while (i < isolates_size_) {
50 Isolate* isolate = isolates_[i]; 54 Isolate* isolate = isolates_[i];
51 ScopedMutex isolate_lock(isolate->profiler_data_mutex()); 55 ScopedMutex isolate_lock(isolate->profiler_data_mutex());
52 IsolateProfilerData* profiler_data = isolate->profiler_data(); 56 IsolateProfilerData* profiler_data = isolate->profiler_data();
57 if (profiler_data == NULL) {
58 // Isolate has been shutdown for profiling.
59 RemoveIsolate(i);
60 // Remove moves the last element into i, do not increment i.
61 continue;
62 }
53 ASSERT(profiler_data != NULL); 63 ASSERT(profiler_data != NULL);
54 if (profiler_data->ShouldSample(current_time)) { 64 if (profiler_data->ShouldSample(current_time)) {
55 pthread_kill(profiler_data->thread_id(), SIGPROF); 65 pthread_kill(profiler_data->thread_id(), SIGPROF);
56 RemoveIsolate(i); 66 RemoveIsolate(i);
57 // Remove moves the last element into i, do not increment i. 67 // Remove moves the last element into i, do not increment i.
58 continue; 68 continue;
59 } 69 }
60 if (profiler_data->CanExpire()) { 70 if (profiler_data->CanExpire()) {
61 int64_t isolate_time_left = 71 int64_t isolate_time_left =
62 profiler_data->TimeUntilExpiration(current_time); 72 profiler_data->TimeUntilExpiration(current_time);
(...skipping 27 matching lines...) Expand all
90 int64_t current_time = OS::GetCurrentTimeMicros(); 100 int64_t current_time = OS::GetCurrentTimeMicros();
91 int64_t next_sample = SampleAndRescheduleIsolates(current_time); 101 int64_t next_sample = SampleAndRescheduleIsolates(current_time);
92 lock.WaitMicros(next_sample); 102 lock.WaitMicros(next_sample);
93 } 103 }
94 } 104 }
95 105
96 106
97 } // namespace dart 107 } // namespace dart
98 108
99 #endif // defined(TARGET_OS_ANDROID) 109 #endif // defined(TARGET_OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698