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

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
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 1846 matching lines...) Expand 10 before | Expand all | Expand 10 after
2450 }; 2454 };
2451 2455
2452 2456
2453 static bool GetVM(Isolate* isolate, JSONStream* js) { 2457 static bool GetVM(Isolate* isolate, JSONStream* js) {
2454 JSONObject jsobj(js); 2458 JSONObject jsobj(js);
2455 jsobj.AddProperty("type", "VM"); 2459 jsobj.AddProperty("type", "VM");
2456 jsobj.AddProperty("id", "vm"); 2460 jsobj.AddProperty("id", "vm");
2457 jsobj.AddProperty("architectureBits", static_cast<intptr_t>(kBitsPerWord)); 2461 jsobj.AddProperty("architectureBits", static_cast<intptr_t>(kBitsPerWord));
2458 jsobj.AddProperty("targetCPU", CPU::Id()); 2462 jsobj.AddProperty("targetCPU", CPU::Id());
2459 jsobj.AddProperty("hostCPU", HostCPUFeatures::hardware()); 2463 jsobj.AddProperty("hostCPU", HostCPUFeatures::hardware());
2460 jsobj.AddPropertyF("date", "%" Pd64 "", OS::GetCurrentTimeMillis());
2461 jsobj.AddProperty("version", Version::String()); 2464 jsobj.AddProperty("version", Version::String());
2462 // Send pid as a string because it allows us to avoid any issues with 2465 // Send pid as a string because it allows us to avoid any issues with
2463 // pids > 53-bits (when consumed by JavaScript). 2466 // pids > 53-bits (when consumed by JavaScript).
2464 // TODO(johnmccutchan): Codify how integers are sent across the service. 2467 // TODO(johnmccutchan): Codify how integers are sent across the service.
2465 jsobj.AddPropertyF("pid", "%" Pd "", OS::ProcessId()); 2468 jsobj.AddPropertyF("pid", "%" Pd "", OS::ProcessId());
2466 jsobj.AddProperty("assertsEnabled", isolate->AssertsEnabled()); 2469 jsobj.AddProperty("assertsEnabled", isolate->AssertsEnabled());
2467 jsobj.AddProperty("typeChecksEnabled", isolate->TypeChecksEnabled()); 2470 jsobj.AddProperty("typeChecksEnabled", isolate->TypeChecksEnabled());
2468 int64_t start_time_micros = Dart::vm_isolate()->start_time(); 2471 int64_t start_time_millis = (Dart::vm_isolate()->start_time() /
2469 int64_t uptime_micros = (OS::GetCurrentTimeMicros() - start_time_micros); 2472 kMicrosecondsPerMillisecond);
2470 double seconds = (static_cast<double>(uptime_micros) / 2473 jsobj.AddProperty64("refreshTime", OS::GetCurrentTimeMillis());
2471 static_cast<double>(kMicrosecondsPerSecond)); 2474 jsobj.AddProperty64("startTime", start_time_millis);
2472 jsobj.AddProperty("uptime", seconds);
2473
2474 // Construct the isolate list. 2475 // Construct the isolate list.
2475 { 2476 {
2476 JSONArray jsarr(&jsobj, "isolates"); 2477 JSONArray jsarr(&jsobj, "isolates");
2477 ServiceIsolateVisitor visitor(&jsarr); 2478 ServiceIsolateVisitor visitor(&jsarr);
2478 Isolate::VisitIsolates(&visitor); 2479 Isolate::VisitIsolates(&visitor);
2479 } 2480 }
2480 return true; 2481 return true;
2481 } 2482 }
2482 2483
2483 2484
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 return true; 2519 return true;
2519 } else { 2520 } else {
2520 jsobj.AddProperty("type", "Failure"); 2521 jsobj.AddProperty("type", "Failure");
2521 jsobj.AddProperty("id", ""); 2522 jsobj.AddProperty("id", "");
2522 jsobj.AddProperty("message", error); 2523 jsobj.AddProperty("message", error);
2523 return true; 2524 return true;
2524 } 2525 }
2525 } 2526 }
2526 2527
2527 2528
2529 static const MethodParameter* set_name_params[] = {
2530 ISOLATE_PARAMETER,
2531 new MethodParameter("name", true),
2532 NULL,
2533 };
2534
2535
2536 static bool SetName(Isolate* isolate, JSONStream* js) {
2537 // TODO(turnidge): Do we want to send some sort of isolate update event?
Cutch 2015/03/18 20:05:48 dead TODO.
turnidge 2015/03/26 17:46:58 Done.
2538 isolate->set_debugger_name(js->LookupParam("name"));
2539 {
2540 ServiceEvent event(isolate, ServiceEvent::kIsolateUpdate);
2541 Service::HandleEvent(&event);
2542 }
2543 JSONObject jsobj(js);
2544 jsobj.AddProperty("type", "Success");
2545 return true;
2546 }
2547
2548
2528 static ServiceMethodDescriptor service_methods_[] = { 2549 static ServiceMethodDescriptor service_methods_[] = {
2529 { "_echo", _Echo, 2550 { "_echo", _Echo,
2530 NULL }, 2551 NULL },
2531 { "_respondWithMalformedJson", _RespondWithMalformedJson, 2552 { "_respondWithMalformedJson", _RespondWithMalformedJson,
2532 NULL }, 2553 NULL },
2533 { "_respondWithMalformedObject", _RespondWithMalformedObject, 2554 { "_respondWithMalformedObject", _RespondWithMalformedObject,
2534 NULL }, 2555 NULL },
2535 { "_triggerEchoEvent", _TriggerEchoEvent, 2556 { "_triggerEchoEvent", _TriggerEchoEvent,
2536 NULL }, 2557 NULL },
2537 { "addBreakpoint", AddBreakpoint, 2558 { "addBreakpoint", AddBreakpoint,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2589 { "getVMMetricList", GetVMMetricList, 2610 { "getVMMetricList", GetVMMetricList,
2590 get_vm_metric_list_params }, 2611 get_vm_metric_list_params },
2591 { "pause", Pause, 2612 { "pause", Pause,
2592 pause_params }, 2613 pause_params },
2593 { "removeBreakpoint", RemoveBreakpoint, 2614 { "removeBreakpoint", RemoveBreakpoint,
2594 remove_breakpoint_params }, 2615 remove_breakpoint_params },
2595 { "resume", Resume, 2616 { "resume", Resume,
2596 resume_params }, 2617 resume_params },
2597 { "requestHeapSnapshot", RequestHeapSnapshot, 2618 { "requestHeapSnapshot", RequestHeapSnapshot,
2598 request_heap_snapshot_params }, 2619 request_heap_snapshot_params },
2599 { "setFlag", SetFlag , 2620 { "setFlag", SetFlag,
2600 set_flags_params }, 2621 set_flags_params },
2622 { "setName", SetName,
2623 set_name_params },
2601 }; 2624 };
2602 2625
2603 2626
2604 ServiceMethodDescriptor* FindMethod(const char* method_name) { 2627 ServiceMethodDescriptor* FindMethod(const char* method_name) {
2605 intptr_t num_methods = sizeof(service_methods_) / 2628 intptr_t num_methods = sizeof(service_methods_) /
2606 sizeof(service_methods_[0]); 2629 sizeof(service_methods_[0]);
2607 for (intptr_t i = 0; i < num_methods; i++) { 2630 for (intptr_t i = 0; i < num_methods; i++) {
2608 ServiceMethodDescriptor& method = service_methods_[i]; 2631 ServiceMethodDescriptor& method = service_methods_[i];
2609 if (strcmp(method_name, method.name) == 0) { 2632 if (strcmp(method_name, method.name) == 0) {
2610 return &method; 2633 return &method;
2611 } 2634 }
2612 } 2635 }
2613 return NULL; 2636 return NULL;
2614 } 2637 }
2615 2638
2616 2639
2617 } // namespace dart 2640 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698