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 1577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 const String& metrics_cls_name = | 1588 const String& metrics_cls_name = |
1589 String::Handle(isolate, String::New("Metrics")); | 1589 String::Handle(isolate, String::New("Metrics")); |
1590 ASSERT(!metrics_cls_name.IsNull()); | 1590 ASSERT(!metrics_cls_name.IsNull()); |
1591 const Class& metrics_cls = | 1591 const Class& metrics_cls = |
1592 Class::Handle(isolate, prof_lib.LookupClass(metrics_cls_name)); | 1592 Class::Handle(isolate, prof_lib.LookupClass(metrics_cls_name)); |
1593 ASSERT(!metrics_cls.IsNull()); | 1593 ASSERT(!metrics_cls.IsNull()); |
1594 return metrics_cls.raw(); | 1594 return metrics_cls.raw(); |
1595 } | 1595 } |
1596 | 1596 |
1597 | 1597 |
| 1598 static bool HandleIsolateMetricsList(Isolate* isolate, JSONStream* js) { |
| 1599 JSONObject obj(js); |
| 1600 obj.AddProperty("type", "MetricList"); |
| 1601 obj.AddProperty("id", "metrics/vm"); |
| 1602 { |
| 1603 JSONArray members(&obj, "members"); |
| 1604 Metric* current = isolate->metrics_list_head(); |
| 1605 while (current != NULL) { |
| 1606 members.AddValue(current); |
| 1607 current = current->next(); |
| 1608 } |
| 1609 } |
| 1610 return true; |
| 1611 } |
| 1612 |
| 1613 |
| 1614 static bool HandleIsolateMetric(Isolate* isolate, |
| 1615 JSONStream* js, |
| 1616 const char* id) { |
| 1617 Metric* current = isolate->metrics_list_head(); |
| 1618 while (current != NULL) { |
| 1619 const char* name = current->name(); |
| 1620 ASSERT(name != NULL); |
| 1621 if (strcmp(name, id) == 0) { |
| 1622 current->PrintJSON(js); |
| 1623 return true; |
| 1624 } |
| 1625 current = current->next(); |
| 1626 } |
| 1627 PrintError(js, "Metric %s not found\n", id); |
| 1628 return true; |
| 1629 } |
| 1630 |
| 1631 |
1598 static bool HandleMetricsList(Isolate* isolate, JSONStream* js) { | 1632 static bool HandleMetricsList(Isolate* isolate, JSONStream* js) { |
1599 const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate)); | 1633 const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate)); |
1600 const String& print_metrics_name = | 1634 const String& print_metrics_name = |
1601 String::Handle(String::New("_printMetrics")); | 1635 String::Handle(String::New("_printMetrics")); |
1602 ASSERT(!print_metrics_name.IsNull()); | 1636 ASSERT(!print_metrics_name.IsNull()); |
1603 const Function& print_metrics = Function::Handle( | 1637 const Function& print_metrics = Function::Handle( |
1604 isolate, | 1638 isolate, |
1605 metrics_cls.LookupStaticFunctionAllowPrivate(print_metrics_name)); | 1639 metrics_cls.LookupStaticFunctionAllowPrivate(print_metrics_name)); |
1606 ASSERT(!print_metrics.IsNull()); | 1640 ASSERT(!print_metrics.IsNull()); |
1607 const Array& args = Object::empty_array(); | 1641 const Array& args = Object::empty_array(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1639 } | 1673 } |
1640 PrintError(js, "Metric %s not found\n", id); | 1674 PrintError(js, "Metric %s not found\n", id); |
1641 return true; | 1675 return true; |
1642 } | 1676 } |
1643 | 1677 |
1644 | 1678 |
1645 static bool HandleMetrics(Isolate* isolate, JSONStream* js) { | 1679 static bool HandleMetrics(Isolate* isolate, JSONStream* js) { |
1646 if (js->num_arguments() == 1) { | 1680 if (js->num_arguments() == 1) { |
1647 return HandleMetricsList(isolate, js); | 1681 return HandleMetricsList(isolate, js); |
1648 } | 1682 } |
| 1683 ASSERT(js->num_arguments() > 1); |
| 1684 const char* arg = js->GetArgument(1); |
| 1685 if (strcmp(arg, "vm") == 0) { |
| 1686 if (js->num_arguments() == 2) { |
| 1687 return HandleIsolateMetricsList(isolate, js); |
| 1688 } else { |
| 1689 if (js->num_arguments() > 3) { |
| 1690 PrintError(js, "Command too long"); |
| 1691 return true; |
| 1692 } |
| 1693 return HandleIsolateMetric(isolate, js, js->GetArgument(2)); |
| 1694 } |
| 1695 } |
1649 if (js->num_arguments() > 2) { | 1696 if (js->num_arguments() > 2) { |
1650 PrintError(js, "Command too long"); | 1697 PrintError(js, "Command too long"); |
1651 return true; | 1698 return true; |
1652 } | 1699 } |
1653 const char* arg = js->GetArgument(1); | |
1654 return HandleMetric(isolate, js, arg); | 1700 return HandleMetric(isolate, js, arg); |
1655 } | 1701 } |
1656 | 1702 |
1657 | 1703 |
1658 static bool HandleObjects(Isolate* isolate, JSONStream* js) { | 1704 static bool HandleObjects(Isolate* isolate, JSONStream* js) { |
1659 REQUIRE_COLLECTION_ID("objects"); | 1705 REQUIRE_COLLECTION_ID("objects"); |
1660 if (js->num_arguments() < 2) { | 1706 if (js->num_arguments() < 2) { |
1661 PrintError(js, "expected at least 2 arguments but found %" Pd "\n", | 1707 PrintError(js, "expected at least 2 arguments but found %" Pd "\n", |
1662 js->num_arguments()); | 1708 js->num_arguments()); |
1663 return true; | 1709 return true; |
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2525 while (current != NULL) { | 2571 while (current != NULL) { |
2526 if (strcmp(name, current->name()) == 0) { | 2572 if (strcmp(name, current->name()) == 0) { |
2527 return current; | 2573 return current; |
2528 } | 2574 } |
2529 current = current->next(); | 2575 current = current->next(); |
2530 } | 2576 } |
2531 return NULL; | 2577 return NULL; |
2532 } | 2578 } |
2533 | 2579 |
2534 } // namespace dart | 2580 } // namespace dart |
OLD | NEW |