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

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

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

Powered by Google App Engine
This is Rietveld 408576698