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

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

Issue 1241683005: Support piping log data over the service protocol (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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
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 "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "platform/globals.h" 9 #include "platform/globals.h"
10 10
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 Dart_ServiceStreamListenCallback Service::stream_listen_callback_ = NULL; 80 Dart_ServiceStreamListenCallback Service::stream_listen_callback_ = NULL;
81 Dart_ServiceStreamCancelCallback Service::stream_cancel_callback_ = NULL; 81 Dart_ServiceStreamCancelCallback Service::stream_cancel_callback_ = NULL;
82 82
83 83
84 // These are the set of streams known to the core VM. 84 // These are the set of streams known to the core VM.
85 StreamInfo Service::isolate_stream("Isolate"); 85 StreamInfo Service::isolate_stream("Isolate");
86 StreamInfo Service::debug_stream("Debug"); 86 StreamInfo Service::debug_stream("Debug");
87 StreamInfo Service::gc_stream("GC"); 87 StreamInfo Service::gc_stream("GC");
88 StreamInfo Service::echo_stream("_Echo"); 88 StreamInfo Service::echo_stream("_Echo");
89 StreamInfo Service::graph_stream("_Graph"); 89 StreamInfo Service::graph_stream("_Graph");
90 90 StreamInfo Service::logging_stream("Logging");
91 91
92 static StreamInfo* streams_[] = { 92 static StreamInfo* streams_[] = {
93 &Service::isolate_stream, 93 &Service::isolate_stream,
94 &Service::debug_stream, 94 &Service::debug_stream,
95 &Service::gc_stream, 95 &Service::gc_stream,
96 &Service::echo_stream, 96 &Service::echo_stream,
97 &Service::graph_stream, 97 &Service::graph_stream,
98 &Service::logging_stream,
98 }; 99 };
99 100
100 101
101 bool Service::ListenStream(const char* stream_id) { 102 bool Service::ListenStream(const char* stream_id) {
102 if (FLAG_trace_service) { 103 if (FLAG_trace_service) {
103 OS::Print("vm-service: starting stream '%s'\n", 104 OS::Print("vm-service: starting stream '%s'\n",
104 stream_id); 105 stream_id);
105 } 106 }
106 intptr_t num_streams = sizeof(streams_) / 107 intptr_t num_streams = sizeof(streams_) /
107 sizeof(streams_[0]); 108 sizeof(streams_[0]);
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 return; 677 return;
677 } 678 }
678 JSONStream js; 679 JSONStream js;
679 const char* stream_id = event->stream_id(); 680 const char* stream_id = event->stream_id();
680 ASSERT(stream_id != NULL); 681 ASSERT(stream_id != NULL);
681 { 682 {
682 JSONObject jsobj(&js); 683 JSONObject jsobj(&js);
683 jsobj.AddProperty("event", event); 684 jsobj.AddProperty("event", event);
684 jsobj.AddProperty("streamId", stream_id); 685 jsobj.AddProperty("streamId", stream_id);
685 } 686 }
687 PostEvent(stream_id, event->KindAsCString(), &js);
688 }
689
690
691 void Service::PostEvent(const char* stream_id,
692 const char* kind,
693 JSONStream* event) {
694 ASSERT(stream_id != NULL);
695 ASSERT(kind != NULL);
696 ASSERT(event != NULL);
686 697
687 // Message is of the format [<stream id>, <json string>]. 698 // Message is of the format [<stream id>, <json string>].
688 // 699 //
689 // Build the event message in the C heap to avoid dart heap 700 // Build the event message in the C heap to avoid dart heap
690 // allocation. This method can be called while we have acquired a 701 // allocation. This method can be called while we have acquired a
691 // direct pointer to typed data, so we can't allocate here. 702 // direct pointer to typed data, so we can't allocate here.
692 Dart_CObject list_cobj; 703 Dart_CObject list_cobj;
693 Dart_CObject* list_values[2]; 704 Dart_CObject* list_values[2];
694 list_cobj.type = Dart_CObject_kArray; 705 list_cobj.type = Dart_CObject_kArray;
695 list_cobj.value.as_array.length = 2; 706 list_cobj.value.as_array.length = 2;
696 list_cobj.value.as_array.values = list_values; 707 list_cobj.value.as_array.values = list_values;
697 708
698 Dart_CObject stream_id_cobj; 709 Dart_CObject stream_id_cobj;
699 stream_id_cobj.type = Dart_CObject_kString; 710 stream_id_cobj.type = Dart_CObject_kString;
700 stream_id_cobj.value.as_string = const_cast<char*>(stream_id); 711 stream_id_cobj.value.as_string = const_cast<char*>(stream_id);
701 list_values[0] = &stream_id_cobj; 712 list_values[0] = &stream_id_cobj;
702 713
703 Dart_CObject json_cobj; 714 Dart_CObject json_cobj;
704 json_cobj.type = Dart_CObject_kString; 715 json_cobj.type = Dart_CObject_kString;
705 json_cobj.value.as_string = const_cast<char*>(js.ToCString()); 716 json_cobj.value.as_string = const_cast<char*>(event->ToCString());
706 list_values[1] = &json_cobj; 717 list_values[1] = &json_cobj;
707 718
708 if (FLAG_trace_service) { 719 if (FLAG_trace_service) {
709 OS::Print( 720 OS::Print(
710 "vm-service: Pushing event of type %s to stream %s\n", 721 "vm-service: Pushing event of type %s to stream %s\n", kind, stream_id);
711 event->KindAsCString(), stream_id);
712 } 722 }
713 723
714 Dart_PostCObject(ServiceIsolate::Port(), &list_cobj); 724 Dart_PostCObject(ServiceIsolate::Port(), &list_cobj);
715 } 725 }
716 726
717 727
718 class EmbedderServiceHandler { 728 class EmbedderServiceHandler {
719 public: 729 public:
720 explicit EmbedderServiceHandler(const char* name) : name_(NULL), 730 explicit EmbedderServiceHandler(const char* name) : name_(NULL),
721 callback_(NULL), 731 callback_(NULL),
(...skipping 1783 matching lines...) Expand 10 before | Expand all | Expand 10 after
2505 return; 2515 return;
2506 } 2516 }
2507 ServiceEvent event(isolate, ServiceEvent::kEmbedder); 2517 ServiceEvent event(isolate, ServiceEvent::kEmbedder);
2508 event.set_embedder_kind(event_kind); 2518 event.set_embedder_kind(event_kind);
2509 event.set_embedder_stream_id(stream_id); 2519 event.set_embedder_stream_id(stream_id);
2510 event.set_bytes(bytes, bytes_len); 2520 event.set_bytes(bytes, bytes_len);
2511 Service::HandleEvent(&event); 2521 Service::HandleEvent(&event);
2512 } 2522 }
2513 2523
2514 2524
2525 void Service::SendLogEvent(Isolate* isolate,
2526 int64_t sequence_number,
2527 int64_t timestamp,
2528
2529 intptr_t level,
2530 const String& name,
2531 const String& message,
2532 const Instance& zone,
2533 const Object& error,
2534 const Instance& stack_trace) {
turnidge 2015/07/17 00:19:55 Can this work like most of the other ServiceEvents
Cutch 2015/07/17 00:50:13 I deliberately didn't make this work like the othe
2535 ServiceEvent service_event(isolate, ServiceEvent::kLogging);
2536 JSONStream js;
2537 const char* stream_id = service_event.stream_id();
2538 ASSERT(stream_id != NULL);
2539 {
2540 JSONObject jsobj(&js);
2541 jsobj.AddProperty("streamId", stream_id);
2542 {
2543 JSONObject event(&jsobj, "event");
2544 // Print header.
2545 service_event.PrintJSONHeader(&event);
2546 {
2547 JSONObject logRecord(&event, "logRecord");
2548 event.AddProperty64("sequenceNumber", sequence_number);
2549 event.AddPropertyTimeMillis("time", timestamp);
2550 event.AddProperty64("level", level);
2551 event.AddProperty("loggerName", name);
2552 event.AddProperty("message", message);
2553 event.AddProperty("zone", zone);
2554 event.AddProperty("error", error);
2555 event.AddProperty("stackTrace", stack_trace);
turnidge 2015/07/17 00:19:54 This stuff would move into the ServiceEvent::Print
Cutch 2015/07/17 00:50:13 Acknowledged.
2556 }
2557 }
2558 }
2559 Service::PostEvent(stream_id, service_event.KindAsCString(), &js);
2560 }
2561
2562
2515 class ContainsAddressVisitor : public FindObjectVisitor { 2563 class ContainsAddressVisitor : public FindObjectVisitor {
2516 public: 2564 public:
2517 ContainsAddressVisitor(Isolate* isolate, uword addr) 2565 ContainsAddressVisitor(Isolate* isolate, uword addr)
2518 : FindObjectVisitor(isolate), addr_(addr) { } 2566 : FindObjectVisitor(isolate), addr_(addr) { }
2519 virtual ~ContainsAddressVisitor() { } 2567 virtual ~ContainsAddressVisitor() { }
2520 2568
2521 virtual uword filter_addr() const { return addr_; } 2569 virtual uword filter_addr() const { return addr_; }
2522 2570
2523 virtual bool FindObject(RawObject* obj) const { 2571 virtual bool FindObject(RawObject* obj) const {
2524 // Free list elements are not real objects, so skip them. 2572 // Free list elements are not real objects, so skip them.
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
3014 ServiceMethodDescriptor& method = service_methods_[i]; 3062 ServiceMethodDescriptor& method = service_methods_[i];
3015 if (strcmp(method_name, method.name) == 0) { 3063 if (strcmp(method_name, method.name) == 0) {
3016 return &method; 3064 return &method;
3017 } 3065 }
3018 } 3066 }
3019 return NULL; 3067 return NULL;
3020 } 3068 }
3021 3069
3022 3070
3023 } // namespace dart 3071 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698