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

Side by Side Diff: pkg/analysis_server/lib/src/channel/byte_stream_channel.dart

Issue 951423002: Add more performance tags. (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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library channel.byte_stream; 5 library channel.byte_stream;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import 'package:analysis_server/src/analysis_server.dart';
11 import 'package:analysis_server/src/channel/channel.dart'; 12 import 'package:analysis_server/src/channel/channel.dart';
12 import 'package:analysis_server/src/protocol.dart'; 13 import 'package:analysis_server/src/protocol.dart';
13 import 'package:analyzer/instrumentation/instrumentation.dart'; 14 import 'package:analyzer/instrumentation/instrumentation.dart';
15 import 'package:analyzer/src/generated/utilities_general.dart';
14 16
15 /** 17 /**
16 * Instances of the class [ByteStreamClientChannel] implement a 18 * Instances of the class [ByteStreamClientChannel] implement a
17 * [ClientCommunicationChannel] that uses a stream and a sink (typically, 19 * [ClientCommunicationChannel] that uses a stream and a sink (typically,
18 * standard input and standard output) to communicate with servers. 20 * standard input and standard output) to communicate with servers.
19 */ 21 */
20 class ByteStreamClientChannel implements ClientCommunicationChannel { 22 class ByteStreamClientChannel implements ClientCommunicationChannel {
21 final Stream input; 23 final Stream input;
22 final IOSink output; 24 final IOSink output;
23 25
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 }); 115 });
114 } 116 }
115 117
116 @override 118 @override
117 void sendNotification(Notification notification) { 119 void sendNotification(Notification notification) {
118 // Don't send any further notifications after the communication channel is 120 // Don't send any further notifications after the communication channel is
119 // closed. 121 // closed.
120 if (_closeRequested) { 122 if (_closeRequested) {
121 return; 123 return;
122 } 124 }
123 ServerCommunicationChannel.ToJson.start(); 125 PerformanceTag prevTag =
124 String jsonEncoding = JSON.encode(notification.toJson()); 126 ServerPerformanceStatistics.serverChannel.makeCurrent();
125 ServerCommunicationChannel.ToJson.stop(); 127 try {
126 _outputLine(jsonEncoding); 128 String jsonEncoding = JSON.encode(notification.toJson());
127 _instrumentationService.logNotification(jsonEncoding); 129 _outputLine(jsonEncoding);
130 _instrumentationService.logNotification(jsonEncoding);
131 } finally {
132 prevTag.makeCurrent();
133 }
Brian Wilkerson 2015/02/24 20:07:29 There's a lot of boiler-plate here. How about some
scheglov 2015/02/24 21:49:04 Will do in a separate CL.
128 } 134 }
129 135
130 @override 136 @override
131 void sendResponse(Response response) { 137 void sendResponse(Response response) {
132 // Don't send any further responses after the communication channel is 138 // Don't send any further responses after the communication channel is
133 // closed. 139 // closed.
134 if (_closeRequested) { 140 if (_closeRequested) {
135 return; 141 return;
136 } 142 }
137 ServerCommunicationChannel.ToJson.start(); 143 PerformanceTag prevTag =
138 String jsonEncoding = JSON.encode(response.toJson()); 144 ServerPerformanceStatistics.serverChannel.makeCurrent();
139 ServerCommunicationChannel.ToJson.stop(); 145 try {
140 _outputLine(jsonEncoding); 146 String jsonEncoding = JSON.encode(response.toJson());
141 _instrumentationService.logResponse(jsonEncoding); 147 _outputLine(jsonEncoding);
148 _instrumentationService.logResponse(jsonEncoding);
149 } finally {
150 prevTag.makeCurrent();
151 }
142 } 152 }
143 153
144 /** 154 /**
145 * Send the string [s] to [_output] followed by a newline. 155 * Send the string [s] to [_output] followed by a newline.
146 */ 156 */
147 void _outputLine(String s) { 157 void _outputLine(String s) {
148 _output.writeln(s); 158 _output.writeln(s);
149 } 159 }
150 160
151 /** 161 /**
152 * Read a request from the given [data] and use the given function to handle 162 * Read a request from the given [data] and use the given function to handle
153 * the request. 163 * the request.
154 */ 164 */
155 void _readRequest(Object data, void onRequest(Request request)) { 165 void _readRequest(Object data, void onRequest(Request request)) {
156 // Ignore any further requests after the communication channel is closed. 166 // Ignore any further requests after the communication channel is closed.
157 if (_closed.isCompleted) { 167 if (_closed.isCompleted) {
158 return; 168 return;
159 } 169 }
160 _instrumentationService.logRequest(data); 170 PerformanceTag prevTag =
161 // Parse the string as a JSON descriptor and process the resulting 171 ServerPerformanceStatistics.serverChannel.makeCurrent();
162 // structure as a request. 172 try {
163 ServerCommunicationChannel.FromJson.start(); 173 _instrumentationService.logRequest(data);
164 Request request = new Request.fromString(data); 174 // Parse the string as a JSON descriptor and process the resulting
165 ServerCommunicationChannel.FromJson.stop(); 175 // structure as a request.
166 if (request == null) { 176 Request request = new Request.fromString(data);
167 sendResponse(new Response.invalidRequestFormat()); 177 if (request == null) {
168 return; 178 sendResponse(new Response.invalidRequestFormat());
179 return;
180 }
181 onRequest(request);
182 } finally {
183 prevTag.makeCurrent();
169 } 184 }
170 onRequest(request);
171 } 185 }
172 } 186 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | pkg/analysis_server/lib/src/channel/channel.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698