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