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 if (!result.IsNull()) { |
| 1634 ASSERT(result.IsString()); |
| 1635 TextBuffer* buffer = js->buffer(); |
| 1636 buffer->AddString(String::Cast(result).ToCString()); |
| 1637 return true; |
| 1638 } |
| 1639 PrintError(js, "Metric %s not found\n", id); |
| 1640 return true; |
| 1641 } |
| 1642 |
| 1643 |
| 1644 static bool HandleMetrics(Isolate* isolate, JSONStream* js) { |
| 1645 if (js->num_arguments() == 1) { |
| 1646 return HandleMetricsList(isolate, js); |
| 1647 } |
| 1648 if (js->num_arguments() > 2) { |
| 1649 PrintError(js, "Command too long"); |
| 1650 return true; |
| 1651 } |
| 1652 const char* arg = js->GetArgument(1); |
| 1653 return HandleMetric(isolate, js, arg); |
| 1654 } |
| 1655 |
| 1656 |
1583 static bool HandleObjects(Isolate* isolate, JSONStream* js) { | 1657 static bool HandleObjects(Isolate* isolate, JSONStream* js) { |
1584 REQUIRE_COLLECTION_ID("objects"); | 1658 REQUIRE_COLLECTION_ID("objects"); |
1585 if (js->num_arguments() < 2) { | 1659 if (js->num_arguments() < 2) { |
1586 PrintError(js, "expected at least 2 arguments but found %" Pd "\n", | 1660 PrintError(js, "expected at least 2 arguments but found %" Pd "\n", |
1587 js->num_arguments()); | 1661 js->num_arguments()); |
1588 return true; | 1662 return true; |
1589 } | 1663 } |
1590 const char* arg = js->GetArgument(1); | 1664 const char* arg = js->GetArgument(1); |
1591 | 1665 |
1592 // Handle special objects first. | 1666 // Handle special objects first. |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2096 { "_echo", HandleIsolateEcho }, | 2170 { "_echo", HandleIsolateEcho }, |
2097 { "", HandleIsolate }, | 2171 { "", HandleIsolate }, |
2098 { "address", HandleAddress }, | 2172 { "address", HandleAddress }, |
2099 { "allocationprofile", HandleAllocationProfile }, | 2173 { "allocationprofile", HandleAllocationProfile }, |
2100 { "classes", HandleClasses }, | 2174 { "classes", HandleClasses }, |
2101 { "code", HandleCode }, | 2175 { "code", HandleCode }, |
2102 { "coverage", HandleCoverage }, | 2176 { "coverage", HandleCoverage }, |
2103 { "debug", HandleDebug }, | 2177 { "debug", HandleDebug }, |
2104 { "heapmap", HandleHeapMap }, | 2178 { "heapmap", HandleHeapMap }, |
2105 { "libraries", HandleLibraries }, | 2179 { "libraries", HandleLibraries }, |
| 2180 { "metrics", HandleMetrics }, |
2106 { "objects", HandleObjects }, | 2181 { "objects", HandleObjects }, |
2107 { "profile", HandleProfile }, | 2182 { "profile", HandleProfile }, |
2108 { "scripts", HandleScripts }, | 2183 { "scripts", HandleScripts }, |
2109 { "stacktrace", HandleStackTrace }, | 2184 { "stacktrace", HandleStackTrace }, |
2110 { "typearguments", HandleTypeArguments }, | 2185 { "typearguments", HandleTypeArguments }, |
2111 }; | 2186 }; |
2112 | 2187 |
2113 | 2188 |
2114 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { | 2189 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { |
2115 intptr_t num_message_handlers = sizeof(isolate_handlers) / | 2190 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) { | 2516 while (current != NULL) { |
2442 if (strcmp(name, current->name()) == 0) { | 2517 if (strcmp(name, current->name()) == 0) { |
2443 return current; | 2518 return current; |
2444 } | 2519 } |
2445 current = current->next(); | 2520 current = current->next(); |
2446 } | 2521 } |
2447 return NULL; | 2522 return NULL; |
2448 } | 2523 } |
2449 | 2524 |
2450 } // namespace dart | 2525 } // namespace dart |
OLD | NEW |