| OLD | NEW |
| 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 instrumentation; | 5 library instrumentation; |
| 6 | 6 |
| 7 import 'dart:async'; |
| 7 import 'dart:convert'; | 8 import 'dart:convert'; |
| 8 | 9 |
| 9 import 'package:analyzer/task/model.dart'; | 10 import 'package:analyzer/task/model.dart'; |
| 10 | 11 |
| 11 /** | 12 /** |
| 12 * A container with analysis performance constants. | 13 * A container with analysis performance constants. |
| 13 */ | 14 */ |
| 14 class AnalysisPerformanceKind { | 15 class AnalysisPerformanceKind { |
| 15 static const String FULL = 'analysis_full'; | 16 static const String FULL = 'analysis_full'; |
| 16 static const String INCREMENTAL = 'analysis_incremental'; | 17 static const String INCREMENTAL = 'analysis_incremental'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 36 * This method should only be used for logging high priority messages, such as | 37 * This method should only be used for logging high priority messages, such as |
| 37 * exceptions that cause the server to shutdown. | 38 * exceptions that cause the server to shutdown. |
| 38 */ | 39 */ |
| 39 void logWithPriority(String message); | 40 void logWithPriority(String message); |
| 40 | 41 |
| 41 /** | 42 /** |
| 42 * Signal that the client is done communicating with the instrumentation | 43 * Signal that the client is done communicating with the instrumentation |
| 43 * server. This method should be invoked exactly one time and no other methods | 44 * server. This method should be invoked exactly one time and no other methods |
| 44 * should be invoked on this instance after this method has been invoked. | 45 * should be invoked on this instance after this method has been invoked. |
| 45 */ | 46 */ |
| 46 void shutdown(); | 47 Future shutdown(); |
| 47 } | 48 } |
| 48 | 49 |
| 49 /** | 50 /** |
| 50 * The interface used by client code to communicate with an instrumentation | 51 * The interface used by client code to communicate with an instrumentation |
| 51 * server by wrapping an [InstrumentationServer]. | 52 * server by wrapping an [InstrumentationServer]. |
| 52 */ | 53 */ |
| 53 class InstrumentationService { | 54 class InstrumentationService { |
| 54 /** | 55 /** |
| 55 * An instrumentation service that will not log any instrumentation data. | 56 * An instrumentation service that will not log any instrumentation data. |
| 56 */ | 57 */ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 76 * if instrumentation data should not be logged. | 77 * if instrumentation data should not be logged. |
| 77 */ | 78 */ |
| 78 InstrumentationServer _instrumentationServer; | 79 InstrumentationServer _instrumentationServer; |
| 79 | 80 |
| 80 /** | 81 /** |
| 81 * Counter used to generate unique ID's for [logSubprocessStart]. | 82 * Counter used to generate unique ID's for [logSubprocessStart]. |
| 82 */ | 83 */ |
| 83 int _subprocessCounter = 0; | 84 int _subprocessCounter = 0; |
| 84 | 85 |
| 85 /** | 86 /** |
| 86 * Initialize a newly created instrumentation service to comunicate with the | 87 * Initialize a newly created instrumentation service to communicate with the |
| 87 * given [instrumentationServer]. | 88 * given [instrumentationServer]. |
| 88 */ | 89 */ |
| 89 InstrumentationService(this._instrumentationServer); | 90 InstrumentationService(this._instrumentationServer); |
| 90 | 91 |
| 91 /** | 92 /** |
| 92 * Return `true` if this [InstrumentationService] was initialized with a | 93 * Return `true` if this [InstrumentationService] was initialized with a |
| 93 * non-`null` server (and hence instrumentation is active). | 94 * non-`null` server (and hence instrumentation is active). |
| 94 */ | 95 */ |
| 95 bool get isActive => _instrumentationServer != null; | 96 bool get isActive => _instrumentationServer != null; |
| 96 | 97 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 210 |
| 210 /** | 211 /** |
| 211 * Log that a response has been sent to the client. | 212 * Log that a response has been sent to the client. |
| 212 */ | 213 */ |
| 213 void logResponse(String response) { | 214 void logResponse(String response) { |
| 214 _log(TAG_RESPONSE, response); | 215 _log(TAG_RESPONSE, response); |
| 215 } | 216 } |
| 216 | 217 |
| 217 /** | 218 /** |
| 218 * Log the result of executing a subprocess. [subprocessId] should be the | 219 * Log the result of executing a subprocess. [subprocessId] should be the |
| 219 * unique IDreturned by [logSubprocessStart]. | 220 * unique ID returned by [logSubprocessStart]. |
| 220 */ | 221 */ |
| 221 void logSubprocessResult( | 222 void logSubprocessResult( |
| 222 int subprocessId, int exitCode, String stdout, String stderr) { | 223 int subprocessId, int exitCode, String stdout, String stderr) { |
| 223 if (_instrumentationServer != null) { | 224 if (_instrumentationServer != null) { |
| 224 _instrumentationServer.log(_join([ | 225 _instrumentationServer.log(_join([ |
| 225 TAG_SUBPROCESS_RESULT, | 226 TAG_SUBPROCESS_RESULT, |
| 226 subprocessId.toString(), | 227 subprocessId.toString(), |
| 227 exitCode.toString(), | 228 exitCode.toString(), |
| 228 JSON.encode(stdout), | 229 JSON.encode(stdout), |
| 229 JSON.encode(stderr) | 230 JSON.encode(stderr) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 _instrumentationServer | 284 _instrumentationServer |
| 284 .log(_join([TAG_WATCH_EVENT, folderPath, filePath, changeType])); | 285 .log(_join([TAG_WATCH_EVENT, folderPath, filePath, changeType])); |
| 285 } | 286 } |
| 286 } | 287 } |
| 287 | 288 |
| 288 /** | 289 /** |
| 289 * Signal that the client is done communicating with the instrumentation | 290 * Signal that the client is done communicating with the instrumentation |
| 290 * server. This method should be invoked exactly one time and no other methods | 291 * server. This method should be invoked exactly one time and no other methods |
| 291 * should be invoked on this instance after this method has been invoked. | 292 * should be invoked on this instance after this method has been invoked. |
| 292 */ | 293 */ |
| 293 void shutdown() { | 294 Future shutdown() async { |
| 294 if (_instrumentationServer != null) { | 295 if (_instrumentationServer != null) { |
| 295 _instrumentationServer.shutdown(); | 296 await _instrumentationServer.shutdown(); |
| 296 _instrumentationServer = null; | 297 _instrumentationServer = null; |
| 297 } | 298 } |
| 298 } | 299 } |
| 299 | 300 |
| 300 /** | 301 /** |
| 301 * Write an escaped version of the given [field] to the given [buffer]. | 302 * Write an escaped version of the given [field] to the given [buffer]. |
| 302 */ | 303 */ |
| 303 void _escape(StringBuffer buffer, String field) { | 304 void _escape(StringBuffer buffer, String field) { |
| 304 int index = field.indexOf(':'); | 305 int index = field.indexOf(':'); |
| 305 if (index < 0) { | 306 if (index < 0) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 } | 367 } |
| 367 | 368 |
| 368 @override | 369 @override |
| 369 void logWithPriority(String message) { | 370 void logWithPriority(String message) { |
| 370 for (InstrumentationServer server in _servers) { | 371 for (InstrumentationServer server in _servers) { |
| 371 server.logWithPriority(message); | 372 server.logWithPriority(message); |
| 372 } | 373 } |
| 373 } | 374 } |
| 374 | 375 |
| 375 @override | 376 @override |
| 376 void shutdown() { | 377 Future shutdown() async { |
| 377 for (InstrumentationServer server in _servers) { | 378 for (InstrumentationServer server in _servers) { |
| 378 server.shutdown(); | 379 await server.shutdown(); |
| 379 } | 380 } |
| 380 } | 381 } |
| 381 } | 382 } |
| OLD | NEW |