Index: runtime/vm/service.cc |
diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc |
index 3502951566ed54a0fdd9a227d3fa5437adec8c83..1d53b6f8884afcb5d7db9c486e80c11dd5d44f64 100644 |
--- a/runtime/vm/service.cc |
+++ b/runtime/vm/service.cc |
@@ -1594,6 +1594,37 @@ static RawClass* GetMetricsClass(Isolate* isolate) { |
} |
+static bool HandleVMMetricsList(Isolate* isolate, JSONStream* js) { |
+ JSONObject obj(js); |
+ obj.AddProperty("type", "MetricList"); |
+ obj.AddProperty("id", "metrics/vm"); |
+ { |
+ JSONArray members(&obj, "members"); |
+ VMMetric* current = isolate->metrics_list_head(); |
+ while (current != NULL) { |
+ members.AddValue(current); |
+ current = current->next(); |
+ } |
+ } |
+ return true; |
+} |
+ |
+ |
+static bool HandleVMMetric(Isolate* isolate, JSONStream* js, const char* id) { |
+ VMMetric* current = isolate->metrics_list_head(); |
+ while (current != NULL) { |
+ const char* name = current->name(); |
+ ASSERT(name != NULL); |
+ if (strcmp(name, id) == 0) { |
+ current->PrintJSON(js); |
+ return true; |
+ } |
+ current = current->next(); |
+ } |
+ return false; |
+} |
+ |
+ |
static bool HandleMetricsList(Isolate* isolate, JSONStream* js) { |
const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate)); |
const String& print_metrics_name = |
@@ -1645,11 +1676,23 @@ static bool HandleMetrics(Isolate* isolate, JSONStream* js) { |
if (js->num_arguments() == 1) { |
return HandleMetricsList(isolate, js); |
} |
+ ASSERT(js->num_arguments() > 1); |
+ const char* arg = js->GetArgument(1); |
+ if (strcmp(arg, "vm") == 0) { |
+ if (js->num_arguments() == 2) { |
+ return HandleVMMetricsList(isolate, js); |
+ } else { |
+ if (js->num_arguments() > 3) { |
+ PrintError(js, "Command too long"); |
+ return true; |
+ } |
+ return HandleVMMetric(isolate, js, js->GetArgument(2)); |
+ } |
+ } |
if (js->num_arguments() > 2) { |
PrintError(js, "Command too long"); |
return true; |
} |
- const char* arg = js->GetArgument(1); |
return HandleMetric(isolate, js, arg); |
} |