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

Side by Side Diff: runtime/vm/service.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 unified diff | Download patch | Annotate | Revision Log
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 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 JSONObject jsobj(js); 1197 JSONObject jsobj(js);
1198 jsobj.AddProperty("type", "InstanceSet"); 1198 jsobj.AddProperty("type", "InstanceSet");
1199 jsobj.AddProperty("id", "instance_set"); 1199 jsobj.AddProperty("id", "instance_set");
1200 jsobj.AddProperty("totalCount", count); 1200 jsobj.AddProperty("totalCount", count);
1201 jsobj.AddProperty("sampleCount", storage.Length()); 1201 jsobj.AddProperty("sampleCount", storage.Length());
1202 jsobj.AddProperty("sample", storage); 1202 jsobj.AddProperty("sample", storage);
1203 return true; 1203 return true;
1204 } 1204 }
1205 1205
1206 1206
1207 static bool HandleClassesCoverage(Isolate* isolate,
1208 const Class& cls,
1209 JSONStream* stream) {
1210 CodeCoverage::PrintJSONForClass(cls, stream);
1211 return true;
1212 }
1213
1214
1207 static bool HandleClasses(Isolate* isolate, JSONStream* js) { 1215 static bool HandleClasses(Isolate* isolate, JSONStream* js) {
1208 if (js->num_arguments() == 1) { 1216 if (js->num_arguments() == 1) {
1209 ClassTable* table = isolate->class_table(); 1217 ClassTable* table = isolate->class_table();
1210 JSONObject jsobj(js); 1218 JSONObject jsobj(js);
1211 table->PrintToJSONObject(&jsobj); 1219 table->PrintToJSONObject(&jsobj);
1212 return true; 1220 return true;
1213 } 1221 }
1214 ASSERT(js->num_arguments() >= 2); 1222 ASSERT(js->num_arguments() >= 2);
1215 intptr_t id; 1223 intptr_t id;
1216 if (!GetIntegerId(js->GetArgument(1), &id)) { 1224 if (!GetIntegerId(js->GetArgument(1), &id)) {
(...skipping 22 matching lines...) Expand all
1239 } else if (strcmp(second, "implicit_closures") == 0) { 1247 } else if (strcmp(second, "implicit_closures") == 0) {
1240 return HandleClassesImplicitClosures(isolate, cls, js); 1248 return HandleClassesImplicitClosures(isolate, cls, js);
1241 } else if (strcmp(second, "dispatchers") == 0) { 1249 } else if (strcmp(second, "dispatchers") == 0) {
1242 return HandleClassesDispatchers(isolate, cls, js); 1250 return HandleClassesDispatchers(isolate, cls, js);
1243 } else if (strcmp(second, "types") == 0) { 1251 } else if (strcmp(second, "types") == 0) {
1244 return HandleClassesTypes(isolate, cls, js); 1252 return HandleClassesTypes(isolate, cls, js);
1245 } else if (strcmp(second, "retained") == 0) { 1253 } else if (strcmp(second, "retained") == 0) {
1246 return HandleClassesRetained(isolate, cls, js); 1254 return HandleClassesRetained(isolate, cls, js);
1247 } else if (strcmp(second, "instances") == 0) { 1255 } else if (strcmp(second, "instances") == 0) {
1248 return HandleClassesInstances(isolate, cls, js); 1256 return HandleClassesInstances(isolate, cls, js);
1257 } else if (strcmp(second, "coverage") == 0) {
1258 return HandleClassesCoverage(isolate, cls, js);
1249 } else { 1259 } else {
1250 PrintError(js, "Invalid sub collection %s", second); 1260 PrintError(js, "Invalid sub collection %s", second);
1251 return true; 1261 return true;
1252 } 1262 }
1253 } 1263 }
1254 UNREACHABLE(); 1264 UNREACHABLE();
1255 return true; 1265 return true;
1256 } 1266 }
1257 1267
1258 1268
(...skipping 11 matching lines...) Expand all
1270 } 1280 }
1271 const String& expr_str = String::Handle(isolate, String::New(expr)); 1281 const String& expr_str = String::Handle(isolate, String::New(expr));
1272 const Object& result = Object::Handle(lib.Evaluate(expr_str, 1282 const Object& result = Object::Handle(lib.Evaluate(expr_str,
1273 Array::empty_array(), 1283 Array::empty_array(),
1274 Array::empty_array())); 1284 Array::empty_array()));
1275 result.PrintJSON(js, true); 1285 result.PrintJSON(js, true);
1276 return true; 1286 return true;
1277 } 1287 }
1278 1288
1279 1289
1290 static bool HandleLibrariesCoverage(Isolate* isolate,
1291 const Library& lib,
1292 JSONStream* js) {
1293 CodeCoverage::PrintJSONForLibrary(lib, Script::Handle(), js);
Ivan Posva 2014/06/26 10:14:33 I find this an awkward API. If you want to factor
1294 return true;
1295 }
1296
1297
1280 static bool HandleLibraries(Isolate* isolate, JSONStream* js) { 1298 static bool HandleLibraries(Isolate* isolate, JSONStream* js) {
1281 // TODO(johnmccutchan): Support fields and functions on libraries. 1299 // TODO(johnmccutchan): Support fields and functions on libraries.
1282 REQUIRE_COLLECTION_ID("libraries"); 1300 REQUIRE_COLLECTION_ID("libraries");
1283 const GrowableObjectArray& libs = 1301 const GrowableObjectArray& libs =
1284 GrowableObjectArray::Handle(isolate->object_store()->libraries()); 1302 GrowableObjectArray::Handle(isolate->object_store()->libraries());
1285 ASSERT(!libs.IsNull()); 1303 ASSERT(!libs.IsNull());
1286 intptr_t id = 0; 1304 intptr_t id = 0;
1287 CHECK_COLLECTION_ID_BOUNDS("libraries", libs.Length(), js->GetArgument(1), 1305 CHECK_COLLECTION_ID_BOUNDS("libraries", libs.Length(), js->GetArgument(1),
1288 id, js); 1306 id, js);
1289 Library& lib = Library::Handle(); 1307 Library& lib = Library::Handle();
1290 lib ^= libs.At(id); 1308 lib ^= libs.At(id);
1291 ASSERT(!lib.IsNull()); 1309 ASSERT(!lib.IsNull());
1292 if (js->num_arguments() == 2) { 1310 if (js->num_arguments() == 2) {
1293 lib.PrintJSON(js, false); 1311 lib.PrintJSON(js, false);
1294 return true; 1312 return true;
1295 } else if (js->num_arguments() >= 3) { 1313 } else if (js->num_arguments() >= 3) {
1296 const char* second = js->GetArgument(2); 1314 const char* second = js->GetArgument(2);
1297 if (strcmp(second, "eval") == 0) { 1315 if (strcmp(second, "eval") == 0) {
1298 return HandleLibrariesEval(isolate, lib, js); 1316 return HandleLibrariesEval(isolate, lib, js);
1317 } else if (strcmp(second, "coverage") == 0) {
1318 return HandleLibrariesCoverage(isolate, lib, js);
1299 } else { 1319 } else {
1300 PrintError(js, "Invalid sub collection %s", second); 1320 PrintError(js, "Invalid sub collection %s", second);
1301 return true; 1321 return true;
1302 } 1322 }
1303 } 1323 }
1304 UNREACHABLE(); 1324 UNREACHABLE();
1305 return true; 1325 return true;
1306 } 1326 }
1307 1327
1308 1328
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 intptr_t num_scripts = loaded_scripts.Length(); 1480 intptr_t num_scripts = loaded_scripts.Length();
1461 for (intptr_t i = 0; i < num_scripts; i++) { 1481 for (intptr_t i = 0; i < num_scripts; i++) {
1462 script ^= loaded_scripts.At(i); 1482 script ^= loaded_scripts.At(i);
1463 members.AddValue(script); 1483 members.AddValue(script);
1464 } 1484 }
1465 } 1485 }
1466 return true; 1486 return true;
1467 } 1487 }
1468 1488
1469 1489
1470 static bool HandleScriptsFetch(Isolate* isolate, JSONStream* js) { 1490 static bool HandleScriptsFetch(
1471 const GrowableObjectArray& libs = 1491 Isolate* isolate, const Script& script, JSONStream* js) {
1472 GrowableObjectArray::Handle(isolate->object_store()->libraries()); 1492 script.PrintJSON(js, false);
1473 int num_libs = libs.Length();
1474 Library &lib = Library::Handle();
1475 Script& script = Script::Handle();
1476 String& url = String::Handle();
1477 const String& id = String::Handle(String::New(js->GetArgument(1)));
1478 ASSERT(!id.IsNull());
1479 // The id is the url of the script % encoded, decode it.
1480 String& requested_url = String::Handle(String::DecodeURI(id));
1481 for (intptr_t i = 0; i < num_libs; i++) {
1482 lib ^= libs.At(i);
1483 ASSERT(!lib.IsNull());
1484 ASSERT(Smi::IsValid(lib.index()));
1485 const Array& loaded_scripts = Array::Handle(lib.LoadedScripts());
1486 ASSERT(!loaded_scripts.IsNull());
1487 intptr_t num_scripts = loaded_scripts.Length();
1488 for (intptr_t i = 0; i < num_scripts; i++) {
1489 script ^= loaded_scripts.At(i);
1490 ASSERT(!script.IsNull());
1491 url ^= script.url();
1492 if (url.Equals(requested_url)) {
1493 script.PrintJSON(js, false);
1494 return true;
1495 }
1496 }
1497 }
1498 PrintErrorWithKind(js, "NotFoundError", "Cannot find script %s",
1499 requested_url.ToCString());
1500 return true; 1493 return true;
1501 } 1494 }
1502 1495
1496
1497 static bool HandleScriptsCoverage(
1498 Isolate* isolate, const Script& script, JSONStream* js) {
1499 CodeCoverage::PrintJSONForScript(script, js);
1500 return true;
1501 }
1502
1503 1503
1504 static bool HandleScripts(Isolate* isolate, JSONStream* js) { 1504 static bool HandleScripts(Isolate* isolate, JSONStream* js) {
1505 if (js->num_arguments() == 1) { 1505 if (js->num_arguments() == 1) {
1506 // Enumerate all scripts. 1506 // Enumerate all scripts.
1507 return HandleScriptsEnumerate(isolate, js); 1507 return HandleScriptsEnumerate(isolate, js);
1508 } else if (js->num_arguments() == 2) { 1508 }
1509 // Fetch specific script. 1509 // Subcommands of scripts require a valid script id.
1510 return HandleScriptsFetch(isolate, js); 1510 const String& id = String::Handle(String::New(js->GetArgument(1)));
1511 ASSERT(!id.IsNull());
1512 // The id is the url of the script % encoded, decode it.
1513 String& requested_url = String::Handle(String::DecodeURI(id));
1514 Script& script = Script::Handle();
1515 script = Script::FindByUrl(requested_url);
1516 if (script.IsNull()) {
1517 PrintErrorWithKind(js, "NotFoundError", "Cannot find script %s",
1518 requested_url.ToCString());
1519 return true;
1520 }
1521 if (js->num_arguments() == 2) {
1522 // If no subcommand is given, just fetch the script.
1523 return HandleScriptsFetch(isolate, script, js);
1524 } else if (js->num_arguments() == 3) {
1525 const char* arg = js->GetArgument(2);
1526 if (strcmp(arg, "coverage") == 0) {
1527 return HandleScriptsCoverage(isolate, script, js);
1528 }
1529 PrintError(js, "Unrecognized subcommand '%s'", arg);
1530 return true;
1511 } else { 1531 } else {
1512 PrintError(js, "Command too long"); 1532 PrintError(js, "Command too long");
1513 return true; 1533 return true;
1514 } 1534 }
1515 } 1535 }
1516 1536
1517 1537
1518 static bool HandleDebugResume(Isolate* isolate, JSONStream* js) { 1538 static bool HandleDebugResume(Isolate* isolate, JSONStream* js) {
1519 if (isolate->message_handler()->paused_on_start()) { 1539 if (isolate->message_handler()->paused_on_start()) {
1520 isolate->message_handler()->set_pause_on_start(false); 1540 isolate->message_handler()->set_pause_on_start(false);
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
2182 while (current != NULL) { 2202 while (current != NULL) {
2183 if (strcmp(name, current->name()) == 0) { 2203 if (strcmp(name, current->name()) == 0) {
2184 return current; 2204 return current;
2185 } 2205 }
2186 current = current->next(); 2206 current = current->next();
2187 } 2207 }
2188 return NULL; 2208 return NULL;
2189 } 2209 }
2190 2210
2191 } // namespace dart 2211 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698