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

Unified Diff: runtime/vm/coverage.cc

Issue 346003003: vmservice: Add /coverage collection to scripts, classes and libraries. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: exclude service_classescoverage from simmips tests 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
Index: runtime/vm/coverage.cc
diff --git a/runtime/vm/coverage.cc b/runtime/vm/coverage.cc
index 5485b2edb3747cd794cc0d165c2a30c814db7f34..3d546a54bf4dc88e4976c5be94f89d7cdae85f64 100644
--- a/runtime/vm/coverage.cc
+++ b/runtime/vm/coverage.cc
@@ -41,6 +41,12 @@ 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) {
@@ -123,7 +129,9 @@ void CodeCoverage::CompileAndAdd(const Function& function,
}
-void CodeCoverage::PrintClass(const Class& cls, const JSONArray& jsarr) {
+void CodeCoverage::PrintClass(const Class& cls,
+ const JSONArray& jsarr,
+ const Script& script_filter) {
Isolate* isolate = Isolate::Current();
if (cls.EnsureIsFinalized(isolate) != Error::null()) {
// Only classes that have been finalized do have a meaningful list of
@@ -141,10 +149,14 @@ void CodeCoverage::PrintClass(const Class& cls, const JSONArray& jsarr) {
while (i < functions.Length()) {
HANDLESCOPE(isolate);
function ^= functions.At(i);
- JSONObject jsobj(&jsarr);
script = function.script();
- ComputeTokenPosToLineNumberMap(script, &pos_to_line);
+ if (!script_filter.IsNull() && script_filter.raw() != script.raw()) {
+ i++;
+ continue;
+ }
saved_url = script.url();
+ ComputeTokenPosToLineNumberMap(script, &pos_to_line);
+ JSONObject jsobj(&jsarr);
jsobj.AddProperty("source", saved_url.ToCString());
jsobj.AddProperty("script", script);
JSONArray hits_arr(&jsobj, "hits");
@@ -178,10 +190,14 @@ void CodeCoverage::PrintClass(const Class& cls, const JSONArray& jsarr) {
while (i < closures.Length()) {
HANDLESCOPE(isolate);
function ^= closures.At(i);
- JSONObject jsobj(&jsarr);
script = function.script();
- ComputeTokenPosToLineNumberMap(script, &pos_to_line);
+ if (!script_filter.IsNull() && script_filter.raw() != script.raw()) {
+ i++;
+ continue;
+ }
saved_url = script.url();
+ ComputeTokenPosToLineNumberMap(script, &pos_to_line);
+ JSONObject jsobj(&jsarr);
jsobj.AddProperty("source", saved_url.ToCString());
jsobj.AddProperty("script", script);
JSONArray hits_arr(&jsobj, "hits");
@@ -204,6 +220,44 @@ void CodeCoverage::PrintClass(const Class& cls, const JSONArray& jsarr) {
}
+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;
@@ -251,7 +305,8 @@ void CodeCoverage::PrintJSON(Isolate* isolate, JSONStream* stream) {
ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate);
while (it.HasNext()) {
cls = it.GetNextClass();
- PrintClass(cls, jsarr);
+ ASSERT(!cls.IsNull());
+ PrintClass(cls, jsarr, Script::Handle());
}
}
}
« no previous file with comments | « runtime/vm/coverage.h ('k') | runtime/vm/object.h » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698