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

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
« no previous file with comments | « runtime/vm/service.h ('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 "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 intptr_t level,
2529 const String& name,
2530 const String& message,
2531 const Instance& zone,
2532 const Object& error,
2533 const Instance& stack_trace) {
2534 ServiceEvent::LogRecord log_record;
2535 log_record.sequence_number = sequence_number;
2536 log_record.timestamp = timestamp;
2537 log_record.level = level;
2538 log_record.name = &name;
2539 log_record.message = &message;
2540 log_record.zone = &zone;
2541 log_record.error = &error;
2542 log_record.stack_trace = &stack_trace;
2543 ServiceEvent event(isolate, ServiceEvent::kLogging);
2544 event.set_log_record(log_record);
2545 Service::HandleEvent(&event);
2546 }
2547
2548
2515 class ContainsAddressVisitor : public FindObjectVisitor { 2549 class ContainsAddressVisitor : public FindObjectVisitor {
2516 public: 2550 public:
2517 ContainsAddressVisitor(Isolate* isolate, uword addr) 2551 ContainsAddressVisitor(Isolate* isolate, uword addr)
2518 : FindObjectVisitor(isolate), addr_(addr) { } 2552 : FindObjectVisitor(isolate), addr_(addr) { }
2519 virtual ~ContainsAddressVisitor() { } 2553 virtual ~ContainsAddressVisitor() { }
2520 2554
2521 virtual uword filter_addr() const { return addr_; } 2555 virtual uword filter_addr() const { return addr_; }
2522 2556
2523 virtual bool FindObject(RawObject* obj) const { 2557 virtual bool FindObject(RawObject* obj) const {
2524 // Free list elements are not real objects, so skip them. 2558 // 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]; 3048 ServiceMethodDescriptor& method = service_methods_[i];
3015 if (strcmp(method_name, method.name) == 0) { 3049 if (strcmp(method_name, method.name) == 0) {
3016 return &method; 3050 return &method;
3017 } 3051 }
3018 } 3052 }
3019 return NULL; 3053 return NULL;
3020 } 3054 }
3021 3055
3022 3056
3023 } // namespace dart 3057 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/service.h ('k') | runtime/vm/service_event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698