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 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 ASSERT(ring != NULL); | 1545 ASSERT(ring != NULL); |
1546 intptr_t id = -1; | 1546 intptr_t id = -1; |
1547 if (!GetIntegerId(arg, &id)) { | 1547 if (!GetIntegerId(arg, &id)) { |
1548 *error = true; | 1548 *error = true; |
1549 return Instance::null(); | 1549 return Instance::null(); |
1550 } | 1550 } |
1551 return ring->GetObjectForId(id); | 1551 return ring->GetObjectForId(id); |
1552 } | 1552 } |
1553 | 1553 |
1554 | 1554 |
| 1555 static RawClass* GetMetricsClass(Isolate* isolate) { |
| 1556 const Library& prof_lib = |
| 1557 Library::Handle(isolate, Library::ProfilerLibrary()); |
| 1558 ASSERT(!prof_lib.IsNull()); |
| 1559 const String& metrics_cls_name = |
| 1560 String::Handle(isolate, String::New("Metrics")); |
| 1561 ASSERT(!metrics_cls_name.IsNull()); |
| 1562 const Class& metrics_cls = |
| 1563 Class::Handle(isolate, prof_lib.LookupClass(metrics_cls_name)); |
| 1564 ASSERT(!metrics_cls.IsNull()); |
| 1565 return metrics_cls.raw(); |
| 1566 } |
| 1567 |
| 1568 |
| 1569 static bool HandleMetricsList(Isolate* isolate, JSONStream* js) { |
| 1570 const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate)); |
| 1571 const String& print_metrics_name = |
| 1572 String::Handle(String::New("_printMetrics")); |
| 1573 ASSERT(!print_metrics_name.IsNull()); |
| 1574 const Function& print_metrics = Function::Handle( |
| 1575 isolate, |
| 1576 metrics_cls.LookupStaticFunctionAllowPrivate(print_metrics_name)); |
| 1577 ASSERT(!print_metrics.IsNull()); |
| 1578 const Array& args = Object::empty_array(); |
| 1579 const Object& result = |
| 1580 Object::Handle(isolate, DartEntry::InvokeFunction(print_metrics, args)); |
| 1581 ASSERT(!result.IsNull()); |
| 1582 ASSERT(result.IsString()); |
| 1583 TextBuffer* buffer = js->buffer(); |
| 1584 buffer->AddString(String::Cast(result).ToCString()); |
| 1585 return true; |
| 1586 } |
| 1587 |
| 1588 |
| 1589 static bool HandleMetric(Isolate* isolate, JSONStream* js, const char* id) { |
| 1590 const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate)); |
| 1591 const String& print_metric_name = |
| 1592 String::Handle(String::New("_printMetric")); |
| 1593 ASSERT(!print_metric_name.IsNull()); |
| 1594 const Function& print_metric = Function::Handle( |
| 1595 isolate, |
| 1596 metrics_cls.LookupStaticFunctionAllowPrivate(print_metric_name)); |
| 1597 ASSERT(!print_metric.IsNull()); |
| 1598 const String& arg0 = String::Handle(String::New(id)); |
| 1599 ASSERT(!arg0.IsNull()); |
| 1600 const Array& args = Array::Handle(Array::New(1)); |
| 1601 ASSERT(!args.IsNull()); |
| 1602 args.SetAt(0, arg0); |
| 1603 const Object& result = |
| 1604 Object::Handle(isolate, DartEntry::InvokeFunction(print_metric, args)); |
| 1605 ASSERT(!result.IsNull()); |
| 1606 ASSERT(result.IsString()); |
| 1607 TextBuffer* buffer = js->buffer(); |
| 1608 buffer->AddString(String::Cast(result).ToCString()); |
| 1609 return metrics_cls.IsClass(); |
| 1610 } |
| 1611 |
| 1612 |
| 1613 static bool HandleMetrics(Isolate* isolate, JSONStream* js) { |
| 1614 if (js->num_arguments() == 1) { |
| 1615 return HandleMetricsList(isolate, js); |
| 1616 } |
| 1617 if (js->num_arguments() > 2) { |
| 1618 PrintError(js, "Command too long"); |
| 1619 return true; |
| 1620 } |
| 1621 const char* arg = js->GetArgument(1); |
| 1622 return HandleMetric(isolate, js, arg); |
| 1623 } |
| 1624 |
| 1625 |
1555 static bool HandleObjects(Isolate* isolate, JSONStream* js) { | 1626 static bool HandleObjects(Isolate* isolate, JSONStream* js) { |
1556 REQUIRE_COLLECTION_ID("objects"); | 1627 REQUIRE_COLLECTION_ID("objects"); |
1557 if (js->num_arguments() < 2) { | 1628 if (js->num_arguments() < 2) { |
1558 PrintError(js, "expected at least 2 arguments but found %" Pd "\n", | 1629 PrintError(js, "expected at least 2 arguments but found %" Pd "\n", |
1559 js->num_arguments()); | 1630 js->num_arguments()); |
1560 return true; | 1631 return true; |
1561 } | 1632 } |
1562 const char* arg = js->GetArgument(1); | 1633 const char* arg = js->GetArgument(1); |
1563 | 1634 |
1564 // Handle special objects first. | 1635 // Handle special objects first. |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2037 { "_echo", HandleIsolateEcho }, | 2108 { "_echo", HandleIsolateEcho }, |
2038 { "", HandleIsolate }, | 2109 { "", HandleIsolate }, |
2039 { "address", HandleAddress }, | 2110 { "address", HandleAddress }, |
2040 { "allocationprofile", HandleAllocationProfile }, | 2111 { "allocationprofile", HandleAllocationProfile }, |
2041 { "classes", HandleClasses }, | 2112 { "classes", HandleClasses }, |
2042 { "code", HandleCode }, | 2113 { "code", HandleCode }, |
2043 { "coverage", HandleCoverage }, | 2114 { "coverage", HandleCoverage }, |
2044 { "debug", HandleDebug }, | 2115 { "debug", HandleDebug }, |
2045 { "heapmap", HandleHeapMap }, | 2116 { "heapmap", HandleHeapMap }, |
2046 { "libraries", HandleLibraries }, | 2117 { "libraries", HandleLibraries }, |
| 2118 { "metrics", HandleMetrics }, |
2047 { "objects", HandleObjects }, | 2119 { "objects", HandleObjects }, |
2048 { "profile", HandleProfile }, | 2120 { "profile", HandleProfile }, |
2049 { "scripts", HandleScripts }, | 2121 { "scripts", HandleScripts }, |
2050 { "stacktrace", HandleStackTrace }, | 2122 { "stacktrace", HandleStackTrace }, |
2051 { "typearguments", HandleTypeArguments }, | 2123 { "typearguments", HandleTypeArguments }, |
2052 }; | 2124 }; |
2053 | 2125 |
2054 | 2126 |
2055 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { | 2127 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { |
2056 intptr_t num_message_handlers = sizeof(isolate_handlers) / | 2128 intptr_t num_message_handlers = sizeof(isolate_handlers) / |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2382 while (current != NULL) { | 2454 while (current != NULL) { |
2383 if (strcmp(name, current->name()) == 0) { | 2455 if (strcmp(name, current->name()) == 0) { |
2384 return current; | 2456 return current; |
2385 } | 2457 } |
2386 current = current->next(); | 2458 current = current->next(); |
2387 } | 2459 } |
2388 return NULL; | 2460 return NULL; |
2389 } | 2461 } |
2390 | 2462 |
2391 } // namespace dart | 2463 } // namespace dart |
OLD | NEW |