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

Side by Side Diff: runtime/vm/coverage.cc

Issue 143973005: Code coverage in Observatory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/coverage.h ('k') | runtime/vm/service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 String& url = String::Handle(); 82 String& url = String::Handle();
83 83
84 int i = 0; 84 int i = 0;
85 while (i < functions.Length()) { 85 while (i < functions.Length()) {
86 HANDLESCOPE(isolate); 86 HANDLESCOPE(isolate);
87 function ^= functions.At(i); 87 function ^= functions.At(i);
88 JSONObject jsobj(&jsarr); 88 JSONObject jsobj(&jsarr);
89 script = function.script(); 89 script = function.script();
90 saved_url = script.url(); 90 saved_url = script.url();
91 jsobj.AddProperty("source", saved_url.ToCString()); 91 jsobj.AddProperty("source", saved_url.ToCString());
92 jsobj.AddProperty("script", script);
92 JSONArray hits_arr(&jsobj, "hits"); 93 JSONArray hits_arr(&jsobj, "hits");
93 94
94 // We stay within this loop while we are seeing functions from the same 95 // We stay within this loop while we are seeing functions from the same
95 // source URI. 96 // source URI.
96 while (i < functions.Length()) { 97 while (i < functions.Length()) {
97 function ^= functions.At(i); 98 function ^= functions.At(i);
98 script = function.script(); 99 script = function.script();
99 url = script.url(); 100 url = script.url();
100 if (!url.Equals(saved_url)) { 101 if (!url.Equals(saved_url)) {
101 break; 102 break;
102 } 103 }
103 CompileAndAdd(function, hits_arr); 104 CompileAndAdd(function, hits_arr);
105 if (function.HasImplicitClosureFunction()) {
106 function = function.ImplicitClosureFunction();
107 CompileAndAdd(function, hits_arr);
108 }
104 i++; 109 i++;
105 } 110 }
106 } 111 }
107 112
108 GrowableObjectArray& closures = 113 GrowableObjectArray& closures =
109 GrowableObjectArray::Handle(cls.closures()); 114 GrowableObjectArray::Handle(cls.closures());
110 if (!closures.IsNull()) { 115 if (!closures.IsNull()) {
111 i = 0; 116 i = 0;
112 // We need to keep rechecking the length of the closures array, as handling 117 // We need to keep rechecking the length of the closures array, as handling
113 // a closure potentially adds new entries to the end. 118 // a closure potentially adds new entries to the end.
114 while (i < closures.Length()) { 119 while (i < closures.Length()) {
115 HANDLESCOPE(isolate); 120 HANDLESCOPE(isolate);
116 function ^= closures.At(i); 121 function ^= closures.At(i);
117 JSONObject jsobj(&jsarr); 122 JSONObject jsobj(&jsarr);
118 script = function.script(); 123 script = function.script();
119 saved_url = script.url(); 124 saved_url = script.url();
120 jsobj.AddProperty("source", saved_url.ToCString()); 125 jsobj.AddProperty("source", saved_url.ToCString());
126 jsobj.AddProperty("script", script);
121 JSONArray hits_arr(&jsobj, "hits"); 127 JSONArray hits_arr(&jsobj, "hits");
122 128
123 // We stay within this loop while we are seeing functions from the same 129 // We stay within this loop while we are seeing functions from the same
124 // source URI. 130 // source URI.
125 while (i < closures.Length()) { 131 while (i < closures.Length()) {
126 function ^= closures.At(i); 132 function ^= closures.At(i);
127 script = function.script(); 133 script = function.script();
128 url = script.url(); 134 url = script.url();
129 if (!url.Equals(saved_url)) { 135 if (!url.Equals(saved_url)) {
130 break; 136 break;
(...skipping 12 matching lines...) Expand all
143 } 149 }
144 150
145 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); 151 Dart_FileOpenCallback file_open = Isolate::file_open_callback();
146 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); 152 Dart_FileWriteCallback file_write = Isolate::file_write_callback();
147 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); 153 Dart_FileCloseCallback file_close = Isolate::file_close_callback();
148 if ((file_open == NULL) || (file_write == NULL) || (file_close == NULL)) { 154 if ((file_open == NULL) || (file_write == NULL) || (file_close == NULL)) {
149 return; 155 return;
150 } 156 }
151 157
152 JSONStream stream; 158 JSONStream stream;
153 { 159 PrintToJSONStream(isolate, &stream);
154 const GrowableObjectArray& libs = GrowableObjectArray::Handle(
155 isolate, isolate->object_store()->libraries());
156 Library& lib = Library::Handle();
157 Class& cls = Class::Handle();
158 JSONArray jsarr(&stream);
159 for (int i = 0; i < libs.Length(); i++) {
160 lib ^= libs.At(i);
161 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate);
162 while (it.HasNext()) {
163 cls = it.GetNextClass();
164 if (cls.EnsureIsFinalized(isolate) == Error::null()) {
165 // Only classes that have been finalized do have a meaningful list of
166 // functions.
167 PrintClass(cls, jsarr);
168 }
169 }
170 }
171 }
172 160
173 const char* format = "%s/dart-cov-%" Pd "-%" Pd ".json"; 161 const char* format = "%s/dart-cov-%" Pd "-%" Pd ".json";
174 intptr_t pid = OS::ProcessId(); 162 intptr_t pid = OS::ProcessId();
175 intptr_t len = OS::SNPrint(NULL, 0, format, 163 intptr_t len = OS::SNPrint(NULL, 0, format,
176 FLAG_coverage_dir, pid, isolate->main_port()); 164 FLAG_coverage_dir, pid, isolate->main_port());
177 char* filename = Isolate::Current()->current_zone()->Alloc<char>(len + 1); 165 char* filename = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
178 OS::SNPrint(filename, len + 1, format, 166 OS::SNPrint(filename, len + 1, format,
179 FLAG_coverage_dir, pid, isolate->main_port()); 167 FLAG_coverage_dir, pid, isolate->main_port());
180 void* file = (*file_open)(filename, true); 168 void* file = (*file_open)(filename, true);
181 if (file == NULL) { 169 if (file == NULL) {
182 OS::Print("Failed to write coverage file: %s\n", filename); 170 OS::Print("Failed to write coverage file: %s\n", filename);
183 return; 171 return;
184 } 172 }
185 (*file_write)(stream.buffer()->buf(), stream.buffer()->length(), file); 173 (*file_write)(stream.buffer()->buf(), stream.buffer()->length(), file);
186 (*file_close)(file); 174 (*file_close)(file);
187 } 175 }
188 176
177
178 void CodeCoverage::PrintToJSONStream(Isolate* isolate, JSONStream* stream) {
179 const GrowableObjectArray& libs = GrowableObjectArray::Handle(
180 isolate, isolate->object_store()->libraries());
181 Library& lib = Library::Handle();
182 Class& cls = Class::Handle();
183 JSONObject coverage(stream);
184 coverage.AddProperty("type", "CodeCoverage");
185 {
186 JSONArray jsarr(&coverage, "coverage");
187 for (int i = 0; i < libs.Length(); i++) {
188 lib ^= libs.At(i);
189 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate);
190 while (it.HasNext()) {
191 cls = it.GetNextClass();
192 if (cls.EnsureIsFinalized(isolate) == Error::null()) {
193 // Only classes that have been finalized do have a meaningful list of
194 // functions.
195 PrintClass(cls, jsarr);
196 }
197 }
198 }
199 }
200 }
201
202
189 } // namespace dart 203 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/coverage.h ('k') | runtime/vm/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698