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

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

Issue 1412733008: Switch profiler from isolates to threads (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
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/profiler_service.h" 5 #include "vm/profiler_service.h"
6 6
7 #include "vm/growable_array.h" 7 #include "vm/growable_array.h"
8 #include "vm/native_symbol.h" 8 #include "vm/native_symbol.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/os.h" 10 #include "vm/os.h"
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 RegisterProfileCodeTag(VMTag::kNoneCodeTagId); 1044 RegisterProfileCodeTag(VMTag::kNoneCodeTagId);
1045 RegisterProfileCodeTag(VMTag::kOptimizedCodeTagId); 1045 RegisterProfileCodeTag(VMTag::kOptimizedCodeTagId);
1046 RegisterProfileCodeTag(VMTag::kUnoptimizedCodeTagId); 1046 RegisterProfileCodeTag(VMTag::kUnoptimizedCodeTagId);
1047 RegisterProfileCodeTag(VMTag::kNativeCodeTagId); 1047 RegisterProfileCodeTag(VMTag::kNativeCodeTagId);
1048 RegisterProfileCodeTag(VMTag::kInlineStartCodeTagId); 1048 RegisterProfileCodeTag(VMTag::kInlineStartCodeTagId);
1049 RegisterProfileCodeTag(VMTag::kInlineEndCodeTagId); 1049 RegisterProfileCodeTag(VMTag::kInlineEndCodeTagId);
1050 } 1050 }
1051 1051
1052 void FilterSamples() { 1052 void FilterSamples() {
1053 ScopeTimer sw("ProfileBuilder::FilterSamples", FLAG_trace_profiler); 1053 ScopeTimer sw("ProfileBuilder::FilterSamples", FLAG_trace_profiler);
1054 Isolate* isolate = thread_->isolate(); 1054 SampleBuffer* sample_buffer = Profiler::sample_buffer();
1055 MutexLocker profiler_data_lock(isolate->profiler_data_mutex());
1056 IsolateProfilerData* profiler_data = isolate->profiler_data();
1057 if (profiler_data == NULL) {
1058 return;
1059 }
1060 SampleBuffer* sample_buffer = profiler_data->sample_buffer();
1061 if (sample_buffer == NULL) { 1055 if (sample_buffer == NULL) {
1062 return; 1056 return;
1063 } 1057 }
1064 samples_ = sample_buffer->BuildProcessedSampleBuffer(filter_); 1058 samples_ = sample_buffer->BuildProcessedSampleBuffer(filter_);
1065 profile_->sample_count_ = samples_->length(); 1059 profile_->sample_count_ = samples_->length();
1066 } 1060 }
1067 1061
1068 void UpdateMinMaxTimes(int64_t timestamp) { 1062 void UpdateMinMaxTimes(int64_t timestamp) {
1069 profile_->min_time_ = 1063 profile_->min_time_ =
1070 timestamp < profile_->min_time_ ? timestamp : profile_->min_time_; 1064 timestamp < profile_->min_time_ ? timestamp : profile_->min_time_;
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2195 return parent_->NumChildren(); 2189 return parent_->NumChildren();
2196 } 2190 }
2197 2191
2198 2192
2199 void ProfilerService::PrintJSONImpl(Thread* thread, 2193 void ProfilerService::PrintJSONImpl(Thread* thread,
2200 JSONStream* stream, 2194 JSONStream* stream,
2201 Profile::TagOrder tag_order, 2195 Profile::TagOrder tag_order,
2202 intptr_t extra_tags, 2196 intptr_t extra_tags,
2203 SampleFilter* filter) { 2197 SampleFilter* filter) {
2204 Isolate* isolate = thread->isolate(); 2198 Isolate* isolate = thread->isolate();
2205 // Disable profile interrupts while processing the buffer. 2199 // Disable thread interrupts while processing the buffer.
2206 Profiler::EndExecution(isolate); 2200 thread->DisableThreadInterrupts();
Ivan Posva 2015/10/28 19:31:53 Should we have a DisableInterruptsScope?
Cutch 2015/10/28 19:50:33 Done here and below.
2207 2201
2208 { 2202 SampleBuffer* sample_buffer = Profiler::sample_buffer();
2209 MutexLocker profiler_data_lock(isolate->profiler_data_mutex()); 2203 if (sample_buffer == NULL) {
2210 IsolateProfilerData* profiler_data = isolate->profiler_data(); 2204 stream->PrintError(kFeatureDisabled, NULL);
2211 if (profiler_data == NULL) { 2205 return;
2212 stream->PrintError(kFeatureDisabled, NULL);
2213 return;
2214 }
2215 } 2206 }
2216 2207
2217 { 2208 {
2218 StackZone zone(thread); 2209 StackZone zone(thread);
2219 HANDLESCOPE(thread); 2210 HANDLESCOPE(thread);
2220 Profile profile(isolate); 2211 Profile profile(isolate);
2221 profile.Build(thread, filter, tag_order, extra_tags); 2212 profile.Build(thread, filter, tag_order, extra_tags);
2222 profile.PrintJSON(stream); 2213 profile.PrintJSON(stream);
2223 } 2214 }
2224 2215
2225 // Enable profile interrupts. 2216 // Re-enable.
2226 Profiler::BeginExecution(isolate); 2217 thread->EnableThreadInterrupts();
2227 } 2218 }
2228 2219
2229 2220
2230 class NoAllocationSampleFilter : public SampleFilter { 2221 class NoAllocationSampleFilter : public SampleFilter {
2231 public: 2222 public:
2232 explicit NoAllocationSampleFilter(Isolate* isolate) 2223 explicit NoAllocationSampleFilter(Isolate* isolate)
2233 : SampleFilter(isolate) { 2224 : SampleFilter(isolate) {
2234 } 2225 }
2235 2226
2236 bool FilterSample(Sample* sample) { 2227 bool FilterSample(Sample* sample) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2271 Profile::TagOrder tag_order, 2262 Profile::TagOrder tag_order,
2272 const Class& cls) { 2263 const Class& cls) {
2273 Thread* thread = Thread::Current(); 2264 Thread* thread = Thread::Current();
2274 Isolate* isolate = thread->isolate(); 2265 Isolate* isolate = thread->isolate();
2275 ClassAllocationSampleFilter filter(isolate, cls); 2266 ClassAllocationSampleFilter filter(isolate, cls);
2276 PrintJSONImpl(thread, stream, tag_order, kNoExtraTags, &filter); 2267 PrintJSONImpl(thread, stream, tag_order, kNoExtraTags, &filter);
2277 } 2268 }
2278 2269
2279 2270
2280 void ProfilerService::ClearSamples() { 2271 void ProfilerService::ClearSamples() {
2281 Isolate* isolate = Isolate::Current(); 2272 SampleBuffer* sample_buffer = Profiler::sample_buffer();
2282 2273 if (sample_buffer == NULL) {
2283 // Disable profile interrupts while processing the buffer.
2284 Profiler::EndExecution(isolate);
2285
2286 MutexLocker profiler_data_lock(isolate->profiler_data_mutex());
2287 IsolateProfilerData* profiler_data = isolate->profiler_data();
2288 if (profiler_data == NULL) {
2289 return; 2274 return;
2290 } 2275 }
2291 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); 2276
2292 ASSERT(sample_buffer != NULL); 2277 Thread* thread = Thread::Current();
2278 Isolate* isolate = thread->isolate();
2279
2280 // Disable thread interrupts while processing the buffer.
2281 thread->DisableThreadInterrupts();
2293 2282
2294 ClearProfileVisitor clear_profile(isolate); 2283 ClearProfileVisitor clear_profile(isolate);
2295 sample_buffer->VisitSamples(&clear_profile); 2284 sample_buffer->VisitSamples(&clear_profile);
2296 2285
2297 // Enable profile interrupts. 2286 // Re-enable.
2298 Profiler::BeginExecution(isolate); 2287 thread->EnableThreadInterrupts();
2299 } 2288 }
2300 2289
2301 } // namespace dart 2290 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698