Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/source_report.h" | 5 #include "vm/source_report.h" |
| 6 | 6 |
| 7 #include "vm/compiler.h" | 7 #include "vm/compiler.h" |
| 8 #include "vm/isolate.h" | |
| 8 #include "vm/object.h" | 9 #include "vm/object.h" |
| 9 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| 11 #include "vm/profiler.h" | |
| 12 #include "vm/profiler_service.h" | |
| 10 | 13 |
| 11 namespace dart { | 14 namespace dart { |
| 12 | 15 |
| 13 SourceReport::SourceReport(intptr_t report_set, CompileMode compile_mode) | 16 SourceReport::SourceReport(intptr_t report_set, CompileMode compile_mode) |
| 14 : report_set_(report_set), | 17 : report_set_(report_set), |
| 15 compile_mode_(compile_mode), | 18 compile_mode_(compile_mode), |
| 16 thread_(NULL), | 19 thread_(NULL), |
| 17 script_(NULL), | 20 script_(NULL), |
| 18 start_pos_(TokenPosition::kNoSource), | 21 start_pos_(TokenPosition::kNoSource), |
| 19 end_pos_(TokenPosition::kNoSource), | 22 end_pos_(TokenPosition::kNoSource), |
| 23 profile_(Isolate::Current()), | |
| 20 next_script_index_(0) { | 24 next_script_index_(0) { |
| 21 } | 25 } |
| 22 | 26 |
| 23 | 27 |
| 24 void SourceReport::Init(Thread* thread, | 28 void SourceReport::Init(Thread* thread, |
| 25 const Script* script, | 29 const Script* script, |
| 26 TokenPosition start_pos, | 30 TokenPosition start_pos, |
| 27 TokenPosition end_pos) { | 31 TokenPosition end_pos) { |
| 28 thread_ = thread; | 32 thread_ = thread; |
| 29 script_ = script; | 33 script_ = script; |
| 30 start_pos_ = start_pos; | 34 start_pos_ = start_pos; |
| 31 end_pos_ = end_pos; | 35 end_pos_ = end_pos; |
| 32 script_table_entries_.Clear(); | 36 script_table_entries_.Clear(); |
| 33 script_table_.Clear(); | 37 script_table_.Clear(); |
| 34 next_script_index_ = 0; | 38 next_script_index_ = 0; |
| 39 if (IsReportRequested(kProfile)) { | |
| 40 SampleFilter samplesForIsolate(Isolate::Current(), -1, -1); | |
|
turnidge
2016/03/11 18:31:57
Is thread_ the current thread? If so, can we use
Cutch
2016/03/11 20:20:00
Done.
| |
| 41 // Build the profile. | |
| 42 profile_.Build(thread, &samplesForIsolate, Profile::kNoTags); | |
| 43 } | |
| 35 } | 44 } |
| 36 | 45 |
| 37 | 46 |
| 38 bool SourceReport::IsReportRequested(ReportKind report_kind) { | 47 bool SourceReport::IsReportRequested(ReportKind report_kind) { |
| 39 return (report_set_ & report_kind) != 0; | 48 return (report_set_ & report_kind) != 0; |
| 40 } | 49 } |
| 41 | 50 |
| 42 | 51 |
| 43 bool SourceReport::ShouldSkipFunction(const Function& func) { | 52 bool SourceReport::ShouldSkipFunction(const Function& func) { |
| 44 if (script_ != NULL && !script_->IsNull()) { | 53 if (script_ != NULL && !script_->IsNull()) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 JSONArray bpts(jsobj, "possibleBreakpoints"); | 252 JSONArray bpts(jsobj, "possibleBreakpoints"); |
| 244 for (int i = 0; i < func_length; i++) { | 253 for (int i = 0; i < func_length; i++) { |
| 245 if (possible[i]) { | 254 if (possible[i]) { |
| 246 // Add the token position. | 255 // Add the token position. |
| 247 bpts.AddValue(begin_pos.Pos() + i); | 256 bpts.AddValue(begin_pos.Pos() + i); |
| 248 } | 257 } |
| 249 } | 258 } |
| 250 } | 259 } |
| 251 | 260 |
| 252 | 261 |
| 262 void SourceReport::PrintProfileData(JSONObject* jsobj, | |
| 263 ProfileFunction* profile_function) { | |
| 264 ASSERT(profile_function != NULL); | |
| 265 ASSERT(profile_function->NumSourcePositions() > 0); | |
| 266 | |
| 267 { | |
| 268 JSONObject profile(jsobj, "profileTicks"); | |
| 269 | |
| 270 // Positions. | |
| 271 { | |
| 272 JSONArray positions(&profile, "positions"); | |
| 273 for (intptr_t i = 0; i < profile_function->NumSourcePositions(); i++) { | |
| 274 const ProfileFunctionSourcePosition& position = | |
| 275 profile_function->GetSourcePosition(i); | |
| 276 if (position.token_pos().IsSourcePosition() && | |
| 277 !position.token_pos().IsNoSource()) { | |
| 278 // Add as an integer. | |
| 279 positions.AddValue(position.token_pos().Pos()); | |
| 280 } else { | |
| 281 // Add as a string. | |
| 282 positions.AddValue(position.token_pos().ToCString()); | |
| 283 } | |
| 284 } | |
| 285 } | |
| 286 | |
| 287 // Exclusive ticks. | |
| 288 { | |
| 289 JSONArray exclusiveTicks(&profile, "exclusiveTicks"); | |
| 290 for (intptr_t i = 0; i < profile_function->NumSourcePositions(); i++) { | |
| 291 const ProfileFunctionSourcePosition& position = | |
| 292 profile_function->GetSourcePosition(i); | |
| 293 exclusiveTicks.AddValue(position.exclusive_ticks()); | |
| 294 } | |
| 295 } | |
| 296 // Inclusive ticks. | |
| 297 { | |
| 298 JSONArray inclusiveTicks(&profile, "inclusiveTicks"); | |
| 299 for (intptr_t i = 0; i < profile_function->NumSourcePositions(); i++) { | |
| 300 const ProfileFunctionSourcePosition& position = | |
| 301 profile_function->GetSourcePosition(i); | |
| 302 inclusiveTicks.AddValue(position.inclusive_ticks()); | |
| 303 } | |
| 304 } | |
| 305 } | |
| 306 } | |
| 307 | |
| 308 | |
| 253 void SourceReport::PrintScriptTable(JSONArray* scripts) { | 309 void SourceReport::PrintScriptTable(JSONArray* scripts) { |
| 254 for (int i = 0; i < script_table_entries_.length(); i++) { | 310 for (int i = 0; i < script_table_entries_.length(); i++) { |
| 255 const Script* script = script_table_entries_[i].script; | 311 const Script* script = script_table_entries_[i].script; |
| 256 scripts->AddValue(*script); | 312 scripts->AddValue(*script); |
| 257 } | 313 } |
| 258 } | 314 } |
| 259 | 315 |
| 260 | 316 |
| 261 void SourceReport::VisitFunction(JSONArray* jsarr, const Function& func) { | 317 void SourceReport::VisitFunction(JSONArray* jsarr, const Function& func) { |
| 262 if (ShouldSkipFunction(func)) { | 318 if (ShouldSkipFunction(func)) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 | 360 |
| 305 if (IsReportRequested(kCallSites)) { | 361 if (IsReportRequested(kCallSites)) { |
| 306 PrintCallSitesData(&range, func, code); | 362 PrintCallSitesData(&range, func, code); |
| 307 } | 363 } |
| 308 if (IsReportRequested(kCoverage)) { | 364 if (IsReportRequested(kCoverage)) { |
| 309 PrintCoverageData(&range, func, code); | 365 PrintCoverageData(&range, func, code); |
| 310 } | 366 } |
| 311 if (IsReportRequested(kPossibleBreakpoints)) { | 367 if (IsReportRequested(kPossibleBreakpoints)) { |
| 312 PrintPossibleBreakpointsData(&range, func, code); | 368 PrintPossibleBreakpointsData(&range, func, code); |
| 313 } | 369 } |
| 370 if (IsReportRequested(kProfile)) { | |
| 371 ProfileFunction* profile_function = profile_.FindFunction(func); | |
| 372 if ((profile_function != NULL) && | |
| 373 (profile_function->NumSourcePositions() > 0)) { | |
| 374 PrintProfileData(&range, profile_function); | |
| 375 } | |
| 376 } | |
| 314 } | 377 } |
| 315 | 378 |
| 316 | 379 |
| 317 void SourceReport::VisitLibrary(JSONArray* jsarr, const Library& lib) { | 380 void SourceReport::VisitLibrary(JSONArray* jsarr, const Library& lib) { |
| 318 Class& cls = Class::Handle(zone()); | 381 Class& cls = Class::Handle(zone()); |
| 319 Array& functions = Array::Handle(zone()); | 382 Array& functions = Array::Handle(zone()); |
| 320 Function& func = Function::Handle(zone()); | 383 Function& func = Function::Handle(zone()); |
| 321 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); | 384 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); |
| 322 while (it.HasNext()) { | 385 while (it.HasNext()) { |
| 323 cls = it.GetNextClass(); | 386 cls = it.GetNextClass(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 VisitClosures(&ranges); | 434 VisitClosures(&ranges); |
| 372 } | 435 } |
| 373 | 436 |
| 374 // Print the script table. | 437 // Print the script table. |
| 375 JSONArray scripts(&report, "scripts"); | 438 JSONArray scripts(&report, "scripts"); |
| 376 PrintScriptTable(&scripts); | 439 PrintScriptTable(&scripts); |
| 377 } | 440 } |
| 378 | 441 |
| 379 | 442 |
| 380 } // namespace dart | 443 } // namespace dart |
| OLD | NEW |