| 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 |
| 16 const char* SourceReport::kCallSitesStr = "_CallSites"; |
| 17 const char* SourceReport::kCoverageStr = "Coverage"; |
| 18 const char* SourceReport::kPossibleBreakpointsStr = "PossibleBreakpoints"; |
| 19 const char* SourceReport::kProfileStr = "_Profile"; |
| 20 |
| 13 SourceReport::SourceReport(intptr_t report_set, CompileMode compile_mode) | 21 SourceReport::SourceReport(intptr_t report_set, CompileMode compile_mode) |
| 14 : report_set_(report_set), | 22 : report_set_(report_set), |
| 15 compile_mode_(compile_mode), | 23 compile_mode_(compile_mode), |
| 16 thread_(NULL), | 24 thread_(NULL), |
| 17 script_(NULL), | 25 script_(NULL), |
| 18 start_pos_(TokenPosition::kNoSource), | 26 start_pos_(TokenPosition::kNoSource), |
| 19 end_pos_(TokenPosition::kNoSource), | 27 end_pos_(TokenPosition::kNoSource), |
| 28 profile_(Isolate::Current()), |
| 20 next_script_index_(0) { | 29 next_script_index_(0) { |
| 21 } | 30 } |
| 22 | 31 |
| 23 | 32 |
| 24 void SourceReport::Init(Thread* thread, | 33 void SourceReport::Init(Thread* thread, |
| 25 const Script* script, | 34 const Script* script, |
| 26 TokenPosition start_pos, | 35 TokenPosition start_pos, |
| 27 TokenPosition end_pos) { | 36 TokenPosition end_pos) { |
| 28 thread_ = thread; | 37 thread_ = thread; |
| 29 script_ = script; | 38 script_ = script; |
| 30 start_pos_ = start_pos; | 39 start_pos_ = start_pos; |
| 31 end_pos_ = end_pos; | 40 end_pos_ = end_pos; |
| 32 script_table_entries_.Clear(); | 41 script_table_entries_.Clear(); |
| 33 script_table_.Clear(); | 42 script_table_.Clear(); |
| 34 next_script_index_ = 0; | 43 next_script_index_ = 0; |
| 44 if (IsReportRequested(kProfile)) { |
| 45 // Build the profile. |
| 46 SampleFilter samplesForIsolate(thread_->isolate(), -1, -1); |
| 47 profile_.Build(thread, &samplesForIsolate, Profile::kNoTags); |
| 48 } |
| 35 } | 49 } |
| 36 | 50 |
| 37 | 51 |
| 38 bool SourceReport::IsReportRequested(ReportKind report_kind) { | 52 bool SourceReport::IsReportRequested(ReportKind report_kind) { |
| 39 return (report_set_ & report_kind) != 0; | 53 return (report_set_ & report_kind) != 0; |
| 40 } | 54 } |
| 41 | 55 |
| 42 | 56 |
| 43 bool SourceReport::ShouldSkipFunction(const Function& func) { | 57 bool SourceReport::ShouldSkipFunction(const Function& func) { |
| 44 if (script_ != NULL && !script_->IsNull()) { | 58 if (script_ != NULL && !script_->IsNull()) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 JSONArray bpts(jsobj, "possibleBreakpoints"); | 257 JSONArray bpts(jsobj, "possibleBreakpoints"); |
| 244 for (int i = 0; i < func_length; i++) { | 258 for (int i = 0; i < func_length; i++) { |
| 245 if (possible[i]) { | 259 if (possible[i]) { |
| 246 // Add the token position. | 260 // Add the token position. |
| 247 bpts.AddValue(begin_pos.Pos() + i); | 261 bpts.AddValue(begin_pos.Pos() + i); |
| 248 } | 262 } |
| 249 } | 263 } |
| 250 } | 264 } |
| 251 | 265 |
| 252 | 266 |
| 267 void SourceReport::PrintProfileData(JSONObject* jsobj, |
| 268 ProfileFunction* profile_function) { |
| 269 ASSERT(profile_function != NULL); |
| 270 ASSERT(profile_function->NumSourcePositions() > 0); |
| 271 |
| 272 { |
| 273 JSONObject profile(jsobj, "profile"); |
| 274 |
| 275 { |
| 276 JSONObject profileData(&profile, "metadata"); |
| 277 profileData.AddProperty("sampleCount", profile_.sample_count()); |
| 278 } |
| 279 |
| 280 // Positions. |
| 281 { |
| 282 JSONArray positions(&profile, "positions"); |
| 283 for (intptr_t i = 0; i < profile_function->NumSourcePositions(); i++) { |
| 284 const ProfileFunctionSourcePosition& position = |
| 285 profile_function->GetSourcePosition(i); |
| 286 if (position.token_pos().IsSourcePosition() && |
| 287 !position.token_pos().IsNoSource()) { |
| 288 // Add as an integer. |
| 289 positions.AddValue(position.token_pos().Pos()); |
| 290 } else { |
| 291 // Add as a string. |
| 292 positions.AddValue(position.token_pos().ToCString()); |
| 293 } |
| 294 } |
| 295 } |
| 296 |
| 297 // Exclusive ticks. |
| 298 { |
| 299 JSONArray exclusiveTicks(&profile, "exclusiveTicks"); |
| 300 for (intptr_t i = 0; i < profile_function->NumSourcePositions(); i++) { |
| 301 const ProfileFunctionSourcePosition& position = |
| 302 profile_function->GetSourcePosition(i); |
| 303 exclusiveTicks.AddValue(position.exclusive_ticks()); |
| 304 } |
| 305 } |
| 306 // Inclusive ticks. |
| 307 { |
| 308 JSONArray inclusiveTicks(&profile, "inclusiveTicks"); |
| 309 for (intptr_t i = 0; i < profile_function->NumSourcePositions(); i++) { |
| 310 const ProfileFunctionSourcePosition& position = |
| 311 profile_function->GetSourcePosition(i); |
| 312 inclusiveTicks.AddValue(position.inclusive_ticks()); |
| 313 } |
| 314 } |
| 315 } |
| 316 } |
| 317 |
| 318 |
| 253 void SourceReport::PrintScriptTable(JSONArray* scripts) { | 319 void SourceReport::PrintScriptTable(JSONArray* scripts) { |
| 254 for (int i = 0; i < script_table_entries_.length(); i++) { | 320 for (int i = 0; i < script_table_entries_.length(); i++) { |
| 255 const Script* script = script_table_entries_[i].script; | 321 const Script* script = script_table_entries_[i].script; |
| 256 scripts->AddValue(*script); | 322 scripts->AddValue(*script); |
| 257 } | 323 } |
| 258 } | 324 } |
| 259 | 325 |
| 260 | 326 |
| 261 void SourceReport::VisitFunction(JSONArray* jsarr, const Function& func) { | 327 void SourceReport::VisitFunction(JSONArray* jsarr, const Function& func) { |
| 262 if (ShouldSkipFunction(func)) { | 328 if (ShouldSkipFunction(func)) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 370 |
| 305 if (IsReportRequested(kCallSites)) { | 371 if (IsReportRequested(kCallSites)) { |
| 306 PrintCallSitesData(&range, func, code); | 372 PrintCallSitesData(&range, func, code); |
| 307 } | 373 } |
| 308 if (IsReportRequested(kCoverage)) { | 374 if (IsReportRequested(kCoverage)) { |
| 309 PrintCoverageData(&range, func, code); | 375 PrintCoverageData(&range, func, code); |
| 310 } | 376 } |
| 311 if (IsReportRequested(kPossibleBreakpoints)) { | 377 if (IsReportRequested(kPossibleBreakpoints)) { |
| 312 PrintPossibleBreakpointsData(&range, func, code); | 378 PrintPossibleBreakpointsData(&range, func, code); |
| 313 } | 379 } |
| 380 if (IsReportRequested(kProfile)) { |
| 381 ProfileFunction* profile_function = profile_.FindFunction(func); |
| 382 if ((profile_function != NULL) && |
| 383 (profile_function->NumSourcePositions() > 0)) { |
| 384 PrintProfileData(&range, profile_function); |
| 385 } |
| 386 } |
| 314 } | 387 } |
| 315 | 388 |
| 316 | 389 |
| 317 void SourceReport::VisitLibrary(JSONArray* jsarr, const Library& lib) { | 390 void SourceReport::VisitLibrary(JSONArray* jsarr, const Library& lib) { |
| 318 Class& cls = Class::Handle(zone()); | 391 Class& cls = Class::Handle(zone()); |
| 319 Array& functions = Array::Handle(zone()); | 392 Array& functions = Array::Handle(zone()); |
| 320 Function& func = Function::Handle(zone()); | 393 Function& func = Function::Handle(zone()); |
| 321 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); | 394 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); |
| 322 while (it.HasNext()) { | 395 while (it.HasNext()) { |
| 323 cls = it.GetNextClass(); | 396 cls = it.GetNextClass(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 VisitClosures(&ranges); | 444 VisitClosures(&ranges); |
| 372 } | 445 } |
| 373 | 446 |
| 374 // Print the script table. | 447 // Print the script table. |
| 375 JSONArray scripts(&report, "scripts"); | 448 JSONArray scripts(&report, "scripts"); |
| 376 PrintScriptTable(&scripts); | 449 PrintScriptTable(&scripts); |
| 377 } | 450 } |
| 378 | 451 |
| 379 | 452 |
| 380 } // namespace dart | 453 } // namespace dart |
| OLD | NEW |