Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Unified Diff: runtime/vm/coverage.cc

Issue 351373002: Coverage API revamp (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: addressed comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/coverage.h ('k') | runtime/vm/coverage_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/coverage.cc
diff --git a/runtime/vm/coverage.cc b/runtime/vm/coverage.cc
index 3d546a54bf4dc88e4976c5be94f89d7cdae85f64..4572eb87d095b285414c5e59e819cdf41877ce37 100644
--- a/runtime/vm/coverage.cc
+++ b/runtime/vm/coverage.cc
@@ -18,6 +18,17 @@ DEFINE_FLAG(charp, coverage_dir, NULL,
"Enable writing coverage data into specified directory.");
+class CoverageFilterAll : public CoverageFilter {
+ public:
+ bool ShouldOutputCoverageFor(const Library& lib,
+ const String& script_url,
+ const Class& cls,
+ const Function& func) const {
+ return true;
+ }
+};
+
+
// map[token_pos] -> line-number.
static void ComputeTokenPosToLineNumberMap(const Script& script,
GrowableArray<intptr_t>* map) {
@@ -41,12 +52,6 @@ static void ComputeTokenPosToLineNumberMap(const Script& script,
}
-static inline void PrintJSONPreamble(JSONObject* jsobj) {
- jsobj->AddProperty("type", "CodeCoverage");
- jsobj->AddProperty("id", "coverage");
-}
-
-
void CodeCoverage::CompileAndAdd(const Function& function,
const JSONArray& hits_arr,
const GrowableArray<intptr_t>& pos_to_line) {
@@ -129,9 +134,10 @@ void CodeCoverage::CompileAndAdd(const Function& function,
}
-void CodeCoverage::PrintClass(const Class& cls,
+void CodeCoverage::PrintClass(const Library& lib,
+ const Class& cls,
const JSONArray& jsarr,
- const Script& script_filter) {
+ CoverageFilter* filter) {
Isolate* isolate = Isolate::Current();
if (cls.EnsureIsFinalized(isolate) != Error::null()) {
// Only classes that have been finalized do have a meaningful list of
@@ -150,11 +156,11 @@ void CodeCoverage::PrintClass(const Class& cls,
HANDLESCOPE(isolate);
function ^= functions.At(i);
script = function.script();
- if (!script_filter.IsNull() && script_filter.raw() != script.raw()) {
+ saved_url = script.url();
+ if (!filter->ShouldOutputCoverageFor(lib, saved_url, cls, function)) {
i++;
continue;
}
- saved_url = script.url();
ComputeTokenPosToLineNumberMap(script, &pos_to_line);
JSONObject jsobj(&jsarr);
jsobj.AddProperty("source", saved_url.ToCString());
@@ -191,11 +197,11 @@ void CodeCoverage::PrintClass(const Class& cls,
HANDLESCOPE(isolate);
function ^= closures.At(i);
script = function.script();
- if (!script_filter.IsNull() && script_filter.raw() != script.raw()) {
+ saved_url = script.url();
+ if (!filter->ShouldOutputCoverageFor(lib, saved_url, cls, function)) {
i++;
continue;
}
- saved_url = script.url();
ComputeTokenPosToLineNumberMap(script, &pos_to_line);
JSONObject jsobj(&jsarr);
jsobj.AddProperty("source", saved_url.ToCString());
@@ -220,44 +226,6 @@ void CodeCoverage::PrintClass(const Class& cls,
}
-void CodeCoverage::PrintJSONForClass(const Class& cls,
- JSONStream* stream) {
- JSONObject coverage(stream);
- PrintJSONPreamble(&coverage);
- {
- JSONArray jsarr(&coverage, "coverage");
- PrintClass(cls, jsarr, Script::Handle());
- }
-}
-
-
-void CodeCoverage::PrintJSONForLibrary(const Library& lib,
- const Script& script_filter,
- JSONStream* stream) {
- Class& cls = Class::Handle();
- JSONObject coverage(stream);
- PrintJSONPreamble(&coverage);
- {
- JSONArray jsarr(&coverage, "coverage");
- ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate);
- while (it.HasNext()) {
- cls = it.GetNextClass();
- ASSERT(!cls.IsNull());
- PrintClass(cls, jsarr, script_filter);
- }
- }
-}
-
-
-void CodeCoverage::PrintJSONForScript(const Script& script,
- JSONStream* stream) {
- Library& lib = Library::Handle();
- lib = script.FindLibrary();
- ASSERT(!lib.IsNull());
- PrintJSONForLibrary(lib, script, stream);
-}
-
-
void CodeCoverage::Write(Isolate* isolate) {
if (FLAG_coverage_dir == NULL) {
return;
@@ -271,7 +239,7 @@ void CodeCoverage::Write(Isolate* isolate) {
}
JSONStream stream;
- PrintJSON(isolate, &stream);
+ PrintJSON(isolate, &stream, NULL);
const char* format = "%s/dart-cov-%" Pd "-%" Pd ".json";
intptr_t pid = OS::ProcessId();
@@ -290,7 +258,13 @@ void CodeCoverage::Write(Isolate* isolate) {
}
-void CodeCoverage::PrintJSON(Isolate* isolate, JSONStream* stream) {
+void CodeCoverage::PrintJSON(Isolate* isolate,
+ JSONStream* stream,
+ CoverageFilter* filter) {
+ CoverageFilterAll default_filter;
+ if (filter == NULL) {
+ filter = &default_filter;
+ }
const GrowableObjectArray& libs = GrowableObjectArray::Handle(
isolate, isolate->object_store()->libraries());
Library& lib = Library::Handle();
@@ -306,7 +280,7 @@ void CodeCoverage::PrintJSON(Isolate* isolate, JSONStream* stream) {
while (it.HasNext()) {
cls = it.GetNextClass();
ASSERT(!cls.IsNull());
- PrintClass(cls, jsarr, Script::Handle());
+ PrintClass(lib, cls, jsarr, filter);
}
}
}
« no previous file with comments | « runtime/vm/coverage.h ('k') | runtime/vm/coverage_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698