| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 tkit.Advance(); | 54 tkit.Advance(); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 | 58 |
| 59 void CodeCoverage::CompileAndAdd(const Function& function, | 59 void CodeCoverage::CompileAndAdd(const Function& function, |
| 60 const JSONArray& hits_or_sites, | 60 const JSONArray& hits_or_sites, |
| 61 const GrowableArray<intptr_t>& pos_to_line, | 61 const GrowableArray<intptr_t>& pos_to_line, |
| 62 bool as_call_sites) { | 62 bool as_call_sites) { |
| 63 if (!FLAG_support_coverage) { |
| 64 return; |
| 65 } |
| 63 // If the function should not be compiled for coverage analysis, then just | 66 // If the function should not be compiled for coverage analysis, then just |
| 64 // skip this method. | 67 // skip this method. |
| 65 // TODO(iposva): Maybe we should skip synthesized methods in general too. | 68 // TODO(iposva): Maybe we should skip synthesized methods in general too. |
| 66 if (function.is_abstract() || function.IsRedirectingFactory()) { | 69 if (function.is_abstract() || function.IsRedirectingFactory()) { |
| 67 return; | 70 return; |
| 68 } | 71 } |
| 69 if (function.IsNonImplicitClosureFunction() && | 72 if (function.IsNonImplicitClosureFunction() && |
| 70 (function.context_scope() == ContextScope::null())) { | 73 (function.context_scope() == ContextScope::null())) { |
| 71 // TODO(iposva): This can arise if we attempt to compile an inner function | 74 // TODO(iposva): This can arise if we attempt to compile an inner function |
| 72 // before we have compiled its enclosing function or if the enclosing | 75 // before we have compiled its enclosing function or if the enclosing |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 hits_or_sites.AddValue(last_count); | 142 hits_or_sites.AddValue(last_count); |
| 140 } | 143 } |
| 141 } | 144 } |
| 142 | 145 |
| 143 | 146 |
| 144 void CodeCoverage::PrintClass(const Library& lib, | 147 void CodeCoverage::PrintClass(const Library& lib, |
| 145 const Class& cls, | 148 const Class& cls, |
| 146 const JSONArray& jsarr, | 149 const JSONArray& jsarr, |
| 147 CoverageFilter* filter, | 150 CoverageFilter* filter, |
| 148 bool as_call_sites) { | 151 bool as_call_sites) { |
| 152 if (!FLAG_support_coverage) { |
| 153 return; |
| 154 } |
| 149 Thread* thread = Thread::Current(); | 155 Thread* thread = Thread::Current(); |
| 150 if (cls.EnsureIsFinalized(thread) != Error::null()) { | 156 if (cls.EnsureIsFinalized(thread) != Error::null()) { |
| 151 // Only classes that have been finalized do have a meaningful list of | 157 // Only classes that have been finalized do have a meaningful list of |
| 152 // functions. | 158 // functions. |
| 153 return; | 159 return; |
| 154 } | 160 } |
| 155 Array& functions = Array::Handle(cls.functions()); | 161 Array& functions = Array::Handle(cls.functions()); |
| 156 ASSERT(!functions.IsNull()); | 162 ASSERT(!functions.IsNull()); |
| 157 Function& function = Function::Handle(); | 163 Function& function = Function::Handle(); |
| 158 Script& script = Script::Handle(); | 164 Script& script = Script::Handle(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 break; | 239 break; |
| 234 } | 240 } |
| 235 CompileAndAdd(function, hits_or_sites, pos_to_line, as_call_sites); | 241 CompileAndAdd(function, hits_or_sites, pos_to_line, as_call_sites); |
| 236 i++; | 242 i++; |
| 237 } | 243 } |
| 238 } | 244 } |
| 239 } | 245 } |
| 240 | 246 |
| 241 | 247 |
| 242 void CodeCoverage::Write(Thread* thread) { | 248 void CodeCoverage::Write(Thread* thread) { |
| 249 if (!FLAG_support_coverage) { |
| 250 return; |
| 251 } |
| 243 if (FLAG_coverage_dir == NULL) { | 252 if (FLAG_coverage_dir == NULL) { |
| 244 return; | 253 return; |
| 245 } | 254 } |
| 246 | 255 |
| 247 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); | 256 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); |
| 248 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); | 257 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); |
| 249 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); | 258 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); |
| 250 if ((file_open == NULL) || (file_write == NULL) || (file_close == NULL)) { | 259 if ((file_open == NULL) || (file_write == NULL) || (file_close == NULL)) { |
| 251 return; | 260 return; |
| 252 } | 261 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 265 } | 274 } |
| 266 (*file_write)(stream.buffer()->buf(), stream.buffer()->length(), file); | 275 (*file_write)(stream.buffer()->buf(), stream.buffer()->length(), file); |
| 267 (*file_close)(file); | 276 (*file_close)(file); |
| 268 } | 277 } |
| 269 | 278 |
| 270 | 279 |
| 271 void CodeCoverage::PrintJSON(Thread* thread, | 280 void CodeCoverage::PrintJSON(Thread* thread, |
| 272 JSONStream* stream, | 281 JSONStream* stream, |
| 273 CoverageFilter* filter, | 282 CoverageFilter* filter, |
| 274 bool as_call_sites) { | 283 bool as_call_sites) { |
| 284 if (!FLAG_support_coverage) { |
| 285 return; |
| 286 } |
| 275 CoverageFilterAll default_filter; | 287 CoverageFilterAll default_filter; |
| 276 if (filter == NULL) { | 288 if (filter == NULL) { |
| 277 filter = &default_filter; | 289 filter = &default_filter; |
| 278 } | 290 } |
| 279 const GrowableObjectArray& libs = GrowableObjectArray::Handle( | 291 const GrowableObjectArray& libs = GrowableObjectArray::Handle( |
| 280 thread->zone(), | 292 thread->zone(), |
| 281 thread->isolate()->object_store()->libraries()); | 293 thread->isolate()->object_store()->libraries()); |
| 282 Library& lib = Library::Handle(); | 294 Library& lib = Library::Handle(); |
| 283 Class& cls = Class::Handle(); | 295 Class& cls = Class::Handle(); |
| 284 JSONObject coverage(stream); | 296 JSONObject coverage(stream); |
| 285 coverage.AddProperty("type", "CodeCoverage"); | 297 coverage.AddProperty("type", "CodeCoverage"); |
| 286 { | 298 { |
| 287 JSONArray jsarr(&coverage, "coverage"); | 299 JSONArray jsarr(&coverage, "coverage"); |
| 288 for (int i = 0; i < libs.Length(); i++) { | 300 for (int i = 0; i < libs.Length(); i++) { |
| 289 lib ^= libs.At(i); | 301 lib ^= libs.At(i); |
| 290 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); | 302 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); |
| 291 while (it.HasNext()) { | 303 while (it.HasNext()) { |
| 292 cls = it.GetNextClass(); | 304 cls = it.GetNextClass(); |
| 293 ASSERT(!cls.IsNull()); | 305 ASSERT(!cls.IsNull()); |
| 294 PrintClass(lib, cls, jsarr, filter, as_call_sites); | 306 PrintClass(lib, cls, jsarr, filter, as_call_sites); |
| 295 } | 307 } |
| 296 } | 308 } |
| 297 } | 309 } |
| 298 } | 310 } |
| 299 | 311 |
| 300 | 312 |
| 301 } // namespace dart | 313 } // namespace dart |
| OLD | NEW |