OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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/coverage.h" | 5 #include "vm/coverage.h" |
6 | 6 |
7 #include "vm/isolate.h" | 7 #include "vm/isolate.h" |
8 #include "vm/json_stream.h" | 8 #include "vm/json_stream.h" |
9 #include "vm/object.h" | 9 #include "vm/object.h" |
10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 DEFINE_FLAG(bool, print_coverage, false, "Print code coverage."); | 14 DEFINE_FLAG(bool, print_coverage, false, "Print code coverage."); |
15 | 15 |
16 void CodeCoverage::PrintClass(const Class& cls, const JSONArray& jsarr) { | 16 void CodeCoverage::PrintClass(const Class& cls, const JSONArray& jsarr) { |
17 const Array& functions = Array::Handle(cls.functions()); | 17 const Array& functions = Array::Handle(cls.functions()); |
18 ASSERT(!functions.IsNull()); | 18 ASSERT(!functions.IsNull()); |
19 Function& function = Function::Handle(); | 19 Function& function = Function::Handle(); |
20 Code& code = Code::Handle(); | 20 Code& code = Code::Handle(); |
21 Script& script = Script::Handle(); | 21 Script& script = Script::Handle(); |
22 String& url = String::Handle(); | 22 String& url = String::Handle(); |
23 String& name = String::Handle(); | 23 String& name = String::Handle(); |
24 PcDescriptors& descriptors = PcDescriptors::Handle(); | 24 PcDescriptors& descriptors = PcDescriptors::Handle(); |
25 Array& ic_array = Array::Handle(); | 25 Array& ic_array = Array::Handle(); |
26 ICData& ic_data = ICData::Handle(); | 26 ICData& ic_data = ICData::Handle(); |
27 for (int i = 0; i < functions.Length(); i++) { | 27 for (int i = 0; i < functions.Length(); i++) { |
28 function ^= functions.At(i); | 28 function ^= functions.At(i); |
29 if (function.HasCode()) { | 29 if (function.HasCode()) { |
30 JSONObject jsobj(jsarr); | 30 JSONObject jsobj(&jsarr); |
31 | 31 |
32 script = function.script(); | 32 script = function.script(); |
33 url = script.url(); | 33 url = script.url(); |
34 name = function.QualifiedUserVisibleName(); | 34 name = function.QualifiedUserVisibleName(); |
35 jsobj.AddProperty("source", url.ToCString()); | 35 jsobj.AddProperty("source", url.ToCString()); |
36 jsobj.AddProperty("function", name.ToCString()); | 36 jsobj.AddProperty("function", name.ToCString()); |
37 | 37 |
38 code = function.unoptimized_code(); | 38 code = function.unoptimized_code(); |
39 ic_array = code.ExtractTypeFeedbackArray(); | 39 ic_array = code.ExtractTypeFeedbackArray(); |
40 descriptors = code.pc_descriptors(); | 40 descriptors = code.pc_descriptors(); |
41 | 41 |
42 JSONArray jsarr(jsobj, "hits"); | 42 JSONArray jsarr(&jsobj, "hits"); |
43 for (int j = 0; j < descriptors.Length(); j++) { | 43 for (int j = 0; j < descriptors.Length(); j++) { |
44 PcDescriptors::Kind kind = descriptors.DescriptorKind(j); | 44 PcDescriptors::Kind kind = descriptors.DescriptorKind(j); |
45 // Only IC based calls have counting. | 45 // Only IC based calls have counting. |
46 if ((kind == PcDescriptors::kIcCall) || | 46 if ((kind == PcDescriptors::kIcCall) || |
47 (kind == PcDescriptors::kUnoptStaticCall)) { | 47 (kind == PcDescriptors::kUnoptStaticCall)) { |
48 intptr_t deopt_id = descriptors.DeoptId(j); | 48 intptr_t deopt_id = descriptors.DeoptId(j); |
49 ic_data ^= ic_array.At(deopt_id); | 49 ic_data ^= ic_array.At(deopt_id); |
50 if (!ic_data.IsNull() && (ic_data.AggregateCount() > 0)) { | 50 if (!ic_data.IsNull() && (ic_data.AggregateCount() > 0)) { |
51 intptr_t token_pos = descriptors.TokenPos(j); | 51 intptr_t token_pos = descriptors.TokenPos(j); |
52 intptr_t line = -1; | 52 intptr_t line = -1; |
53 intptr_t col = -1; | 53 intptr_t col = -1; |
54 script.GetTokenLocation(token_pos, &line, &col); | 54 script.GetTokenLocation(token_pos, &line, &col); |
55 JSONObject ic_info(jsarr); | 55 JSONObject ic_info(&jsarr); |
56 ic_info.AddProperty("line", line); | 56 ic_info.AddProperty("line", line); |
57 ic_info.AddProperty("col", col); | 57 ic_info.AddProperty("col", col); |
58 ic_info.AddProperty("count", ic_data.AggregateCount()); | 58 ic_info.AddProperty("count", ic_data.AggregateCount()); |
59 } | 59 } |
60 } | 60 } |
61 } | 61 } |
62 } | 62 } |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
(...skipping 20 matching lines...) Expand all Loading... |
86 } | 86 } |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 OS::Print("### COVERAGE DATA ###\n" | 90 OS::Print("### COVERAGE DATA ###\n" |
91 "%s\n" | 91 "%s\n" |
92 "### END ###\n", stream.ToCString()); | 92 "### END ###\n", stream.ToCString()); |
93 } | 93 } |
94 | 94 |
95 } // namespace dart | 95 } // namespace dart |
OLD | NEW |