| 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. |
| 9 */ |
| 10 class AnalysisPerformanceKind { |
| 11 static const String FULL = 'analysis_full'; |
| 12 static const String INCREMENTAL = 'analysis_incremental'; |
| 13 } |
| 14 |
| 15 /** |
| 8 * The interface used by client code to communicate with an instrumentation | 16 * The interface used by client code to communicate with an instrumentation |
| 9 * server. | 17 * server. |
| 10 */ | 18 */ |
| 11 abstract class InstrumentationServer { | 19 abstract class InstrumentationServer { |
| 12 /** | 20 /** |
| 13 * Pass the given [message] to the instrumentation server so that it will be | 21 * Pass the given [message] to the instrumentation server so that it will be |
| 14 * logged with other messages. | 22 * logged with other messages. |
| 15 * | 23 * |
| 16 * This method should be used for most logging. | 24 * This method should be used for most logging. |
| 17 */ | 25 */ |
| (...skipping 24 matching lines...) Expand all Loading... |
| 42 /** | 50 /** |
| 43 * An instrumentation service that will not log any instrumentation data. | 51 * An instrumentation service that will not log any instrumentation data. |
| 44 */ | 52 */ |
| 45 static final InstrumentationService NULL_SERVICE = | 53 static final InstrumentationService NULL_SERVICE = |
| 46 new InstrumentationService(null); | 54 new InstrumentationService(null); |
| 47 | 55 |
| 48 static const String TAG_ERROR = 'Err'; | 56 static const String TAG_ERROR = 'Err'; |
| 49 static const String TAG_EXCEPTION = 'Ex'; | 57 static const String TAG_EXCEPTION = 'Ex'; |
| 50 static const String TAG_LOG_ENTRY = 'Log'; | 58 static const String TAG_LOG_ENTRY = 'Log'; |
| 51 static const String TAG_NOTIFICATION = 'Noti'; | 59 static const String TAG_NOTIFICATION = 'Noti'; |
| 60 static const String TAG_PERFORMANCE = 'Perf'; |
| 52 static const String TAG_REQUEST = 'Req'; | 61 static const String TAG_REQUEST = 'Req'; |
| 53 static const String TAG_RESPONSE = 'Res'; | 62 static const String TAG_RESPONSE = 'Res'; |
| 54 static const String TAG_VERSION = 'Ver'; | 63 static const String TAG_VERSION = 'Ver'; |
| 55 | 64 |
| 56 /** | 65 /** |
| 57 * The instrumentation server used to communicate with the server, or `null` | 66 * The instrumentation server used to communicate with the server, or `null` |
| 58 * if instrumentation data should not be logged. | 67 * if instrumentation data should not be logged. |
| 59 */ | 68 */ |
| 60 InstrumentationServer _instrumentationServer; | 69 InstrumentationServer _instrumentationServer; |
| 61 | 70 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 110 } |
| 102 | 111 |
| 103 /** | 112 /** |
| 104 * Log that a notification has been sent to the client. | 113 * Log that a notification has been sent to the client. |
| 105 */ | 114 */ |
| 106 void logNotification(String notification) { | 115 void logNotification(String notification) { |
| 107 _log(TAG_NOTIFICATION, notification); | 116 _log(TAG_NOTIFICATION, notification); |
| 108 } | 117 } |
| 109 | 118 |
| 110 /** | 119 /** |
| 120 * Log the given performance fact. |
| 121 */ |
| 122 void logPerformance(String kind, Stopwatch sw, String message) { |
| 123 sw.stop(); |
| 124 String elapsed = sw.elapsedMilliseconds.toString(); |
| 125 if (_instrumentationServer != null) { |
| 126 _instrumentationServer.log( |
| 127 _join([TAG_PERFORMANCE, kind, elapsed, message])); |
| 128 } |
| 129 } |
| 130 |
| 131 /** |
| 111 * Log that the given priority [exception] was thrown, with the given | 132 * Log that the given priority [exception] was thrown, with the given |
| 112 * [stackTrace]. | 133 * [stackTrace]. |
| 113 */ | 134 */ |
| 114 void logPriorityException(dynamic exception, StackTrace stackTrace) { | 135 void logPriorityException(dynamic exception, StackTrace stackTrace) { |
| 115 if (_instrumentationServer != null) { | 136 if (_instrumentationServer != null) { |
| 116 String message = _toString(exception); | 137 String message = _toString(exception); |
| 117 String trace = _toString(stackTrace); | 138 String trace = _toString(stackTrace); |
| 118 _instrumentationServer.logWithPriority( | 139 _instrumentationServer.logWithPriority( |
| 119 _join([TAG_EXCEPTION, message, trace])); | 140 _join([TAG_EXCEPTION, message, trace])); |
| 120 } | 141 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 } | 242 } |
| 222 } | 243 } |
| 223 | 244 |
| 224 @override | 245 @override |
| 225 void shutdown() { | 246 void shutdown() { |
| 226 for (InstrumentationServer server in _servers) { | 247 for (InstrumentationServer server in _servers) { |
| 227 server.shutdown(); | 248 server.shutdown(); |
| 228 } | 249 } |
| 229 } | 250 } |
| 230 } | 251 } |
| OLD | NEW |