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 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1573 ASSERT(ring != NULL); | 1573 ASSERT(ring != NULL); |
| 1574 intptr_t id = -1; | 1574 intptr_t id = -1; |
| 1575 if (!GetIntegerId(arg, &id)) { | 1575 if (!GetIntegerId(arg, &id)) { |
| 1576 *error = true; | 1576 *error = true; |
| 1577 return Instance::null(); | 1577 return Instance::null(); |
| 1578 } | 1578 } |
| 1579 return ring->GetObjectForId(id); | 1579 return ring->GetObjectForId(id); |
| 1580 } | 1580 } |
| 1581 | 1581 |
| 1582 | 1582 |
| 1583 static RawClass* GetMetricsClass(Isolate* isolate) { | |
| 1584 const Library& prof_lib = | |
| 1585 Library::Handle(isolate, Library::ProfilerLibrary()); | |
| 1586 ASSERT(!prof_lib.IsNull()); | |
| 1587 const String& metrics_cls_name = | |
| 1588 String::Handle(isolate, String::New("Metrics")); | |
| 1589 ASSERT(!metrics_cls_name.IsNull()); | |
| 1590 const Class& metrics_cls = | |
| 1591 Class::Handle(isolate, prof_lib.LookupClass(metrics_cls_name)); | |
| 1592 ASSERT(!metrics_cls.IsNull()); | |
| 1593 return metrics_cls.raw(); | |
| 1594 } | |
| 1595 | |
| 1596 | |
| 1597 static bool HandleMetricsList(Isolate* isolate, JSONStream* js) { | |
| 1598 const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate)); | |
| 1599 const String& print_metrics_name = | |
| 1600 String::Handle(String::New("_printMetrics")); | |
| 1601 ASSERT(!print_metrics_name.IsNull()); | |
| 1602 const Function& print_metrics = Function::Handle( | |
| 1603 isolate, | |
| 1604 metrics_cls.LookupStaticFunctionAllowPrivate(print_metrics_name)); | |
| 1605 ASSERT(!print_metrics.IsNull()); | |
| 1606 const Array& args = Object::empty_array(); | |
| 1607 const Object& result = | |
| 1608 Object::Handle(isolate, DartEntry::InvokeFunction(print_metrics, args)); | |
| 1609 ASSERT(!result.IsNull()); | |
| 1610 ASSERT(result.IsString()); | |
| 1611 TextBuffer* buffer = js->buffer(); | |
| 1612 buffer->AddString(String::Cast(result).ToCString()); | |
| 1613 return true; | |
| 1614 } | |
| 1615 | |
| 1616 | |
| 1617 static bool HandleMetric(Isolate* isolate, JSONStream* js, const char* id) { | |
| 1618 const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate)); | |
| 1619 const String& print_metric_name = | |
| 1620 String::Handle(String::New("_printMetric")); | |
| 1621 ASSERT(!print_metric_name.IsNull()); | |
| 1622 const Function& print_metric = Function::Handle( | |
| 1623 isolate, | |
| 1624 metrics_cls.LookupStaticFunctionAllowPrivate(print_metric_name)); | |
| 1625 ASSERT(!print_metric.IsNull()); | |
| 1626 const String& arg0 = String::Handle(String::New(id)); | |
| 1627 ASSERT(!arg0.IsNull()); | |
| 1628 const Array& args = Array::Handle(Array::New(1)); | |
| 1629 ASSERT(!args.IsNull()); | |
| 1630 args.SetAt(0, arg0); | |
| 1631 const Object& result = | |
| 1632 Object::Handle(isolate, DartEntry::InvokeFunction(print_metric, args)); | |
| 1633 ASSERT(!result.IsNull()); | |
|
turnidge
2014/07/30 19:15:00
You should handle null here. The _printMetric fun
Cutch
2014/07/30 21:55:04
Excellent catch.
| |
| 1634 ASSERT(result.IsString()); | |
| 1635 TextBuffer* buffer = js->buffer(); | |
| 1636 buffer->AddString(String::Cast(result).ToCString()); | |
| 1637 return true; | |
| 1638 } | |
| 1639 | |
| 1640 | |
| 1641 static bool HandleMetrics(Isolate* isolate, JSONStream* js) { | |
| 1642 if (js->num_arguments() == 1) { | |
| 1643 return HandleMetricsList(isolate, js); | |
| 1644 } | |
| 1645 if (js->num_arguments() > 2) { | |
| 1646 PrintError(js, "Command too long"); | |
| 1647 return true; | |
| 1648 } | |
| 1649 const char* arg = js->GetArgument(1); | |
| 1650 return HandleMetric(isolate, js, arg); | |
| 1651 } | |
| 1652 | |
| 1653 | |
| 1583 static bool HandleObjects(Isolate* isolate, JSONStream* js) { | 1654 static bool HandleObjects(Isolate* isolate, JSONStream* js) { |
| 1584 REQUIRE_COLLECTION_ID("objects"); | 1655 REQUIRE_COLLECTION_ID("objects"); |
| 1585 if (js->num_arguments() < 2) { | 1656 if (js->num_arguments() < 2) { |
| 1586 PrintError(js, "expected at least 2 arguments but found %" Pd "\n", | 1657 PrintError(js, "expected at least 2 arguments but found %" Pd "\n", |
| 1587 js->num_arguments()); | 1658 js->num_arguments()); |
| 1588 return true; | 1659 return true; |
| 1589 } | 1660 } |
| 1590 const char* arg = js->GetArgument(1); | 1661 const char* arg = js->GetArgument(1); |
| 1591 | 1662 |
| 1592 // Handle special objects first. | 1663 // Handle special objects first. |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2096 { "_echo", HandleIsolateEcho }, | 2167 { "_echo", HandleIsolateEcho }, |
| 2097 { "", HandleIsolate }, | 2168 { "", HandleIsolate }, |
| 2098 { "address", HandleAddress }, | 2169 { "address", HandleAddress }, |
| 2099 { "allocationprofile", HandleAllocationProfile }, | 2170 { "allocationprofile", HandleAllocationProfile }, |
| 2100 { "classes", HandleClasses }, | 2171 { "classes", HandleClasses }, |
| 2101 { "code", HandleCode }, | 2172 { "code", HandleCode }, |
| 2102 { "coverage", HandleCoverage }, | 2173 { "coverage", HandleCoverage }, |
| 2103 { "debug", HandleDebug }, | 2174 { "debug", HandleDebug }, |
| 2104 { "heapmap", HandleHeapMap }, | 2175 { "heapmap", HandleHeapMap }, |
| 2105 { "libraries", HandleLibraries }, | 2176 { "libraries", HandleLibraries }, |
| 2177 { "metrics", HandleMetrics }, | |
|
turnidge
2014/07/30 19:15:00
Will we ever want to have per-vm metrics instead o
Cutch
2014/07/30 21:55:04
Yes, for example, the number of isolates could be
| |
| 2106 { "objects", HandleObjects }, | 2178 { "objects", HandleObjects }, |
| 2107 { "profile", HandleProfile }, | 2179 { "profile", HandleProfile }, |
| 2108 { "scripts", HandleScripts }, | 2180 { "scripts", HandleScripts }, |
| 2109 { "stacktrace", HandleStackTrace }, | 2181 { "stacktrace", HandleStackTrace }, |
| 2110 { "typearguments", HandleTypeArguments }, | 2182 { "typearguments", HandleTypeArguments }, |
| 2111 }; | 2183 }; |
| 2112 | 2184 |
| 2113 | 2185 |
| 2114 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { | 2186 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { |
| 2115 intptr_t num_message_handlers = sizeof(isolate_handlers) / | 2187 intptr_t num_message_handlers = sizeof(isolate_handlers) / |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2441 while (current != NULL) { | 2513 while (current != NULL) { |
| 2442 if (strcmp(name, current->name()) == 0) { | 2514 if (strcmp(name, current->name()) == 0) { |
| 2443 return current; | 2515 return current; |
| 2444 } | 2516 } |
| 2445 current = current->next(); | 2517 current = current->next(); |
| 2446 } | 2518 } |
| 2447 return NULL; | 2519 return NULL; |
| 2448 } | 2520 } |
| 2449 | 2521 |
| 2450 } // namespace dart | 2522 } // namespace dart |
| OLD | NEW |