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

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

Issue 164503002: Trace VM service requests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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/bin/vmservice/client/HACKING.txt ('k') | no next file » | 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 8
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/coverage.h" 10 #include "vm/coverage.h"
(...skipping 10 matching lines...) Expand all
21 #include "vm/object_id_ring.h" 21 #include "vm/object_id_ring.h"
22 #include "vm/object_store.h" 22 #include "vm/object_store.h"
23 #include "vm/port.h" 23 #include "vm/port.h"
24 #include "vm/profiler.h" 24 #include "vm/profiler.h"
25 #include "vm/stack_frame.h" 25 #include "vm/stack_frame.h"
26 #include "vm/symbols.h" 26 #include "vm/symbols.h"
27 27
28 28
29 namespace dart { 29 namespace dart {
30 30
31 DEFINE_FLAG(bool, trace_service, false, "Trace VM service requests.");
32
31 struct ResourcesEntry { 33 struct ResourcesEntry {
32 const char* path_; 34 const char* path_;
33 const char* resource_; 35 const char* resource_;
34 int length_; 36 int length_;
35 }; 37 };
36 38
37 extern ResourcesEntry __service_resources_[]; 39 extern ResourcesEntry __service_resources_[];
38 40
39 class Resources { 41 class Resources {
40 public: 42 public:
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 path ^= message.At(1); 568 path ^= message.At(1);
567 option_keys ^= message.At(2); 569 option_keys ^= message.At(2);
568 option_values ^= message.At(3); 570 option_values ^= message.At(3);
569 571
570 ASSERT(!path.IsNull()); 572 ASSERT(!path.IsNull());
571 ASSERT(!option_keys.IsNull()); 573 ASSERT(!option_keys.IsNull());
572 ASSERT(!option_values.IsNull()); 574 ASSERT(!option_values.IsNull());
573 // Same number of option keys as values. 575 // Same number of option keys as values.
574 ASSERT(option_keys.Length() == option_values.Length()); 576 ASSERT(option_keys.Length() == option_values.Length());
575 577
576 String& pathSegment = String::Handle(); 578 String& path_segment = String::Handle();
577 if (path.Length() > 0) { 579 if (path.Length() > 0) {
578 pathSegment ^= path.At(0); 580 path_segment ^= path.At(0);
579 } else { 581 } else {
580 pathSegment ^= Symbols::Empty().raw(); 582 path_segment ^= Symbols::Empty().raw();
581 } 583 }
582 ASSERT(!pathSegment.IsNull()); 584 ASSERT(!path_segment.IsNull());
585 const char* path_segment_c = path_segment.ToCString();
583 586
584 IsolateMessageHandler handler = 587 IsolateMessageHandler handler =
585 FindIsolateMessageHandler(pathSegment.ToCString()); 588 FindIsolateMessageHandler(path_segment_c);
589 if (FLAG_trace_service) {
590 const char* handler_text =
591 handler == NULL ? "No handler found." : "Handler found.";
592 OS::Print("Service request <%s> to %s - %s\n",
593 path_segment_c,
594 isolate->name(),
595 handler_text);
596 }
586 { 597 {
587 JSONStream js; 598 JSONStream js;
588 SetupJSONStream(&js, zone.GetZone(), 599 SetupJSONStream(&js, zone.GetZone(),
589 reply_port, path, option_keys, option_values); 600 reply_port, path, option_keys, option_values);
601
590 if (handler == NULL) { 602 if (handler == NULL) {
591 PrintError(&js, "Unrecognized path"); 603 PrintError(&js, "Unrecognized path");
592 PostReply(&js); 604 PostReply(&js);
593 } else { 605 } else {
606 int64_t start_handler_micros = OS::GetCurrentTimeMicros();
607 int64_t delta_micros = 0;
608 bool posted = false;
594 if (handler(isolate, &js)) { 609 if (handler(isolate, &js)) {
610 delta_micros = OS::GetCurrentTimeMicros() - start_handler_micros;
595 // Handler returns true if the reply is ready to be posted. 611 // Handler returns true if the reply is ready to be posted.
596 PostReply(&js); 612 PostReply(&js);
turnidge 2014/02/13 20:49:51 I suggest moving the initial timer code and tracin
613 posted = true;
614 } else {
615 delta_micros = OS::GetCurrentTimeMicros() - start_handler_micros;
616 }
617 if (FLAG_trace_service) {
618 if (posted) {
619 OS::Print("Service request <%s> to %s handled in %" Pd64 " us.\n",
620 path_segment_c,
621 isolate->name(),
622 delta_micros);
623 } else {
624 OS::Print("Service request <%s> to %s deferred in %" Pd64 " us.\n",
625 path_segment_c,
626 isolate->name(),
627 delta_micros);
628 }
597 } 629 }
598 } 630 }
599 } 631 }
600 } 632 }
601 } 633 }
602 634
603 635
604 static bool HandleIsolate(Isolate* isolate, JSONStream* js) { 636 static bool HandleIsolate(Isolate* isolate, JSONStream* js) {
605 isolate->PrintToJSONStream(js); 637 isolate->PrintToJSONStream(js);
606 return true; 638 return true;
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 option_values ^= message.At(3); 1176 option_values ^= message.At(3);
1145 1177
1146 ASSERT(!path.IsNull()); 1178 ASSERT(!path.IsNull());
1147 ASSERT(!option_keys.IsNull()); 1179 ASSERT(!option_keys.IsNull());
1148 ASSERT(!option_values.IsNull()); 1180 ASSERT(!option_values.IsNull());
1149 // Path always has at least one entry in it. 1181 // Path always has at least one entry in it.
1150 ASSERT(path.Length() > 0); 1182 ASSERT(path.Length() > 0);
1151 // Same number of option keys as values. 1183 // Same number of option keys as values.
1152 ASSERT(option_keys.Length() == option_values.Length()); 1184 ASSERT(option_keys.Length() == option_values.Length());
1153 1185
1154 String& pathSegment = String::Handle(); 1186 String& path_segment = String::Handle();
1155 pathSegment ^= path.At(0); 1187 path_segment ^= path.At(0);
1156 ASSERT(!pathSegment.IsNull()); 1188 ASSERT(!path_segment.IsNull());
1189 const char* path_segment_c = path_segment.ToCString();
1190 RootMessageHandler handler =
1191 FindRootMessageHandler(path_segment_c);
1157 1192
1158 RootMessageHandler handler = 1193 if (FLAG_trace_service) {
1159 FindRootMessageHandler(pathSegment.ToCString()); 1194 const char* handler_text =
1195 handler == NULL ? "No handler found." : "Handler found.";
1196 OS::Print("Service request <%s> - %s\n",
1197 path_segment_c,
1198 handler_text);
1199 }
1160 { 1200 {
1161 JSONStream js; 1201 JSONStream js;
1162 SetupJSONStream(&js, zone.GetZone(), 1202 SetupJSONStream(&js, zone.GetZone(),
1163 reply_port, path, option_keys, option_values); 1203 reply_port, path, option_keys, option_values);
1164 if (handler == NULL) { 1204 if (handler == NULL) {
1165 PrintError(&js, "Unrecognized path"); 1205 PrintError(&js, "Unrecognized path");
1166 PostReply(&js); 1206 PostReply(&js);
1167 } else { 1207 } else {
1208 int64_t start_handler_micros = OS::GetCurrentTimeMicros();
1209 int64_t delta_micros = 0;
1210 bool posted = false;
1168 if (handler(&js)) { 1211 if (handler(&js)) {
1212 delta_micros = OS::GetCurrentTimeMicros() - start_handler_micros;
1169 // Handler returns true if the reply is ready to be posted. 1213 // Handler returns true if the reply is ready to be posted.
1170 PostReply(&js); 1214 PostReply(&js);
1215 posted = true;
1216 } else {
1217 delta_micros = OS::GetCurrentTimeMicros() - start_handler_micros;
1218 }
1219 if (FLAG_trace_service) {
1220 if (posted) {
1221 OS::Print("Service request <%s> handled in %" Pd64 " us.\n",
1222 path_segment_c,
1223 delta_micros);
1224 } else {
1225 OS::Print("Service request <%s> deferred in %" Pd64 " us.\n",
1226 path_segment_c,
1227 delta_micros);
1228 }
1171 } 1229 }
1172 } 1230 }
1173 } 1231 }
1174 } 1232 }
1175 } 1233 }
1176 1234
1177 1235
1178 static bool HandleRootEcho(JSONStream* js) { 1236 static bool HandleRootEcho(JSONStream* js) {
1179 JSONObject jsobj(js); 1237 JSONObject jsobj(js);
1180 jsobj.AddProperty("type", "message"); 1238 jsobj.AddProperty("type", "message");
(...skipping 22 matching lines...) Expand all
1203 for (intptr_t i = 0; i < num_message_handlers; i++) { 1261 for (intptr_t i = 0; i < num_message_handlers; i++) {
1204 const RootMessageHandlerEntry& entry = root_handlers[i]; 1262 const RootMessageHandlerEntry& entry = root_handlers[i];
1205 if (!strcmp(command, entry.command)) { 1263 if (!strcmp(command, entry.command)) {
1206 return entry.handler; 1264 return entry.handler;
1207 } 1265 }
1208 } 1266 }
1209 return NULL; 1267 return NULL;
1210 } 1268 }
1211 1269
1212 } // namespace dart 1270 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/vmservice/client/HACKING.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698