Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: runtime/vm/service.cc

Issue 464953002: Add VMMetric and some sample metrics (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1576 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 const String& metrics_cls_name = 1587 const String& metrics_cls_name =
1588 String::Handle(isolate, String::New("Metrics")); 1588 String::Handle(isolate, String::New("Metrics"));
1589 ASSERT(!metrics_cls_name.IsNull()); 1589 ASSERT(!metrics_cls_name.IsNull());
1590 const Class& metrics_cls = 1590 const Class& metrics_cls =
1591 Class::Handle(isolate, prof_lib.LookupClass(metrics_cls_name)); 1591 Class::Handle(isolate, prof_lib.LookupClass(metrics_cls_name));
1592 ASSERT(!metrics_cls.IsNull()); 1592 ASSERT(!metrics_cls.IsNull());
1593 return metrics_cls.raw(); 1593 return metrics_cls.raw();
1594 } 1594 }
1595 1595
1596 1596
1597 static bool HandleVMMetricsList(Isolate* isolate, JSONStream* js) {
1598 JSONObject obj(js);
1599 obj.AddProperty("type", "MetricList");
1600 obj.AddProperty("id", "metrics/vm");
1601 {
1602 JSONArray members(&obj, "members");
1603 VMMetric* current = isolate->metrics_list_head();
1604 while (current != NULL) {
1605 members.AddValue(current);
1606 current = current->next();
1607 }
1608 }
1609 return true;
1610 }
1611
1612
1613 static bool HandleVMMetric(Isolate* isolate, JSONStream* js, const char* id) {
1614 VMMetric* current = isolate->metrics_list_head();
1615 while (current != NULL) {
1616 const char* name = current->name();
1617 ASSERT(name != NULL);
1618 if (strcmp(name, id) == 0) {
1619 current->PrintJSON(js);
1620 return true;
1621 }
1622 current = current->next();
1623 }
1624 return false;
1625 }
1626
1627
1597 static bool HandleMetricsList(Isolate* isolate, JSONStream* js) { 1628 static bool HandleMetricsList(Isolate* isolate, JSONStream* js) {
1598 const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate)); 1629 const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate));
1599 const String& print_metrics_name = 1630 const String& print_metrics_name =
1600 String::Handle(String::New("_printMetrics")); 1631 String::Handle(String::New("_printMetrics"));
1601 ASSERT(!print_metrics_name.IsNull()); 1632 ASSERT(!print_metrics_name.IsNull());
1602 const Function& print_metrics = Function::Handle( 1633 const Function& print_metrics = Function::Handle(
1603 isolate, 1634 isolate,
1604 metrics_cls.LookupStaticFunctionAllowPrivate(print_metrics_name)); 1635 metrics_cls.LookupStaticFunctionAllowPrivate(print_metrics_name));
1605 ASSERT(!print_metrics.IsNull()); 1636 ASSERT(!print_metrics.IsNull());
1606 const Array& args = Object::empty_array(); 1637 const Array& args = Object::empty_array();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 } 1669 }
1639 PrintError(js, "Metric %s not found\n", id); 1670 PrintError(js, "Metric %s not found\n", id);
1640 return true; 1671 return true;
1641 } 1672 }
1642 1673
1643 1674
1644 static bool HandleMetrics(Isolate* isolate, JSONStream* js) { 1675 static bool HandleMetrics(Isolate* isolate, JSONStream* js) {
1645 if (js->num_arguments() == 1) { 1676 if (js->num_arguments() == 1) {
1646 return HandleMetricsList(isolate, js); 1677 return HandleMetricsList(isolate, js);
1647 } 1678 }
1679 ASSERT(js->num_arguments() > 1);
1680 const char* arg = js->GetArgument(1);
1681 if (strcmp(arg, "vm") == 0) {
1682 if (js->num_arguments() == 2) {
1683 return HandleVMMetricsList(isolate, js);
1684 } else {
1685 if (js->num_arguments() > 3) {
1686 PrintError(js, "Command too long");
1687 return true;
1688 }
1689 return HandleVMMetric(isolate, js, js->GetArgument(2));
1690 }
1691 }
1648 if (js->num_arguments() > 2) { 1692 if (js->num_arguments() > 2) {
1649 PrintError(js, "Command too long"); 1693 PrintError(js, "Command too long");
1650 return true; 1694 return true;
1651 } 1695 }
1652 const char* arg = js->GetArgument(1);
1653 return HandleMetric(isolate, js, arg); 1696 return HandleMetric(isolate, js, arg);
1654 } 1697 }
1655 1698
1656 1699
1657 static bool HandleObjects(Isolate* isolate, JSONStream* js) { 1700 static bool HandleObjects(Isolate* isolate, JSONStream* js) {
1658 REQUIRE_COLLECTION_ID("objects"); 1701 REQUIRE_COLLECTION_ID("objects");
1659 if (js->num_arguments() < 2) { 1702 if (js->num_arguments() < 2) {
1660 PrintError(js, "expected at least 2 arguments but found %" Pd "\n", 1703 PrintError(js, "expected at least 2 arguments but found %" Pd "\n",
1661 js->num_arguments()); 1704 js->num_arguments());
1662 return true; 1705 return true;
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
2524 while (current != NULL) { 2567 while (current != NULL) {
2525 if (strcmp(name, current->name()) == 0) { 2568 if (strcmp(name, current->name()) == 0) {
2526 return current; 2569 return current;
2527 } 2570 }
2528 current = current->next(); 2571 current = current->next();
2529 } 2572 }
2530 return NULL; 2573 return NULL;
2531 } 2574 }
2532 2575
2533 } // namespace dart 2576 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698