| 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 /** | 7 /** |
| 8 * A container with analysis performance constants. | 8 * A container with analysis performance constants. |
| 9 */ | 9 */ |
| 10 class AnalysisPerformanceKind { | 10 class AnalysisPerformanceKind { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 * The interface used by client code to communicate with an instrumentation | 46 * The interface used by client code to communicate with an instrumentation |
| 47 * server by wrapping an [InstrumentationServer]. | 47 * server by wrapping an [InstrumentationServer]. |
| 48 */ | 48 */ |
| 49 class InstrumentationService { | 49 class InstrumentationService { |
| 50 /** | 50 /** |
| 51 * An instrumentation service that will not log any instrumentation data. | 51 * An instrumentation service that will not log any instrumentation data. |
| 52 */ | 52 */ |
| 53 static final InstrumentationService NULL_SERVICE = | 53 static final InstrumentationService NULL_SERVICE = |
| 54 new InstrumentationService(null); | 54 new InstrumentationService(null); |
| 55 | 55 |
| 56 static const String TAG_ANALYSIS_TASK = 'Task'; |
| 56 static const String TAG_ERROR = 'Err'; | 57 static const String TAG_ERROR = 'Err'; |
| 57 static const String TAG_EXCEPTION = 'Ex'; | 58 static const String TAG_EXCEPTION = 'Ex'; |
| 58 static const String TAG_FILE_READ = 'Read'; | 59 static const String TAG_FILE_READ = 'Read'; |
| 59 static const String TAG_LOG_ENTRY = 'Log'; | 60 static const String TAG_LOG_ENTRY = 'Log'; |
| 60 static const String TAG_NOTIFICATION = 'Noti'; | 61 static const String TAG_NOTIFICATION = 'Noti'; |
| 61 static const String TAG_PERFORMANCE = 'Perf'; | 62 static const String TAG_PERFORMANCE = 'Perf'; |
| 62 static const String TAG_REQUEST = 'Req'; | 63 static const String TAG_REQUEST = 'Req'; |
| 63 static const String TAG_RESPONSE = 'Res'; | 64 static const String TAG_RESPONSE = 'Res'; |
| 64 static const String TAG_VERSION = 'Ver'; | 65 static const String TAG_VERSION = 'Ver'; |
| 66 static const String TAG_WATCH_EVENT = 'Watch'; |
| 65 | 67 |
| 66 /** | 68 /** |
| 67 * The instrumentation server used to communicate with the server, or `null` | 69 * The instrumentation server used to communicate with the server, or `null` |
| 68 * if instrumentation data should not be logged. | 70 * if instrumentation data should not be logged. |
| 69 */ | 71 */ |
| 70 InstrumentationServer _instrumentationServer; | 72 InstrumentationServer _instrumentationServer; |
| 71 | 73 |
| 72 /** | 74 /** |
| 73 * Initialize a newly created instrumentation service to comunicate with the | 75 * Initialize a newly created instrumentation service to comunicate with the |
| 74 * given [instrumentationServer]. | 76 * given [instrumentationServer]. |
| 75 */ | 77 */ |
| 76 InstrumentationService(this._instrumentationServer); | 78 InstrumentationService(this._instrumentationServer); |
| 77 | 79 |
| 78 /** | 80 /** |
| 79 * Return `true` if this [InstrumentationService] was initialized with a | 81 * Return `true` if this [InstrumentationService] was initialized with a |
| 80 * non-`null` server (and hence instrumentation is active). | 82 * non-`null` server (and hence instrumentation is active). |
| 81 */ | 83 */ |
| 82 bool get isActive => _instrumentationServer != null; | 84 bool get isActive => _instrumentationServer != null; |
| 83 | 85 |
| 84 /** | 86 /** |
| 85 * The current time, expressed as a decimal encoded number of milliseconds. | 87 * The current time, expressed as a decimal encoded number of milliseconds. |
| 86 */ | 88 */ |
| 87 String get _timestamp => new DateTime.now().millisecondsSinceEpoch.toString(); | 89 String get _timestamp => new DateTime.now().millisecondsSinceEpoch.toString(); |
| 88 | 90 |
| 89 /** | 91 /** |
| 92 * Log that an analysis task is being performed in the given [context]. The |
| 93 * task has the given [description]. |
| 94 */ |
| 95 void logAnalysisTask(String context, String description) { |
| 96 if (_instrumentationServer != null) { |
| 97 _instrumentationServer.log( |
| 98 _join([TAG_ANALYSIS_TASK, context, description])); |
| 99 } |
| 100 } |
| 101 |
| 102 /** |
| 90 * Log the fact that an error, described by the given [message], has occurred. | 103 * Log the fact that an error, described by the given [message], has occurred. |
| 91 */ | 104 */ |
| 92 void logError(String message) { | 105 void logError(String message) { |
| 93 _log(TAG_ERROR, message); | 106 _log(TAG_ERROR, message); |
| 94 } | 107 } |
| 95 | 108 |
| 96 /** | 109 /** |
| 97 * Log that the given non-priority [exception] was thrown, with the given | 110 * Log that the given non-priority [exception] was thrown, with the given |
| 98 * [stackTrace]. | 111 * [stackTrace]. |
| 99 */ | 112 */ |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 TAG_VERSION, | 207 TAG_VERSION, |
| 195 uuid, | 208 uuid, |
| 196 normalize(clientId), | 209 normalize(clientId), |
| 197 normalize(clientVersion), | 210 normalize(clientVersion), |
| 198 serverVersion, | 211 serverVersion, |
| 199 sdkVersion])); | 212 sdkVersion])); |
| 200 } | 213 } |
| 201 } | 214 } |
| 202 | 215 |
| 203 /** | 216 /** |
| 217 * Log that the file system watcher sent an event. The [folderPath] is the |
| 218 * path to the folder containing the changed file, the [filePath] is the path |
| 219 * of the file that changed, and the [changeType] indicates what kind of |
| 220 * change occurred. |
| 221 */ |
| 222 void logWatchEvent(String folderPath, String filePath, String changeType) { |
| 223 if (_instrumentationServer != null) { |
| 224 _instrumentationServer.log( |
| 225 _join([TAG_WATCH_EVENT, folderPath, filePath, changeType])); |
| 226 } |
| 227 } |
| 228 |
| 229 /** |
| 204 * Signal that the client is done communicating with the instrumentation | 230 * Signal that the client is done communicating with the instrumentation |
| 205 * server. This method should be invoked exactly one time and no other methods | 231 * server. This method should be invoked exactly one time and no other methods |
| 206 * should be invoked on this instance after this method has been invoked. | 232 * should be invoked on this instance after this method has been invoked. |
| 207 */ | 233 */ |
| 208 void shutdown() { | 234 void shutdown() { |
| 209 if (_instrumentationServer != null) { | 235 if (_instrumentationServer != null) { |
| 210 _instrumentationServer.shutdown(); | 236 _instrumentationServer.shutdown(); |
| 211 _instrumentationServer = null; | 237 _instrumentationServer = null; |
| 212 } | 238 } |
| 213 } | 239 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 } | 313 } |
| 288 } | 314 } |
| 289 | 315 |
| 290 @override | 316 @override |
| 291 void shutdown() { | 317 void shutdown() { |
| 292 for (InstrumentationServer server in _servers) { | 318 for (InstrumentationServer server in _servers) { |
| 293 server.shutdown(); | 319 server.shutdown(); |
| 294 } | 320 } |
| 295 } | 321 } |
| 296 } | 322 } |
| OLD | NEW |