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

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

Issue 1007863003: Allow Observatory debugger to switch isolates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/service_event.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 522
523 523
524 void Service::SetEventMask(uint32_t mask) { 524 void Service::SetEventMask(uint32_t mask) {
525 event_mask_ = mask; 525 event_mask_ = mask;
526 } 526 }
527 527
528 528
529 void Service::SendEvent(intptr_t eventFamilyId, 529 void Service::SendEvent(intptr_t eventFamilyId,
530 intptr_t eventType, 530 intptr_t eventType,
531 const Object& eventMessage) { 531 const Object& eventMessage) {
532 ASSERT(!ServiceIsolate::IsServiceIsolate(Isolate::Current()));
532 if (!ServiceIsolate::IsRunning()) { 533 if (!ServiceIsolate::IsRunning()) {
533 return; 534 return;
534 } 535 }
535 Isolate* isolate = Isolate::Current(); 536 Isolate* isolate = Isolate::Current();
536 ASSERT(isolate != NULL); 537 ASSERT(isolate != NULL);
537 HANDLESCOPE(isolate); 538 HANDLESCOPE(isolate);
538 539
539 // Construct a list of the form [eventFamilyId, eventMessage]. 540 // Construct a list of the form [eventFamilyId, eventMessage].
540 // 541 //
541 // TODO(turnidge): Revisit passing the eventFamilyId here at all. 542 // TODO(turnidge): Revisit passing the eventFamilyId here at all.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 memmove(message.DataAddr(offset), data, size); 585 memmove(message.DataAddr(offset), data, size);
585 offset += size; 586 offset += size;
586 } 587 }
587 ASSERT(offset == total_bytes); 588 ASSERT(offset == total_bytes);
588 // TODO(turnidge): Pass the real eventType here. 589 // TODO(turnidge): Pass the real eventType here.
589 SendEvent(eventFamilyId, 0, message); 590 SendEvent(eventFamilyId, 0, message);
590 } 591 }
591 592
592 593
593 void Service::HandleGCEvent(GCEvent* event) { 594 void Service::HandleGCEvent(GCEvent* event) {
595 if (ServiceIsolate::IsServiceIsolate(Isolate::Current())) {
596 return;
597 }
594 JSONStream js; 598 JSONStream js;
595 event->PrintJSON(&js); 599 event->PrintJSON(&js);
596 const String& message = String::Handle(String::New(js.ToCString())); 600 const String& message = String::Handle(String::New(js.ToCString()));
597 // TODO(turnidge): Pass the real eventType here. 601 // TODO(turnidge): Pass the real eventType here.
598 SendEvent(kEventFamilyGC, 0, message); 602 SendEvent(kEventFamilyGC, 0, message);
599 } 603 }
600 604
601 605
602 void Service::HandleEvent(ServiceEvent* event) { 606 void Service::HandleEvent(ServiceEvent* event) {
603 JSONStream js; 607 JSONStream js;
(...skipping 1827 matching lines...) Expand 10 before | Expand all | Expand 10 after
2431 }; 2435 };
2432 2436
2433 2437
2434 static bool GetVM(Isolate* isolate, JSONStream* js) { 2438 static bool GetVM(Isolate* isolate, JSONStream* js) {
2435 JSONObject jsobj(js); 2439 JSONObject jsobj(js);
2436 jsobj.AddProperty("type", "VM"); 2440 jsobj.AddProperty("type", "VM");
2437 jsobj.AddProperty("id", "vm"); 2441 jsobj.AddProperty("id", "vm");
2438 jsobj.AddProperty("architectureBits", static_cast<intptr_t>(kBitsPerWord)); 2442 jsobj.AddProperty("architectureBits", static_cast<intptr_t>(kBitsPerWord));
2439 jsobj.AddProperty("targetCPU", CPU::Id()); 2443 jsobj.AddProperty("targetCPU", CPU::Id());
2440 jsobj.AddProperty("hostCPU", HostCPUFeatures::hardware()); 2444 jsobj.AddProperty("hostCPU", HostCPUFeatures::hardware());
2441 jsobj.AddPropertyF("date", "%" Pd64 "", OS::GetCurrentTimeMillis());
2442 jsobj.AddProperty("version", Version::String()); 2445 jsobj.AddProperty("version", Version::String());
2443 // Send pid as a string because it allows us to avoid any issues with 2446 // Send pid as a string because it allows us to avoid any issues with
2444 // pids > 53-bits (when consumed by JavaScript). 2447 // pids > 53-bits (when consumed by JavaScript).
2445 // TODO(johnmccutchan): Codify how integers are sent across the service. 2448 // TODO(johnmccutchan): Codify how integers are sent across the service.
2446 jsobj.AddPropertyF("pid", "%" Pd "", OS::ProcessId()); 2449 jsobj.AddPropertyF("pid", "%" Pd "", OS::ProcessId());
2447 jsobj.AddProperty("assertsEnabled", isolate->AssertsEnabled()); 2450 jsobj.AddProperty("assertsEnabled", isolate->AssertsEnabled());
2448 jsobj.AddProperty("typeChecksEnabled", isolate->TypeChecksEnabled()); 2451 jsobj.AddProperty("typeChecksEnabled", isolate->TypeChecksEnabled());
2449 int64_t start_time_micros = Dart::vm_isolate()->start_time(); 2452 int64_t start_time_millis = (Dart::vm_isolate()->start_time() /
2450 int64_t uptime_micros = (OS::GetCurrentTimeMicros() - start_time_micros); 2453 kMicrosecondsPerMillisecond);
2451 double seconds = (static_cast<double>(uptime_micros) / 2454 jsobj.AddProperty64("refreshTime", OS::GetCurrentTimeMillis());
2452 static_cast<double>(kMicrosecondsPerSecond)); 2455 jsobj.AddProperty64("startTime", start_time_millis);
2453 jsobj.AddProperty("uptime", seconds);
2454
2455 // Construct the isolate list. 2456 // Construct the isolate list.
2456 { 2457 {
2457 JSONArray jsarr(&jsobj, "isolates"); 2458 JSONArray jsarr(&jsobj, "isolates");
2458 ServiceIsolateVisitor visitor(&jsarr); 2459 ServiceIsolateVisitor visitor(&jsarr);
2459 Isolate::VisitIsolates(&visitor); 2460 Isolate::VisitIsolates(&visitor);
2460 } 2461 }
2461 return true; 2462 return true;
2462 } 2463 }
2463 2464
2464 2465
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2499 return true; 2500 return true;
2500 } else { 2501 } else {
2501 jsobj.AddProperty("type", "Failure"); 2502 jsobj.AddProperty("type", "Failure");
2502 jsobj.AddProperty("id", ""); 2503 jsobj.AddProperty("id", "");
2503 jsobj.AddProperty("message", error); 2504 jsobj.AddProperty("message", error);
2504 return true; 2505 return true;
2505 } 2506 }
2506 } 2507 }
2507 2508
2508 2509
2510 static const MethodParameter* set_name_params[] = {
2511 ISOLATE_PARAMETER,
2512 new MethodParameter("name", true),
2513 NULL,
2514 };
2515
2516
2517 static bool SetName(Isolate* isolate, JSONStream* js) {
2518 isolate->set_debugger_name(js->LookupParam("name"));
2519 {
2520 ServiceEvent event(isolate, ServiceEvent::kIsolateUpdate);
2521 Service::HandleEvent(&event);
2522 }
2523 JSONObject jsobj(js);
2524 jsobj.AddProperty("type", "Success");
2525 return true;
2526 }
2527
2528
2509 static ServiceMethodDescriptor service_methods_[] = { 2529 static ServiceMethodDescriptor service_methods_[] = {
2510 { "_echo", _Echo, 2530 { "_echo", _Echo,
2511 NULL }, 2531 NULL },
2512 { "_respondWithMalformedJson", _RespondWithMalformedJson, 2532 { "_respondWithMalformedJson", _RespondWithMalformedJson,
2513 NULL }, 2533 NULL },
2514 { "_respondWithMalformedObject", _RespondWithMalformedObject, 2534 { "_respondWithMalformedObject", _RespondWithMalformedObject,
2515 NULL }, 2535 NULL },
2516 { "_triggerEchoEvent", _TriggerEchoEvent, 2536 { "_triggerEchoEvent", _TriggerEchoEvent,
2517 NULL }, 2537 NULL },
2518 { "addBreakpoint", AddBreakpoint, 2538 { "addBreakpoint", AddBreakpoint,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2570 { "getVMMetricList", GetVMMetricList, 2590 { "getVMMetricList", GetVMMetricList,
2571 get_vm_metric_list_params }, 2591 get_vm_metric_list_params },
2572 { "pause", Pause, 2592 { "pause", Pause,
2573 pause_params }, 2593 pause_params },
2574 { "removeBreakpoint", RemoveBreakpoint, 2594 { "removeBreakpoint", RemoveBreakpoint,
2575 remove_breakpoint_params }, 2595 remove_breakpoint_params },
2576 { "resume", Resume, 2596 { "resume", Resume,
2577 resume_params }, 2597 resume_params },
2578 { "requestHeapSnapshot", RequestHeapSnapshot, 2598 { "requestHeapSnapshot", RequestHeapSnapshot,
2579 request_heap_snapshot_params }, 2599 request_heap_snapshot_params },
2580 { "setFlag", SetFlag , 2600 { "setFlag", SetFlag,
2581 set_flags_params }, 2601 set_flags_params },
2602 { "setName", SetName,
2603 set_name_params },
2582 }; 2604 };
2583 2605
2584 2606
2585 ServiceMethodDescriptor* FindMethod(const char* method_name) { 2607 ServiceMethodDescriptor* FindMethod(const char* method_name) {
2586 intptr_t num_methods = sizeof(service_methods_) / 2608 intptr_t num_methods = sizeof(service_methods_) /
2587 sizeof(service_methods_[0]); 2609 sizeof(service_methods_[0]);
2588 for (intptr_t i = 0; i < num_methods; i++) { 2610 for (intptr_t i = 0; i < num_methods; i++) {
2589 ServiceMethodDescriptor& method = service_methods_[i]; 2611 ServiceMethodDescriptor& method = service_methods_[i];
2590 if (strcmp(method_name, method.name) == 0) { 2612 if (strcmp(method_name, method.name) == 0) {
2591 return &method; 2613 return &method;
2592 } 2614 }
2593 } 2615 }
2594 return NULL; 2616 return NULL;
2595 } 2617 }
2596 2618
2597 2619
2598 } // namespace dart 2620 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/service_event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698