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

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

Issue 1310463005: - Ensure that HandleScope is initialized with a thread. (Remove (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months 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 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2187 return true; 2187 return true;
2188 } 2188 }
2189 2189
2190 2190
2191 intptr_t ProfileTrieWalker::SiblingCount() { 2191 intptr_t ProfileTrieWalker::SiblingCount() {
2192 ASSERT(parent_ != NULL); 2192 ASSERT(parent_ != NULL);
2193 return parent_->NumChildren(); 2193 return parent_->NumChildren();
2194 } 2194 }
2195 2195
2196 2196
2197 void ProfilerService::PrintJSONImpl(Isolate* isolate, 2197 void ProfilerService::PrintJSONImpl(Thread* thread,
2198 JSONStream* stream, 2198 JSONStream* stream,
2199 Profile::TagOrder tag_order, 2199 Profile::TagOrder tag_order,
2200 intptr_t extra_tags, 2200 intptr_t extra_tags,
2201 SampleFilter* filter) { 2201 SampleFilter* filter) {
2202 Isolate* isolate = thread->isolate();
2202 // Disable profile interrupts while processing the buffer. 2203 // Disable profile interrupts while processing the buffer.
2203 Profiler::EndExecution(isolate); 2204 Profiler::EndExecution(isolate);
2204 2205
2205 { 2206 {
2206 MutexLocker profiler_data_lock(isolate->profiler_data_mutex()); 2207 MutexLocker profiler_data_lock(isolate->profiler_data_mutex());
2207 IsolateProfilerData* profiler_data = isolate->profiler_data(); 2208 IsolateProfilerData* profiler_data = isolate->profiler_data();
2208 if (profiler_data == NULL) { 2209 if (profiler_data == NULL) {
2209 stream->PrintError(kFeatureDisabled, NULL); 2210 stream->PrintError(kFeatureDisabled, NULL);
2210 return; 2211 return;
2211 } 2212 }
2212 } 2213 }
2213 2214
2214 { 2215 {
2215 StackZone zone(isolate); 2216 StackZone zone(isolate);
2216 HANDLESCOPE(isolate); 2217 HANDLESCOPE(thread);
2217 Profile profile(isolate); 2218 Profile profile(isolate);
2218 profile.Build(filter, tag_order, extra_tags); 2219 profile.Build(filter, tag_order, extra_tags);
2219 profile.PrintJSON(stream); 2220 profile.PrintJSON(stream);
2220 } 2221 }
2221 2222
2222 // Enable profile interrupts. 2223 // Enable profile interrupts.
2223 Profiler::BeginExecution(isolate); 2224 Profiler::BeginExecution(isolate);
2224 } 2225 }
2225 2226
2226 2227
2227 class NoAllocationSampleFilter : public SampleFilter { 2228 class NoAllocationSampleFilter : public SampleFilter {
2228 public: 2229 public:
2229 explicit NoAllocationSampleFilter(Isolate* isolate) 2230 explicit NoAllocationSampleFilter(Isolate* isolate)
2230 : SampleFilter(isolate) { 2231 : SampleFilter(isolate) {
2231 } 2232 }
2232 2233
2233 bool FilterSample(Sample* sample) { 2234 bool FilterSample(Sample* sample) {
2234 return !sample->is_allocation_sample(); 2235 return !sample->is_allocation_sample();
2235 } 2236 }
2236 }; 2237 };
2237 2238
2238 2239
2239 void ProfilerService::PrintJSON(JSONStream* stream, 2240 void ProfilerService::PrintJSON(JSONStream* stream,
2240 Profile::TagOrder tag_order, 2241 Profile::TagOrder tag_order,
2241 intptr_t extra_tags) { 2242 intptr_t extra_tags) {
2242 Isolate* isolate = Isolate::Current(); 2243 Thread* thread = Thread::Current();
2244 Isolate* isolate = thread->isolate();
2243 NoAllocationSampleFilter filter(isolate); 2245 NoAllocationSampleFilter filter(isolate);
2244 PrintJSONImpl(isolate, stream, tag_order, extra_tags, &filter); 2246 PrintJSONImpl(thread, stream, tag_order, extra_tags, &filter);
2245 } 2247 }
2246 2248
2247 2249
2248 class ClassAllocationSampleFilter : public SampleFilter { 2250 class ClassAllocationSampleFilter : public SampleFilter {
2249 public: 2251 public:
2250 ClassAllocationSampleFilter(Isolate* isolate, const Class& cls) 2252 ClassAllocationSampleFilter(Isolate* isolate, const Class& cls)
2251 : SampleFilter(isolate), 2253 : SampleFilter(isolate),
2252 cls_(Class::Handle(cls.raw())) { 2254 cls_(Class::Handle(cls.raw())) {
2253 ASSERT(!cls_.IsNull()); 2255 ASSERT(!cls_.IsNull());
2254 } 2256 }
2255 2257
2256 bool FilterSample(Sample* sample) { 2258 bool FilterSample(Sample* sample) {
2257 return sample->is_allocation_sample() && 2259 return sample->is_allocation_sample() &&
2258 (sample->allocation_cid() == cls_.id()); 2260 (sample->allocation_cid() == cls_.id());
2259 } 2261 }
2260 2262
2261 private: 2263 private:
2262 const Class& cls_; 2264 const Class& cls_;
2263 }; 2265 };
2264 2266
2265 2267
2266 void ProfilerService::PrintAllocationJSON(JSONStream* stream, 2268 void ProfilerService::PrintAllocationJSON(JSONStream* stream,
2267 Profile::TagOrder tag_order, 2269 Profile::TagOrder tag_order,
2268 const Class& cls) { 2270 const Class& cls) {
2269 Isolate* isolate = Isolate::Current(); 2271 Thread* thread = Thread::Current();
2272 Isolate* isolate = thread->isolate();
2270 ClassAllocationSampleFilter filter(isolate, cls); 2273 ClassAllocationSampleFilter filter(isolate, cls);
2271 PrintJSONImpl(isolate, stream, tag_order, kNoExtraTags, &filter); 2274 PrintJSONImpl(thread, stream, tag_order, kNoExtraTags, &filter);
2272 } 2275 }
2273 2276
2274 2277
2275 void ProfilerService::ClearSamples() { 2278 void ProfilerService::ClearSamples() {
2276 Isolate* isolate = Isolate::Current(); 2279 Isolate* isolate = Isolate::Current();
2277 2280
2278 // Disable profile interrupts while processing the buffer. 2281 // Disable profile interrupts while processing the buffer.
2279 Profiler::EndExecution(isolate); 2282 Profiler::EndExecution(isolate);
2280 2283
2281 MutexLocker profiler_data_lock(isolate->profiler_data_mutex()); 2284 MutexLocker profiler_data_lock(isolate->profiler_data_mutex());
2282 IsolateProfilerData* profiler_data = isolate->profiler_data(); 2285 IsolateProfilerData* profiler_data = isolate->profiler_data();
2283 if (profiler_data == NULL) { 2286 if (profiler_data == NULL) {
2284 return; 2287 return;
2285 } 2288 }
2286 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); 2289 SampleBuffer* sample_buffer = profiler_data->sample_buffer();
2287 ASSERT(sample_buffer != NULL); 2290 ASSERT(sample_buffer != NULL);
2288 2291
2289 ClearProfileVisitor clear_profile(isolate); 2292 ClearProfileVisitor clear_profile(isolate);
2290 sample_buffer->VisitSamples(&clear_profile); 2293 sample_buffer->VisitSamples(&clear_profile);
2291 2294
2292 // Enable profile interrupts. 2295 // Enable profile interrupts.
2293 Profiler::BeginExecution(isolate); 2296 Profiler::BeginExecution(isolate);
2294 } 2297 }
2295 2298
2296 } // namespace dart 2299 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698