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

Side by Side Diff: runtime/vm/service.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, 5 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/object_test.cc ('k') | no next file » | 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/service.h" 5 #include "vm/service.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/globals.h" 8 #include "platform/globals.h"
9 9
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 144 }
145 145
146 private: 146 private:
147 char* name_; 147 char* name_;
148 Dart_ServiceRequestCallback callback_; 148 Dart_ServiceRequestCallback callback_;
149 void* user_data_; 149 void* user_data_;
150 EmbedderServiceHandler* next_; 150 EmbedderServiceHandler* next_;
151 }; 151 };
152 152
153 153
154 class LibraryCoverageFilter : public CoverageFilter {
155 public:
156 explicit LibraryCoverageFilter(const Library& lib) : lib_(lib) {}
157 bool ShouldOutputCoverageFor(const Library& lib,
158 const String& script_url,
159 const Class& cls,
160 const Function& func) const {
161 return lib.raw() == lib_.raw();
162 }
163 private:
164 const Library& lib_;
165 };
166
167
168 class ScriptCoverageFilter : public CoverageFilter {
169 public:
170 explicit ScriptCoverageFilter(const String& script_url)
171 : script_url_(script_url) {}
172 bool ShouldOutputCoverageFor(const Library& lib,
173 const String& script_url,
174 const Class& cls,
175 const Function& func) const {
176 return script_url_.Equals(script_url);
177 }
178 private:
179 const String& script_url_;
180 };
181
182
183 class ClassCoverageFilter : public CoverageFilter {
184 public:
185 explicit ClassCoverageFilter(const Class& cls) : cls_(cls) {}
186 bool ShouldOutputCoverageFor(const Library& lib,
187 const String& script_url,
188 const Class& cls,
189 const Function& func) const {
190 return cls.raw() == cls_.raw();
191 }
192 private:
193 const Class& cls_;
194 };
195
196
154 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 197 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
155 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 198 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
156 return reinterpret_cast<uint8_t*>(new_ptr); 199 return reinterpret_cast<uint8_t*>(new_ptr);
157 } 200 }
158 201
159 202
160 static void SendIsolateServiceMessage(Dart_NativeArguments args) { 203 static void SendIsolateServiceMessage(Dart_NativeArguments args) {
161 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 204 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
162 Isolate* isolate = arguments->isolate(); 205 Isolate* isolate = arguments->isolate();
163 StackZone zone(isolate); 206 StackZone zone(isolate);
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 jsobj.AddProperty("totalCount", count); 1243 jsobj.AddProperty("totalCount", count);
1201 jsobj.AddProperty("sampleCount", storage.Length()); 1244 jsobj.AddProperty("sampleCount", storage.Length());
1202 jsobj.AddProperty("sample", storage); 1245 jsobj.AddProperty("sample", storage);
1203 return true; 1246 return true;
1204 } 1247 }
1205 1248
1206 1249
1207 static bool HandleClassesCoverage(Isolate* isolate, 1250 static bool HandleClassesCoverage(Isolate* isolate,
1208 const Class& cls, 1251 const Class& cls,
1209 JSONStream* stream) { 1252 JSONStream* stream) {
1210 CodeCoverage::PrintJSONForClass(cls, stream); 1253 ClassCoverageFilter cf(cls);
1254 CodeCoverage::PrintJSON(isolate, stream, &cf);
1211 return true; 1255 return true;
1212 } 1256 }
1213 1257
1214 1258
1215 static bool HandleClasses(Isolate* isolate, JSONStream* js) { 1259 static bool HandleClasses(Isolate* isolate, JSONStream* js) {
1216 if (js->num_arguments() == 1) { 1260 if (js->num_arguments() == 1) {
1217 ClassTable* table = isolate->class_table(); 1261 ClassTable* table = isolate->class_table();
1218 JSONObject jsobj(js); 1262 JSONObject jsobj(js);
1219 table->PrintToJSONObject(&jsobj); 1263 table->PrintToJSONObject(&jsobj);
1220 return true; 1264 return true;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 Array::empty_array(), 1327 Array::empty_array(),
1284 Array::empty_array())); 1328 Array::empty_array()));
1285 result.PrintJSON(js, true); 1329 result.PrintJSON(js, true);
1286 return true; 1330 return true;
1287 } 1331 }
1288 1332
1289 1333
1290 static bool HandleLibrariesCoverage(Isolate* isolate, 1334 static bool HandleLibrariesCoverage(Isolate* isolate,
1291 const Library& lib, 1335 const Library& lib,
1292 JSONStream* js) { 1336 JSONStream* js) {
1293 CodeCoverage::PrintJSONForLibrary(lib, Script::Handle(), js); 1337 LibraryCoverageFilter lf(lib);
1338 CodeCoverage::PrintJSON(isolate, js, &lf);
1294 return true; 1339 return true;
1295 } 1340 }
1296 1341
1297 1342
1298 static bool HandleLibraries(Isolate* isolate, JSONStream* js) { 1343 static bool HandleLibraries(Isolate* isolate, JSONStream* js) {
1299 // TODO(johnmccutchan): Support fields and functions on libraries. 1344 // TODO(johnmccutchan): Support fields and functions on libraries.
1300 REQUIRE_COLLECTION_ID("libraries"); 1345 REQUIRE_COLLECTION_ID("libraries");
1301 const GrowableObjectArray& libs = 1346 const GrowableObjectArray& libs =
1302 GrowableObjectArray::Handle(isolate->object_store()->libraries()); 1347 GrowableObjectArray::Handle(isolate->object_store()->libraries());
1303 ASSERT(!libs.IsNull()); 1348 ASSERT(!libs.IsNull());
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 1533
1489 1534
1490 static bool HandleScriptsFetch( 1535 static bool HandleScriptsFetch(
1491 Isolate* isolate, const Script& script, JSONStream* js) { 1536 Isolate* isolate, const Script& script, JSONStream* js) {
1492 script.PrintJSON(js, false); 1537 script.PrintJSON(js, false);
1493 return true; 1538 return true;
1494 } 1539 }
1495 1540
1496 1541
1497 static bool HandleScriptsCoverage( 1542 static bool HandleScriptsCoverage(
1498 Isolate* isolate, const Script& script, JSONStream* js) { 1543 Isolate* isolate, const String& script_url, JSONStream* js) {
1499 CodeCoverage::PrintJSONForScript(script, js); 1544 ScriptCoverageFilter sf(script_url);
1545 CodeCoverage::PrintJSON(isolate, js, &sf);
1500 return true; 1546 return true;
1501 } 1547 }
1502 1548
1503 1549
1504 static bool HandleScripts(Isolate* isolate, JSONStream* js) { 1550 static bool HandleScripts(Isolate* isolate, JSONStream* js) {
1505 if (js->num_arguments() == 1) { 1551 if (js->num_arguments() == 1) {
1506 // Enumerate all scripts. 1552 // Enumerate all scripts.
1507 return HandleScriptsEnumerate(isolate, js); 1553 return HandleScriptsEnumerate(isolate, js);
1508 } 1554 }
1509 // Subcommands of scripts require a valid script id. 1555 // Subcommands of scripts require a valid script id.
1510 const String& id = String::Handle(String::New(js->GetArgument(1))); 1556 const String& id = String::Handle(String::New(js->GetArgument(1)));
1511 ASSERT(!id.IsNull()); 1557 ASSERT(!id.IsNull());
1512 // The id is the url of the script % encoded, decode it. 1558 // The id is the url of the script % encoded, decode it.
1513 String& requested_url = String::Handle(String::DecodeURI(id)); 1559 String& requested_url = String::Handle(String::DecodeURI(id));
1514 Script& script = Script::Handle(); 1560 Script& script = Script::Handle();
1515 script = Script::FindByUrl(requested_url); 1561 // There may exist more than one script object for a given url. Since they all
1516 if (script.IsNull()) { 1562 // have the same properties (source, tokens) we don't care which one we get.
1563 const GrowableObjectArray& libs = GrowableObjectArray::Handle(
1564 isolate, isolate->object_store()->libraries());
1565 Library& lib = Library::Handle();
1566 String& script_url = String::Handle();
1567 bool found = false;
1568 for (intptr_t i = 0; !found && (i < libs.Length()); i++) {
1569 lib ^= libs.At(i);
1570 ASSERT(!lib.IsNull());
1571 const Array& loaded_scripts = Array::Handle(lib.LoadedScripts());
1572 ASSERT(!loaded_scripts.IsNull());
1573 for (intptr_t j = 0; !found && (j < loaded_scripts.Length()); j++) {
1574 script ^= loaded_scripts.At(j);
1575 ASSERT(!script.IsNull());
1576 script_url ^= script.url();
1577 if (script_url.Equals(requested_url)) {
1578 found = true;
1579 }
1580 }
1581 }
1582 if (!found) {
1517 PrintErrorWithKind(js, "NotFoundError", "Cannot find script %s", 1583 PrintErrorWithKind(js, "NotFoundError", "Cannot find script %s",
1518 requested_url.ToCString()); 1584 requested_url.ToCString());
1519 return true; 1585 return true;
1520 } 1586 }
1521 if (js->num_arguments() == 2) { 1587 if (js->num_arguments() == 2) {
1522 // If no subcommand is given, just fetch the script. 1588 // If no subcommand is given, just fetch the script.
1523 return HandleScriptsFetch(isolate, script, js); 1589 return HandleScriptsFetch(isolate, script, js);
1524 } else if (js->num_arguments() == 3) { 1590 } else if (js->num_arguments() == 3) {
1525 const char* arg = js->GetArgument(2); 1591 const char* arg = js->GetArgument(2);
1526 if (strcmp(arg, "coverage") == 0) { 1592 if (strcmp(arg, "coverage") == 0) {
1527 return HandleScriptsCoverage(isolate, script, js); 1593 return HandleScriptsCoverage(isolate, requested_url, js);
1528 } 1594 }
1529 PrintError(js, "Unrecognized subcommand '%s'", arg); 1595 PrintError(js, "Unrecognized subcommand '%s'", arg);
1530 return true; 1596 return true;
1531 } else { 1597 } else {
1532 PrintError(js, "Command too long"); 1598 PrintError(js, "Command too long");
1533 return true; 1599 return true;
1534 } 1600 }
1535 } 1601 }
1536 1602
1537 1603
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 } else { 1785 } else {
1720 PrintError(js, "Invalid tags option value: %s\n", tags_option); 1786 PrintError(js, "Invalid tags option value: %s\n", tags_option);
1721 return true; 1787 return true;
1722 } 1788 }
1723 } 1789 }
1724 Profiler::PrintJSON(isolate, js, full_profile, tag_order); 1790 Profiler::PrintJSON(isolate, js, full_profile, tag_order);
1725 return true; 1791 return true;
1726 } 1792 }
1727 1793
1728 static bool HandleCoverage(Isolate* isolate, JSONStream* js) { 1794 static bool HandleCoverage(Isolate* isolate, JSONStream* js) {
1729 CodeCoverage::PrintJSON(isolate, js); 1795 CodeCoverage::PrintJSON(isolate, js, NULL);
1730 return true; 1796 return true;
1731 } 1797 }
1732 1798
1733 1799
1734 static bool HandleAllocationProfile(Isolate* isolate, JSONStream* js) { 1800 static bool HandleAllocationProfile(Isolate* isolate, JSONStream* js) {
1735 bool should_reset_accumulator = false; 1801 bool should_reset_accumulator = false;
1736 bool should_collect = false; 1802 bool should_collect = false;
1737 if (js->num_arguments() != 1) { 1803 if (js->num_arguments() != 1) {
1738 PrintError(js, "Command too long"); 1804 PrintError(js, "Command too long");
1739 return true; 1805 return true;
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
2202 while (current != NULL) { 2268 while (current != NULL) {
2203 if (strcmp(name, current->name()) == 0) { 2269 if (strcmp(name, current->name()) == 0) {
2204 return current; 2270 return current;
2205 } 2271 }
2206 current = current->next(); 2272 current = current->next();
2207 } 2273 }
2208 return NULL; 2274 return NULL;
2209 } 2275 }
2210 2276
2211 } // namespace dart 2277 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698