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 2400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2411 const String& metrics_cls_name = | 2411 const String& metrics_cls_name = |
2412 String::Handle(isolate, String::New("Metrics")); | 2412 String::Handle(isolate, String::New("Metrics")); |
2413 ASSERT(!metrics_cls_name.IsNull()); | 2413 ASSERT(!metrics_cls_name.IsNull()); |
2414 const Class& metrics_cls = | 2414 const Class& metrics_cls = |
2415 Class::Handle(isolate, prof_lib.LookupClass(metrics_cls_name)); | 2415 Class::Handle(isolate, prof_lib.LookupClass(metrics_cls_name)); |
2416 ASSERT(!metrics_cls.IsNull()); | 2416 ASSERT(!metrics_cls.IsNull()); |
2417 return metrics_cls.raw(); | 2417 return metrics_cls.raw(); |
2418 } | 2418 } |
2419 | 2419 |
2420 | 2420 |
2421 static bool HandleIsolateMetricsList(Isolate* isolate, JSONStream* js) { | 2421 static bool HandleNativeMetricsList(Isolate* isolate, JSONStream* js) { |
2422 JSONObject obj(js); | 2422 JSONObject obj(js); |
2423 obj.AddProperty("type", "MetricList"); | 2423 obj.AddProperty("type", "MetricList"); |
2424 obj.AddProperty("id", "metrics/vm"); | |
2425 { | 2424 { |
2426 JSONArray members(&obj, "members"); | 2425 JSONArray metrics(&obj, "metrics"); |
2427 Metric* current = isolate->metrics_list_head(); | 2426 Metric* current = isolate->metrics_list_head(); |
2428 while (current != NULL) { | 2427 while (current != NULL) { |
2429 members.AddValue(current); | 2428 metrics.AddValue(current); |
2430 current = current->next(); | 2429 current = current->next(); |
2431 } | 2430 } |
2432 } | 2431 } |
2433 return true; | 2432 return true; |
2434 } | 2433 } |
2435 | 2434 |
2436 | 2435 |
2437 static bool HandleIsolateMetric(Isolate* isolate, | 2436 static bool HandleNativeMetric(Isolate* isolate, |
2438 JSONStream* js, | 2437 JSONStream* js, |
2439 const char* id) { | 2438 const char* id) { |
2440 Metric* current = isolate->metrics_list_head(); | 2439 Metric* current = isolate->metrics_list_head(); |
2441 while (current != NULL) { | 2440 while (current != NULL) { |
2442 const char* name = current->name(); | 2441 const char* name = current->name(); |
2443 ASSERT(name != NULL); | 2442 ASSERT(name != NULL); |
2444 if (strcmp(name, id) == 0) { | 2443 if (strcmp(name, id) == 0) { |
2445 current->PrintJSON(js); | 2444 current->PrintJSON(js); |
2446 return true; | 2445 return true; |
2447 } | 2446 } |
2448 current = current->next(); | 2447 current = current->next(); |
2449 } | 2448 } |
2450 PrintError(js, "Metric %s not found\n", id); | 2449 PrintError(js, "Native Metric %s not found\n", id); |
2451 return true; | 2450 return true; |
2452 } | 2451 } |
2453 | 2452 |
2454 | 2453 |
2455 static bool HandleMetricsList(Isolate* isolate, JSONStream* js) { | 2454 static bool HandleDartMetricsList(Isolate* isolate, JSONStream* js) { |
2456 const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate)); | 2455 const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate)); |
2457 const String& print_metrics_name = | 2456 const String& print_metrics_name = |
2458 String::Handle(String::New("_printMetrics")); | 2457 String::Handle(String::New("_printMetrics")); |
2459 ASSERT(!print_metrics_name.IsNull()); | 2458 ASSERT(!print_metrics_name.IsNull()); |
2460 const Function& print_metrics = Function::Handle( | 2459 const Function& print_metrics = Function::Handle( |
2461 isolate, | 2460 isolate, |
2462 metrics_cls.LookupStaticFunctionAllowPrivate(print_metrics_name)); | 2461 metrics_cls.LookupStaticFunctionAllowPrivate(print_metrics_name)); |
2463 ASSERT(!print_metrics.IsNull()); | 2462 ASSERT(!print_metrics.IsNull()); |
2464 const Array& args = Object::empty_array(); | 2463 const Array& args = Object::empty_array(); |
2465 const Object& result = | 2464 const Object& result = |
2466 Object::Handle(isolate, DartEntry::InvokeFunction(print_metrics, args)); | 2465 Object::Handle(isolate, DartEntry::InvokeFunction(print_metrics, args)); |
2467 ASSERT(!result.IsNull()); | 2466 ASSERT(!result.IsNull()); |
2468 ASSERT(result.IsString()); | 2467 ASSERT(result.IsString()); |
2469 TextBuffer* buffer = js->buffer(); | 2468 TextBuffer* buffer = js->buffer(); |
2470 buffer->AddString(String::Cast(result).ToCString()); | 2469 buffer->AddString(String::Cast(result).ToCString()); |
2471 return true; | 2470 return true; |
2472 } | 2471 } |
2473 | 2472 |
2474 | 2473 |
2475 static bool HandleMetric(Isolate* isolate, JSONStream* js, const char* id) { | 2474 static bool HandleDartMetric(Isolate* isolate, JSONStream* js, const char* id) { |
2476 const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate)); | 2475 const Class& metrics_cls = Class::Handle(isolate, GetMetricsClass(isolate)); |
2477 const String& print_metric_name = | 2476 const String& print_metric_name = |
2478 String::Handle(String::New("_printMetric")); | 2477 String::Handle(String::New("_printMetric")); |
2479 ASSERT(!print_metric_name.IsNull()); | 2478 ASSERT(!print_metric_name.IsNull()); |
2480 const Function& print_metric = Function::Handle( | 2479 const Function& print_metric = Function::Handle( |
2481 isolate, | 2480 isolate, |
2482 metrics_cls.LookupStaticFunctionAllowPrivate(print_metric_name)); | 2481 metrics_cls.LookupStaticFunctionAllowPrivate(print_metric_name)); |
2483 ASSERT(!print_metric.IsNull()); | 2482 ASSERT(!print_metric.IsNull()); |
2484 const String& arg0 = String::Handle(String::New(id)); | 2483 const String& arg0 = String::Handle(String::New(id)); |
2485 ASSERT(!arg0.IsNull()); | 2484 ASSERT(!arg0.IsNull()); |
2486 const Array& args = Array::Handle(Array::New(1)); | 2485 const Array& args = Array::Handle(Array::New(1)); |
2487 ASSERT(!args.IsNull()); | 2486 ASSERT(!args.IsNull()); |
2488 args.SetAt(0, arg0); | 2487 args.SetAt(0, arg0); |
2489 const Object& result = | 2488 const Object& result = |
2490 Object::Handle(isolate, DartEntry::InvokeFunction(print_metric, args)); | 2489 Object::Handle(isolate, DartEntry::InvokeFunction(print_metric, args)); |
2491 if (!result.IsNull()) { | 2490 if (!result.IsNull()) { |
2492 ASSERT(result.IsString()); | 2491 ASSERT(result.IsString()); |
2493 TextBuffer* buffer = js->buffer(); | 2492 TextBuffer* buffer = js->buffer(); |
2494 buffer->AddString(String::Cast(result).ToCString()); | 2493 buffer->AddString(String::Cast(result).ToCString()); |
2495 return true; | 2494 return true; |
2496 } | 2495 } |
2497 PrintError(js, "Metric %s not found\n", id); | 2496 PrintError(js, "Dart Metric %s not found\n", id); |
2498 return true; | 2497 return true; |
2499 } | 2498 } |
2500 | 2499 |
2501 | 2500 |
2502 static bool HandleMetrics(Isolate* isolate, JSONStream* js) { | 2501 static bool HandleIsolateGetMetricList(Isolate* isolate, JSONStream* js) { |
2503 if (js->num_arguments() == 1) { | 2502 bool native_metrics = false; |
2504 return HandleMetricsList(isolate, js); | 2503 if (js->HasOption("type")) { |
2505 } | 2504 if (js->OptionIs("type", "Native")) { |
2506 ASSERT(js->num_arguments() > 1); | 2505 native_metrics = true; |
2507 const char* arg = js->GetArgument(1); | 2506 } else if (js->OptionIs("type", "Dart")) { |
2508 if (strcmp(arg, "vm") == 0) { | 2507 native_metrics = false; |
2509 if (js->num_arguments() == 2) { | |
2510 return HandleIsolateMetricsList(isolate, js); | |
2511 } else { | 2508 } else { |
2512 if (js->num_arguments() > 3) { | 2509 PrintError(js, "Invalid 'type' option value: %s\n", |
2513 PrintError(js, "Command too long"); | 2510 js->LookupOption("type")); |
2514 return true; | 2511 return true; |
2515 } | |
2516 return HandleIsolateMetric(isolate, js, js->GetArgument(2)); | |
2517 } | 2512 } |
2518 } | 2513 } else { |
2519 if (js->num_arguments() > 2) { | 2514 PrintError(js, "Expected 'type' option."); |
2520 PrintError(js, "Command too long"); | |
2521 return true; | 2515 return true; |
2522 } | 2516 } |
2523 return HandleMetric(isolate, js, arg); | 2517 if (native_metrics) { |
| 2518 return HandleNativeMetricsList(isolate, js); |
| 2519 } |
| 2520 return HandleDartMetricsList(isolate, js); |
2524 } | 2521 } |
2525 | 2522 |
2526 | 2523 |
| 2524 static bool HandleIsolateGetMetric(Isolate* isolate, JSONStream* js) { |
| 2525 const char* metric_id = js->LookupOption("metricId"); |
| 2526 if (metric_id == NULL) { |
| 2527 PrintError(js, "Expected 'metricId' option."); |
| 2528 return true; |
| 2529 } |
| 2530 // Verify id begins with "metrics/". |
| 2531 static const char* kMetricIdPrefix = "metrics/"; |
| 2532 static intptr_t kMetricIdPrefixLen = strlen(kMetricIdPrefix); |
| 2533 if (strncmp(metric_id, kMetricIdPrefix, kMetricIdPrefixLen) != 0) { |
| 2534 PrintError(js, "Metric %s not found\n", metric_id); |
| 2535 } |
| 2536 // Check if id begins with "metrics/native/". |
| 2537 static const char* kNativeMetricIdPrefix = "metrics/native/"; |
| 2538 static intptr_t kNativeMetricIdPrefixLen = strlen(kNativeMetricIdPrefix); |
| 2539 const bool native_metric = |
| 2540 strncmp(metric_id, kNativeMetricIdPrefix, kNativeMetricIdPrefixLen) == 0; |
| 2541 if (native_metric) { |
| 2542 const char* id = metric_id + kNativeMetricIdPrefixLen; |
| 2543 return HandleNativeMetric(isolate, js, id); |
| 2544 } |
| 2545 const char* id = metric_id + kMetricIdPrefixLen; |
| 2546 return HandleDartMetric(isolate, js, id); |
| 2547 } |
| 2548 |
| 2549 |
| 2550 static bool HandleVMGetMetricList(JSONStream* js) { |
| 2551 return false; |
| 2552 } |
| 2553 |
| 2554 |
| 2555 static bool HandleVMGetMetric(JSONStream* js) { |
| 2556 const char* metric_id = js->LookupOption("metricId"); |
| 2557 if (metric_id == NULL) { |
| 2558 PrintError(js, "Expected 'metricId' option."); |
| 2559 } |
| 2560 return false; |
| 2561 } |
| 2562 |
| 2563 |
2527 static bool HandleObjects(Isolate* isolate, JSONStream* js) { | 2564 static bool HandleObjects(Isolate* isolate, JSONStream* js) { |
2528 REQUIRE_COLLECTION_ID("objects"); | 2565 REQUIRE_COLLECTION_ID("objects"); |
2529 if (js->num_arguments() != 2) { | 2566 if (js->num_arguments() != 2) { |
2530 PrintError(js, "expected at least 2 arguments but found %" Pd "\n", | 2567 PrintError(js, "expected at least 2 arguments but found %" Pd "\n", |
2531 js->num_arguments()); | 2568 js->num_arguments()); |
2532 return true; | 2569 return true; |
2533 } | 2570 } |
2534 const char* arg = js->GetArgument(1); | 2571 const char* arg = js->GetArgument(1); |
2535 | 2572 |
2536 // Handle special non-objects first. | 2573 // Handle special non-objects first. |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2911 return true; | 2948 return true; |
2912 } | 2949 } |
2913 | 2950 |
2914 | 2951 |
2915 static IsolateMessageHandlerEntry isolate_handlers[] = { | 2952 static IsolateMessageHandlerEntry isolate_handlers[] = { |
2916 { "", HandleIsolate }, // getObject | 2953 { "", HandleIsolate }, // getObject |
2917 { "address", HandleAddress }, // to do | 2954 { "address", HandleAddress }, // to do |
2918 { "classes", HandleClasses }, // getObject | 2955 { "classes", HandleClasses }, // getObject |
2919 { "code", HandleCode }, // getObject | 2956 { "code", HandleCode }, // getObject |
2920 { "libraries", HandleLibraries }, // getObject | 2957 { "libraries", HandleLibraries }, // getObject |
2921 { "metrics", HandleMetrics }, // to do - complex? | |
2922 { "objects", HandleObjects }, // getObject | 2958 { "objects", HandleObjects }, // getObject |
2923 { "scripts", HandleScripts }, // getObject | 2959 { "scripts", HandleScripts }, // getObject |
2924 }; | 2960 }; |
2925 | 2961 |
2926 | 2962 |
2927 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { | 2963 static IsolateMessageHandler FindIsolateMessageHandler(const char* command) { |
2928 intptr_t num_message_handlers = sizeof(isolate_handlers) / | 2964 intptr_t num_message_handlers = sizeof(isolate_handlers) / |
2929 sizeof(isolate_handlers[0]); | 2965 sizeof(isolate_handlers[0]); |
2930 for (intptr_t i = 0; i < num_message_handlers; i++) { | 2966 for (intptr_t i = 0; i < num_message_handlers; i++) { |
2931 const IsolateMessageHandlerEntry& entry = isolate_handlers[i]; | 2967 const IsolateMessageHandlerEntry& entry = isolate_handlers[i]; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3027 { "removeBreakpoint", HandleIsolateRemoveBreakpoint }, | 3063 { "removeBreakpoint", HandleIsolateRemoveBreakpoint }, |
3028 { "getCoverage", HandleIsolateGetCoverage }, | 3064 { "getCoverage", HandleIsolateGetCoverage }, |
3029 { "eval", HandleIsolateEval }, | 3065 { "eval", HandleIsolateEval }, |
3030 { "getRetainedSize", HandleIsolateGetRetainedSize }, | 3066 { "getRetainedSize", HandleIsolateGetRetainedSize }, |
3031 { "getRetainingPath", HandleIsolateGetRetainingPath }, | 3067 { "getRetainingPath", HandleIsolateGetRetainingPath }, |
3032 { "getInboundReferences", HandleIsolateGetInboundReferences }, | 3068 { "getInboundReferences", HandleIsolateGetInboundReferences }, |
3033 { "getInstances", HandleIsolateGetInstances }, | 3069 { "getInstances", HandleIsolateGetInstances }, |
3034 { "requestHeapSnapshot", HandleIsolateRequestHeapSnapshot }, | 3070 { "requestHeapSnapshot", HandleIsolateRequestHeapSnapshot }, |
3035 { "getClassList", HandleIsolateGetClassList }, | 3071 { "getClassList", HandleIsolateGetClassList }, |
3036 { "getTypeArgumentsList", HandleIsolateGetTypeArgumentsList }, | 3072 { "getTypeArgumentsList", HandleIsolateGetTypeArgumentsList }, |
| 3073 { "getIsolateMetricList", HandleIsolateGetMetricList }, |
| 3074 { "getIsolateMetric", HandleIsolateGetMetric }, |
3037 { "_echo", HandleIsolateEcho }, | 3075 { "_echo", HandleIsolateEcho }, |
3038 { "_triggerEchoEvent", HandleIsolateTriggerEchoEvent }, | 3076 { "_triggerEchoEvent", HandleIsolateTriggerEchoEvent }, |
3039 { "_respondWithMalformedJson", HandleIsolateRespondWithMalformedJson }, | 3077 { "_respondWithMalformedJson", HandleIsolateRespondWithMalformedJson }, |
3040 { "_respondWithMalformedObject", HandleIsolateRespondWithMalformedObject }, | 3078 { "_respondWithMalformedObject", HandleIsolateRespondWithMalformedObject }, |
3041 }; | 3079 }; |
3042 | 3080 |
3043 | 3081 |
3044 static IsolateMessageHandler FindIsolateMessageHandlerNew(const char* command) { | 3082 static IsolateMessageHandler FindIsolateMessageHandlerNew(const char* command) { |
3045 intptr_t num_message_handlers = sizeof(isolate_handlers_new) / | 3083 intptr_t num_message_handlers = sizeof(isolate_handlers_new) / |
3046 sizeof(isolate_handlers_new[0]); | 3084 sizeof(isolate_handlers_new[0]); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3308 } | 3346 } |
3309 if (FLAG_trace_service) { | 3347 if (FLAG_trace_service) { |
3310 OS::Print("vm-service: No root message handler for <%s>.\n", command); | 3348 OS::Print("vm-service: No root message handler for <%s>.\n", command); |
3311 } | 3349 } |
3312 return NULL; | 3350 return NULL; |
3313 } | 3351 } |
3314 | 3352 |
3315 | 3353 |
3316 static RootMessageHandlerEntry root_handlers_new[] = { | 3354 static RootMessageHandlerEntry root_handlers_new[] = { |
3317 { "getVM", HandleVM }, | 3355 { "getVM", HandleVM }, |
| 3356 { "getVMMetricList", HandleVMGetMetricList }, |
| 3357 { "getVMMetric", HandleVMGetMetric }, |
3318 { "_echo", HandleRootEcho }, | 3358 { "_echo", HandleRootEcho }, |
3319 }; | 3359 }; |
3320 | 3360 |
3321 | 3361 |
3322 static RootMessageHandler FindRootMessageHandlerNew(const char* command) { | 3362 static RootMessageHandler FindRootMessageHandlerNew(const char* command) { |
3323 intptr_t num_message_handlers = sizeof(root_handlers_new) / | 3363 intptr_t num_message_handlers = sizeof(root_handlers_new) / |
3324 sizeof(root_handlers_new[0]); | 3364 sizeof(root_handlers_new[0]); |
3325 for (intptr_t i = 0; i < num_message_handlers; i++) { | 3365 for (intptr_t i = 0; i < num_message_handlers; i++) { |
3326 const RootMessageHandlerEntry& entry = root_handlers_new[i]; | 3366 const RootMessageHandlerEntry& entry = root_handlers_new[i]; |
3327 if (strcmp(command, entry.command) == 0) { | 3367 if (strcmp(command, entry.command) == 0) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3499 while (current != NULL) { | 3539 while (current != NULL) { |
3500 if (strcmp(name, current->name()) == 0) { | 3540 if (strcmp(name, current->name()) == 0) { |
3501 return current; | 3541 return current; |
3502 } | 3542 } |
3503 current = current->next(); | 3543 current = current->next(); |
3504 } | 3544 } |
3505 return NULL; | 3545 return NULL; |
3506 } | 3546 } |
3507 | 3547 |
3508 } // namespace dart | 3548 } // namespace dart |
OLD | NEW |