OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "vm/coverage.h" |
| 6 |
| 7 #include "vm/isolate.h" |
| 8 #include "vm/json_stream.h" |
| 9 #include "vm/object.h" |
| 10 #include "vm/object_store.h" |
| 11 |
| 12 namespace dart { |
| 13 |
| 14 DEFINE_FLAG(bool, print_coverage, false, "Print code coverage."); |
| 15 |
| 16 void CodeCoverage::PrintClass(const Class& cls, const JSONArray& jsarr) { |
| 17 const Array& functions = Array::Handle(cls.functions()); |
| 18 ASSERT(!functions.IsNull()); |
| 19 Function& function = Function::Handle(); |
| 20 Code& code = Code::Handle(); |
| 21 Script& script = Script::Handle(); |
| 22 String& url = String::Handle(); |
| 23 String& name = String::Handle(); |
| 24 PcDescriptors& descriptors = PcDescriptors::Handle(); |
| 25 Array& ic_array = Array::Handle(); |
| 26 ICData& ic_data = ICData::Handle(); |
| 27 for (int i = 0; i < functions.Length(); i++) { |
| 28 function ^= functions.At(i); |
| 29 if (function.HasCode()) { |
| 30 JSONObject jsobj(jsarr); |
| 31 |
| 32 script = function.script(); |
| 33 url = script.url(); |
| 34 name = function.QualifiedUserVisibleName(); |
| 35 jsobj.AddProperty("source", url.ToCString()); |
| 36 jsobj.AddProperty("function", name.ToCString()); |
| 37 |
| 38 code = function.unoptimized_code(); |
| 39 ic_array = code.ExtractTypeFeedbackArray(); |
| 40 descriptors = code.pc_descriptors(); |
| 41 |
| 42 JSONArray jsarr(jsobj, "hits"); |
| 43 for (int j = 0; j < descriptors.Length(); j++) { |
| 44 PcDescriptors::Kind kind = descriptors.DescriptorKind(j); |
| 45 // Only IC based calls have counting. |
| 46 if ((kind == PcDescriptors::kIcCall) || |
| 47 (kind == PcDescriptors::kUnoptStaticCall)) { |
| 48 intptr_t deopt_id = descriptors.DeoptId(j); |
| 49 ic_data ^= ic_array.At(deopt_id); |
| 50 if (!ic_data.IsNull() && (ic_data.AggregateCount() > 0)) { |
| 51 intptr_t token_pos = descriptors.TokenPos(j); |
| 52 intptr_t line = -1; |
| 53 intptr_t col = -1; |
| 54 script.GetTokenLocation(token_pos, &line, &col); |
| 55 // OS::Print(" %s -> %"Pd" @ %"Pd" %"Pd"\n", |
| 56 // ic_data.ToCString(), |
| 57 // ic_data.AggregateCount(), |
| 58 // token_pos, line); |
| 59 JSONObject ic_info(jsarr); |
| 60 ic_info.AddProperty("line", line); |
| 61 ic_info.AddProperty("col", col); |
| 62 ic_info.AddProperty("count", ic_data.AggregateCount()); |
| 63 } |
| 64 } |
| 65 } |
| 66 } |
| 67 } |
| 68 } |
| 69 |
| 70 |
| 71 void CodeCoverage::Print(Isolate* isolate) { |
| 72 JSONStream stream; |
| 73 |
| 74 { |
| 75 const GrowableObjectArray& libs = GrowableObjectArray::Handle( |
| 76 isolate, isolate->object_store()->libraries()); |
| 77 Library& lib = Library::Handle(); |
| 78 Class& cls = Class::Handle(); |
| 79 JSONArray jsarr(&stream); |
| 80 for (int i = 0; i < libs.Length(); i++) { |
| 81 lib ^= libs.At(i); |
| 82 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); |
| 83 while (it.HasNext()) { |
| 84 cls = it.GetNextClass(); |
| 85 if (cls.is_finalized()) { |
| 86 // Only classes that have been finalized do have a meaningful list of |
| 87 // functions. |
| 88 PrintClass(cls, jsarr); |
| 89 } |
| 90 } |
| 91 } |
| 92 } |
| 93 |
| 94 OS::Print("### COVERAGE DATA ###\n" |
| 95 "%s\n" |
| 96 "### END ###\n", stream.ToCString()); |
| 97 } |
| 98 |
| 99 } // namespace dart |
OLD | NEW |