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

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

Issue 1294023009: Switch to a VM wide timeline recorder (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 "platform/assert.h" 5 #include "platform/assert.h"
6 6
7 #include "vm/dart_entry.h" 7 #include "vm/dart_entry.h"
8 #include "vm/debugger.h" 8 #include "vm/debugger.h"
9 #include "vm/json_stream.h" 9 #include "vm/json_stream.h"
10 #include "vm/message.h" 10 #include "vm/message.h"
11 #include "vm/metrics.h" 11 #include "vm/metrics.h"
12 #include "vm/object.h" 12 #include "vm/object.h"
13 #include "vm/service_event.h" 13 #include "vm/service_event.h"
14 #include "vm/service.h" 14 #include "vm/service.h"
15 #include "vm/timeline.h" 15 #include "vm/timeline.h"
16 #include "vm/unicode.h" 16 #include "vm/unicode.h"
17 17
18 18
19 namespace dart { 19 namespace dart {
20 20
21 DECLARE_FLAG(bool, trace_service); 21 DECLARE_FLAG(bool, trace_service);
22 22
23 JSONStream::JSONStream(intptr_t buf_size) 23 JSONStream::JSONStream(intptr_t buf_size)
24 : open_objects_(0), 24 : open_objects_(0),
25 buffer_(buf_size), 25 buffer_(buf_size),
26 default_id_zone_(Isolate::Current()->object_id_ring(), 26 default_id_zone_(),
27 ObjectIdRing::kAllocateId),
28 id_zone_(&default_id_zone_), 27 id_zone_(&default_id_zone_),
29 reply_port_(ILLEGAL_PORT), 28 reply_port_(ILLEGAL_PORT),
30 seq_(Instance::Handle(Instance::null())), 29 seq_(NULL),
31 method_(""), 30 method_(""),
32 param_keys_(NULL), 31 param_keys_(NULL),
33 param_values_(NULL), 32 param_values_(NULL),
34 num_params_(0) { 33 num_params_(0) {
34 ObjectIdRing* ring = NULL;
35 Isolate* isolate = Isolate::Current();
36 if (isolate != NULL) {
37 ring = isolate->object_id_ring();
38 }
39 default_id_zone_.Init(ring, ObjectIdRing::kAllocateId);
35 } 40 }
36 41
37 42
38 JSONStream::~JSONStream() { 43 JSONStream::~JSONStream() {
39 } 44 }
40 45
41 46
42 void JSONStream::Setup(Zone* zone, 47 void JSONStream::Setup(Zone* zone,
43 Dart_Port reply_port, 48 Dart_Port reply_port,
44 const Instance& seq, 49 const Instance& seq,
45 const String& method, 50 const String& method,
46 const Array& param_keys, 51 const Array& param_keys,
47 const Array& param_values) { 52 const Array& param_values) {
48 set_reply_port(reply_port); 53 set_reply_port(reply_port);
49 seq_ ^= seq.raw(); 54 seq_ = &Instance::ZoneHandle(seq.raw());
50 method_ = method.ToCString(); 55 method_ = method.ToCString();
51 56
52 String& string_iterator = String::Handle(); 57 String& string_iterator = String::Handle();
53 if (param_keys.Length() > 0) { 58 if (param_keys.Length() > 0) {
54 ASSERT(param_keys.Length() == param_values.Length()); 59 ASSERT(param_keys.Length() == param_values.Length());
55 const char** param_keys_native = 60 const char** param_keys_native =
56 zone->Alloc<const char*>(param_keys.Length()); 61 zone->Alloc<const char*>(param_keys.Length());
57 const char** param_values_native = 62 const char** param_values_native =
58 zone->Alloc<const char*>(param_keys.Length()); 63 zone->Alloc<const char*>(param_keys.Length());
59 for (intptr_t i = 0; i < param_keys.Length(); i++) { 64 for (intptr_t i = 0; i < param_keys.Length(); i++) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 173
169 174
170 void JSONStream::PostReply() { 175 void JSONStream::PostReply() {
171 Dart_Port port = reply_port(); 176 Dart_Port port = reply_port();
172 ASSERT(port != ILLEGAL_PORT); 177 ASSERT(port != ILLEGAL_PORT);
173 set_reply_port(ILLEGAL_PORT); // Prevent double replies. 178 set_reply_port(ILLEGAL_PORT); // Prevent double replies.
174 int64_t process_delta_micros = 0; 179 int64_t process_delta_micros = 0;
175 if (FLAG_trace_service) { 180 if (FLAG_trace_service) {
176 process_delta_micros = OS::GetCurrentTimeMicros() - setup_time_micros_; 181 process_delta_micros = OS::GetCurrentTimeMicros() - setup_time_micros_;
177 } 182 }
178 183 ASSERT(seq_ != NULL);
179 if (seq_.IsString()) { 184 if (seq_->IsString()) {
180 const String& str = String::Cast(seq_); 185 const String& str = String::Cast(*seq_);
181 PrintProperty("id", str.ToCString()); 186 PrintProperty("id", str.ToCString());
182 } else if (seq_.IsInteger()) { 187 } else if (seq_->IsInteger()) {
183 const Integer& integer = Integer::Cast(seq_); 188 const Integer& integer = Integer::Cast(*seq_);
184 PrintProperty64("id", integer.AsInt64Value()); 189 PrintProperty64("id", integer.AsInt64Value());
185 } else if (seq_.IsDouble()) { 190 } else if (seq_->IsDouble()) {
186 const Double& dbl = Double::Cast(seq_); 191 const Double& dbl = Double::Cast(*seq_);
187 PrintProperty("id", dbl.value()); 192 PrintProperty("id", dbl.value());
188 } else if (seq_.IsNull()) { 193 } else if (seq_->IsNull()) {
189 // JSON-RPC 2.0 says that a request with a null ID shouldn't get a reply. 194 // JSON-RPC 2.0 says that a request with a null ID shouldn't get a reply.
190 PostNullReply(port); 195 PostNullReply(port);
191 return; 196 return;
192 } 197 }
193 buffer_.AddChar('}'); 198 buffer_.AddChar('}');
194 199
195 const String& reply = String::Handle(String::New(ToCString())); 200 const String& reply = String::Handle(String::New(ToCString()));
196 ASSERT(!reply.IsNull()); 201 ASSERT(!reply.IsNull());
197 202
198 uint8_t* data = NULL; 203 uint8_t* data = NULL;
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); 728 intptr_t len2 = OS::VSNPrint(p, len+1, format, args);
724 va_end(args); 729 va_end(args);
725 ASSERT(len == len2); 730 ASSERT(len == len2);
726 stream_->buffer_.AddChar('"'); 731 stream_->buffer_.AddChar('"');
727 stream_->AddEscapedUTF8String(p); 732 stream_->AddEscapedUTF8String(p);
728 stream_->buffer_.AddChar('"'); 733 stream_->buffer_.AddChar('"');
729 free(p); 734 free(p);
730 } 735 }
731 736
732 } // namespace dart 737 } // namespace dart
OLDNEW
« runtime/vm/dart.cc ('K') | « runtime/vm/json_stream.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698