| 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:convert'; |
| 8 |
| 7 /** | 9 /** |
| 8 * A container with analysis performance constants. | 10 * A container with analysis performance constants. |
| 9 */ | 11 */ |
| 10 class AnalysisPerformanceKind { | 12 class AnalysisPerformanceKind { |
| 11 static const String FULL = 'analysis_full'; | 13 static const String FULL = 'analysis_full'; |
| 12 static const String INCREMENTAL = 'analysis_incremental'; | 14 static const String INCREMENTAL = 'analysis_incremental'; |
| 13 } | 15 } |
| 14 | 16 |
| 15 /** | 17 /** |
| 16 * The interface used by client code to communicate with an instrumentation | 18 * The interface used by client code to communicate with an instrumentation |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 57 |
| 56 static const String TAG_ANALYSIS_TASK = 'Task'; | 58 static const String TAG_ANALYSIS_TASK = 'Task'; |
| 57 static const String TAG_ERROR = 'Err'; | 59 static const String TAG_ERROR = 'Err'; |
| 58 static const String TAG_EXCEPTION = 'Ex'; | 60 static const String TAG_EXCEPTION = 'Ex'; |
| 59 static const String TAG_FILE_READ = 'Read'; | 61 static const String TAG_FILE_READ = 'Read'; |
| 60 static const String TAG_LOG_ENTRY = 'Log'; | 62 static const String TAG_LOG_ENTRY = 'Log'; |
| 61 static const String TAG_NOTIFICATION = 'Noti'; | 63 static const String TAG_NOTIFICATION = 'Noti'; |
| 62 static const String TAG_PERFORMANCE = 'Perf'; | 64 static const String TAG_PERFORMANCE = 'Perf'; |
| 63 static const String TAG_REQUEST = 'Req'; | 65 static const String TAG_REQUEST = 'Req'; |
| 64 static const String TAG_RESPONSE = 'Res'; | 66 static const String TAG_RESPONSE = 'Res'; |
| 67 static const String TAG_SUBPROCESS_START = 'SPStart'; |
| 68 static const String TAG_SUBPROCESS_RESULT = 'SPResult'; |
| 65 static const String TAG_VERSION = 'Ver'; | 69 static const String TAG_VERSION = 'Ver'; |
| 66 static const String TAG_WATCH_EVENT = 'Watch'; | 70 static const String TAG_WATCH_EVENT = 'Watch'; |
| 67 | 71 |
| 68 /** | 72 /** |
| 69 * The instrumentation server used to communicate with the server, or `null` | 73 * The instrumentation server used to communicate with the server, or `null` |
| 70 * if instrumentation data should not be logged. | 74 * if instrumentation data should not be logged. |
| 71 */ | 75 */ |
| 72 InstrumentationServer _instrumentationServer; | 76 InstrumentationServer _instrumentationServer; |
| 73 | 77 |
| 74 /** | 78 /** |
| 79 * Counter used to generate unique ID's for [logSubprocessStart]. |
| 80 */ |
| 81 int _subprocessCounter = 0; |
| 82 |
| 83 /** |
| 75 * Initialize a newly created instrumentation service to comunicate with the | 84 * Initialize a newly created instrumentation service to comunicate with the |
| 76 * given [instrumentationServer]. | 85 * given [instrumentationServer]. |
| 77 */ | 86 */ |
| 78 InstrumentationService(this._instrumentationServer); | 87 InstrumentationService(this._instrumentationServer); |
| 79 | 88 |
| 80 /** | 89 /** |
| 81 * Return `true` if this [InstrumentationService] was initialized with a | 90 * Return `true` if this [InstrumentationService] was initialized with a |
| 82 * non-`null` server (and hence instrumentation is active). | 91 * non-`null` server (and hence instrumentation is active). |
| 83 */ | 92 */ |
| 84 bool get isActive => _instrumentationServer != null; | 93 bool get isActive => _instrumentationServer != null; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 193 } |
| 185 | 194 |
| 186 /** | 195 /** |
| 187 * Log that a response has been sent to the client. | 196 * Log that a response has been sent to the client. |
| 188 */ | 197 */ |
| 189 void logResponse(String response) { | 198 void logResponse(String response) { |
| 190 _log(TAG_RESPONSE, response); | 199 _log(TAG_RESPONSE, response); |
| 191 } | 200 } |
| 192 | 201 |
| 193 /** | 202 /** |
| 203 * Log the result of executing a subprocess. [subprocessId] should be the |
| 204 * unique IDreturned by [logSubprocessStart]. |
| 205 */ |
| 206 void logSubprocessResult( |
| 207 int subprocessId, int exitCode, String stdout, String stderr) { |
| 208 if (_instrumentationServer != null) { |
| 209 _instrumentationServer.log(_join([ |
| 210 TAG_SUBPROCESS_RESULT, |
| 211 subprocessId.toString(), |
| 212 exitCode.toString(), |
| 213 JSON.encode(stdout), |
| 214 JSON.encode(stderr) |
| 215 ])); |
| 216 } |
| 217 } |
| 218 |
| 219 /** |
| 220 * Log that the given subprocess is about to be executed. Returns a unique |
| 221 * identifier that can be used to identify the subprocess for later log |
| 222 * entries. |
| 223 */ |
| 224 int logSubprocessStart( |
| 225 String executablePath, List<String> arguments, String workingDirectory) { |
| 226 int subprocessId = _subprocessCounter++; |
| 227 if (_instrumentationServer != null) { |
| 228 _instrumentationServer.log(_join([ |
| 229 TAG_SUBPROCESS_START, |
| 230 subprocessId.toString(), |
| 231 executablePath, |
| 232 workingDirectory, |
| 233 JSON.encode(arguments) |
| 234 ])); |
| 235 } |
| 236 return subprocessId; |
| 237 } |
| 238 |
| 239 /** |
| 194 * Signal that the client has started analysis server. | 240 * Signal that the client has started analysis server. |
| 195 * This method should be invoked exactly one time. | 241 * This method should be invoked exactly one time. |
| 196 */ | 242 */ |
| 197 void logVersion(String uuid, String clientId, String clientVersion, | 243 void logVersion(String uuid, String clientId, String clientVersion, |
| 198 String serverVersion, String sdkVersion) { | 244 String serverVersion, String sdkVersion) { |
| 199 String normalize(String value) => | 245 String normalize(String value) => |
| 200 value != null && value.length > 0 ? value : 'unknown'; | 246 value != null && value.length > 0 ? value : 'unknown'; |
| 201 | 247 |
| 202 if (_instrumentationServer != null) { | 248 if (_instrumentationServer != null) { |
| 203 _instrumentationServer.logWithPriority(_join([ | 249 _instrumentationServer.logWithPriority(_join([ |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 357 } |
| 312 } | 358 } |
| 313 | 359 |
| 314 @override | 360 @override |
| 315 void shutdown() { | 361 void shutdown() { |
| 316 for (InstrumentationServer server in _servers) { | 362 for (InstrumentationServer server in _servers) { |
| 317 server.shutdown(); | 363 server.shutdown(); |
| 318 } | 364 } |
| 319 } | 365 } |
| 320 } | 366 } |
| OLD | NEW |