| 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 "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 RawPcDescriptors::kIcCall | RawPcDescriptors::kUnoptStaticCall); | 96 RawPcDescriptors::kIcCall | RawPcDescriptors::kUnoptStaticCall); |
| 97 while (iter.MoveNext()) { | 97 while (iter.MoveNext()) { |
| 98 HANDLESCOPE(thread); | 98 HANDLESCOPE(thread); |
| 99 const ICData* ic_data = (*ic_data_array)[iter.DeoptId()]; | 99 const ICData* ic_data = (*ic_data_array)[iter.DeoptId()]; |
| 100 if (!ic_data->IsNull()) { | 100 if (!ic_data->IsNull()) { |
| 101 const intptr_t token_pos = iter.TokenPos(); | 101 const intptr_t token_pos = iter.TokenPos(); |
| 102 // Filter out descriptors that do not map to tokens in the source code. | 102 // Filter out descriptors that do not map to tokens in the source code. |
| 103 if ((token_pos < begin_pos) || (token_pos > end_pos)) { | 103 if ((token_pos < begin_pos) || (token_pos > end_pos)) { |
| 104 continue; | 104 continue; |
| 105 } | 105 } |
| 106 intptr_t line = pos_to_line[token_pos]; | |
| 107 #if defined(DEBUG) | |
| 108 const Script& script = Script::Handle(zone, function.script()); | |
| 109 intptr_t test_line = -1; | |
| 110 script.GetTokenLocation(token_pos, &test_line, NULL); | |
| 111 ASSERT(test_line == line); | |
| 112 #endif | |
| 113 // Merge hit data where possible. | |
| 114 if (last_line == line) { | |
| 115 last_count += ic_data->AggregateCount(); | |
| 116 } else { | |
| 117 if ((last_line != -1) && !as_call_sites) { | |
| 118 hits_or_sites.AddValue(last_line); | |
| 119 hits_or_sites.AddValue(last_count); | |
| 120 } | |
| 121 last_count = ic_data->AggregateCount(); | |
| 122 last_line = line; | |
| 123 } | |
| 124 if (as_call_sites) { | 106 if (as_call_sites) { |
| 125 bool is_static_call = iter.Kind() == RawPcDescriptors::kUnoptStaticCall; | 107 bool is_static_call = iter.Kind() == RawPcDescriptors::kUnoptStaticCall; |
| 126 ic_data->PrintToJSONArray(hits_or_sites, token_pos, is_static_call); | 108 ic_data->PrintToJSONArray(hits_or_sites, token_pos, is_static_call); |
| 109 } else { |
| 110 intptr_t line = pos_to_line[token_pos]; |
| 111 #if defined(DEBUG) |
| 112 const Script& script = Script::Handle(zone, function.script()); |
| 113 intptr_t test_line = -1; |
| 114 script.GetTokenLocation(token_pos, &test_line, NULL); |
| 115 ASSERT(test_line == line); |
| 116 #endif |
| 117 // Merge hit data where possible. |
| 118 if (last_line == line) { |
| 119 last_count += ic_data->AggregateCount(); |
| 120 } else { |
| 121 if ((last_line != -1)) { |
| 122 hits_or_sites.AddValue(last_line); |
| 123 hits_or_sites.AddValue(last_count); |
| 124 } |
| 125 last_count = ic_data->AggregateCount(); |
| 126 last_line = line; |
| 127 } |
| 127 } | 128 } |
| 128 } | 129 } |
| 129 } | 130 } |
| 130 // Write last hit value if needed. | 131 // Write last hit value if needed. |
| 131 if ((last_line != -1) && !as_call_sites) { | 132 if (!as_call_sites && (last_line != -1)) { |
| 132 hits_or_sites.AddValue(last_line); | 133 hits_or_sites.AddValue(last_line); |
| 133 hits_or_sites.AddValue(last_count); | 134 hits_or_sites.AddValue(last_count); |
| 134 } | 135 } |
| 135 } | 136 } |
| 136 | 137 |
| 137 | 138 |
| 138 void CodeCoverage::PrintClass(const Library& lib, | 139 void CodeCoverage::PrintClass(const Library& lib, |
| 139 const Class& cls, | 140 const Class& cls, |
| 140 const JSONArray& jsarr, | 141 const JSONArray& jsarr, |
| 141 CoverageFilter* filter, | 142 CoverageFilter* filter, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 157 int i = 0; | 158 int i = 0; |
| 158 while (i < functions.Length()) { | 159 while (i < functions.Length()) { |
| 159 HANDLESCOPE(thread); | 160 HANDLESCOPE(thread); |
| 160 function ^= functions.At(i); | 161 function ^= functions.At(i); |
| 161 script = function.script(); | 162 script = function.script(); |
| 162 saved_url = script.url(); | 163 saved_url = script.url(); |
| 163 if (!filter->ShouldOutputCoverageFor(lib, script, cls, function)) { | 164 if (!filter->ShouldOutputCoverageFor(lib, script, cls, function)) { |
| 164 i++; | 165 i++; |
| 165 continue; | 166 continue; |
| 166 } | 167 } |
| 167 ComputeTokenPosToLineNumberMap(script, &pos_to_line); | 168 if (!as_call_sites) { |
| 169 ComputeTokenPosToLineNumberMap(script, &pos_to_line); |
| 170 } |
| 168 JSONObject jsobj(&jsarr); | 171 JSONObject jsobj(&jsarr); |
| 169 jsobj.AddProperty("source", saved_url.ToCString()); | 172 jsobj.AddProperty("source", saved_url.ToCString()); |
| 170 jsobj.AddProperty("script", script); | 173 jsobj.AddProperty("script", script); |
| 171 JSONArray hits_or_sites(&jsobj, as_call_sites ? "callSites" : "hits"); | 174 JSONArray hits_or_sites(&jsobj, as_call_sites ? "callSites" : "hits"); |
| 172 | 175 |
| 173 // We stay within this loop while we are seeing functions from the same | 176 // We stay within this loop while we are seeing functions from the same |
| 174 // source URI. | 177 // source URI. |
| 175 while (i < functions.Length()) { | 178 while (i < functions.Length()) { |
| 176 function ^= functions.At(i); | 179 function ^= functions.At(i); |
| 177 script = function.script(); | 180 script = function.script(); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 cls = it.GetNextClass(); | 287 cls = it.GetNextClass(); |
| 285 ASSERT(!cls.IsNull()); | 288 ASSERT(!cls.IsNull()); |
| 286 PrintClass(lib, cls, jsarr, filter, as_call_sites); | 289 PrintClass(lib, cls, jsarr, filter, as_call_sites); |
| 287 } | 290 } |
| 288 } | 291 } |
| 289 } | 292 } |
| 290 } | 293 } |
| 291 | 294 |
| 292 | 295 |
| 293 } // namespace dart | 296 } // namespace dart |
| OLD | NEW |