Chromium Code Reviews| 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 analyzer.instrumentation.instrumentation; | 5 library analyzer.instrumentation.instrumentation; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:analyzer/task/model.dart'; | 10 import 'package:analyzer/task/model.dart'; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 static final InstrumentationService NULL_SERVICE = | 68 static final InstrumentationService NULL_SERVICE = |
| 69 new InstrumentationService(null); | 69 new InstrumentationService(null); |
| 70 | 70 |
| 71 static const String TAG_ANALYSIS_TASK = 'Task'; | 71 static const String TAG_ANALYSIS_TASK = 'Task'; |
| 72 static const String TAG_ERROR = 'Err'; | 72 static const String TAG_ERROR = 'Err'; |
| 73 static const String TAG_EXCEPTION = 'Ex'; | 73 static const String TAG_EXCEPTION = 'Ex'; |
| 74 static const String TAG_FILE_READ = 'Read'; | 74 static const String TAG_FILE_READ = 'Read'; |
| 75 static const String TAG_LOG_ENTRY = 'Log'; | 75 static const String TAG_LOG_ENTRY = 'Log'; |
| 76 static const String TAG_NOTIFICATION = 'Noti'; | 76 static const String TAG_NOTIFICATION = 'Noti'; |
| 77 static const String TAG_PERFORMANCE = 'Perf'; | 77 static const String TAG_PERFORMANCE = 'Perf'; |
| 78 static const String TAG_PLUGIN_ERROR = 'PluginErr'; | |
| 79 static const String TAG_PLUGIN_EXCEPTION = 'PluginEx'; | |
| 78 static const String TAG_PLUGIN_NOTIFICATION = 'PluginNoti'; | 80 static const String TAG_PLUGIN_NOTIFICATION = 'PluginNoti'; |
| 79 static const String TAG_PLUGIN_REQUEST = 'PluginReq'; | 81 static const String TAG_PLUGIN_REQUEST = 'PluginReq'; |
| 80 static const String TAG_PLUGIN_RESPONSE = 'PluginRes'; | 82 static const String TAG_PLUGIN_RESPONSE = 'PluginRes'; |
| 83 static const String TAG_PLUGIN_TIMEOUT = 'PluginTo'; | |
| 81 static const String TAG_REQUEST = 'Req'; | 84 static const String TAG_REQUEST = 'Req'; |
| 82 static const String TAG_RESPONSE = 'Res'; | 85 static const String TAG_RESPONSE = 'Res'; |
| 83 static const String TAG_SUBPROCESS_START = 'SPStart'; | 86 static const String TAG_SUBPROCESS_START = 'SPStart'; |
| 84 static const String TAG_SUBPROCESS_RESULT = 'SPResult'; | 87 static const String TAG_SUBPROCESS_RESULT = 'SPResult'; |
| 85 static const String TAG_VERSION = 'Ver'; | 88 static const String TAG_VERSION = 'Ver'; |
| 86 static const String TAG_WATCH_EVENT = 'Watch'; | 89 static const String TAG_WATCH_EVENT = 'Watch'; |
| 87 | 90 |
| 88 /** | 91 /** |
| 89 * The instrumentation server used to communicate with the server, or `null` | 92 * The instrumentation server used to communicate with the server, or `null` |
| 90 * if instrumentation data should not be logged. | 93 * if instrumentation data should not be logged. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 */ | 200 */ |
| 198 void logPerformance(String kind, Stopwatch sw, String message) { | 201 void logPerformance(String kind, Stopwatch sw, String message) { |
| 199 sw.stop(); | 202 sw.stop(); |
| 200 String elapsed = sw.elapsedMilliseconds.toString(); | 203 String elapsed = sw.elapsedMilliseconds.toString(); |
| 201 if (_instrumentationServer != null) { | 204 if (_instrumentationServer != null) { |
| 202 _instrumentationServer | 205 _instrumentationServer |
| 203 .log(_join([TAG_PERFORMANCE, kind, elapsed, message])); | 206 .log(_join([TAG_PERFORMANCE, kind, elapsed, message])); |
| 204 } | 207 } |
| 205 } | 208 } |
| 206 | 209 |
| 210 /** | |
| 211 * Log the fact that an error, described by the given [message], was reported | |
| 212 * by the given [plugin]. | |
| 213 */ | |
| 214 void logPluginError( | |
| 215 PluginData plugin, String code, String message, String stackTrace) { | |
| 216 List<String> fields = <String>[TAG_PLUGIN_ERROR]; | |
| 217 fields.add(code ?? ''); | |
| 218 fields.add(message ?? ''); | |
| 219 fields.add(stackTrace ?? ''); | |
| 220 plugin.addToFields(fields); | |
| 221 _instrumentationServer.log(_join(fields)); | |
|
scheglov
2017/04/19 17:46:59
Why don't we check for null in this method?
Brian Wilkerson
2017/04/19 18:01:13
Done
| |
| 222 } | |
| 223 | |
| 224 /** | |
| 225 * Log that the given non-priority [exception] was thrown, with the given | |
| 226 * [stackTrace] by the given [plugin]. | |
| 227 */ | |
| 228 void logPluginException( | |
| 229 PluginData plugin, dynamic exception, StackTrace stackTrace) { | |
| 230 if (_instrumentationServer != null) { | |
| 231 List<String> fields = <String>[ | |
| 232 TAG_PLUGIN_EXCEPTION, | |
| 233 _toString(exception), | |
| 234 _toString(stackTrace) | |
| 235 ]; | |
| 236 plugin.addToFields(fields); | |
| 237 _instrumentationServer.log(_join(fields)); | |
| 238 } | |
| 239 } | |
| 240 | |
| 207 void logPluginNotification(Uri pluginUri, String notification) { | 241 void logPluginNotification(Uri pluginUri, String notification) { |
| 208 if (_instrumentationServer != null) { | 242 if (_instrumentationServer != null) { |
| 209 _instrumentationServer.log( | 243 _instrumentationServer.log( |
| 210 _join([TAG_PLUGIN_NOTIFICATION, _toString(pluginUri), notification])); | 244 _join([TAG_PLUGIN_NOTIFICATION, _toString(pluginUri), notification])); |
| 211 } | 245 } |
| 212 } | 246 } |
| 213 | 247 |
| 214 void logPluginRequest(Uri pluginUri, String request) { | 248 void logPluginRequest(Uri pluginUri, String request) { |
| 215 if (_instrumentationServer != null) { | 249 if (_instrumentationServer != null) { |
| 216 _instrumentationServer | 250 _instrumentationServer |
| 217 .log(_join([TAG_PLUGIN_REQUEST, _toString(pluginUri), request])); | 251 .log(_join([TAG_PLUGIN_REQUEST, _toString(pluginUri), request])); |
| 218 } | 252 } |
| 219 } | 253 } |
| 220 | 254 |
| 221 void logPluginResponse(Uri pluginUri, String response) { | 255 void logPluginResponse(Uri pluginUri, String response) { |
| 222 if (_instrumentationServer != null) { | 256 if (_instrumentationServer != null) { |
| 223 _instrumentationServer | 257 _instrumentationServer |
| 224 .log(_join([TAG_PLUGIN_RESPONSE, _toString(pluginUri), response])); | 258 .log(_join([TAG_PLUGIN_RESPONSE, _toString(pluginUri), response])); |
| 225 } | 259 } |
| 226 } | 260 } |
| 227 | 261 |
| 228 /** | 262 /** |
| 263 * Log that the given [plugin] took too long to execute the given [request]. | |
| 264 */ | |
| 265 void logPluginTimeout(PluginData plugin, String request) { | |
| 266 if (_instrumentationServer != null) { | |
| 267 List<String> fields = <String>[TAG_PLUGIN_TIMEOUT, request]; | |
| 268 plugin.addToFields(fields); | |
| 269 _instrumentationServer.log(_join(fields)); | |
| 270 } | |
| 271 } | |
| 272 | |
| 273 /** | |
| 229 * Log that the given priority [exception] was thrown, with the given | 274 * Log that the given priority [exception] was thrown, with the given |
| 230 * [stackTrace]. | 275 * [stackTrace]. |
| 231 */ | 276 */ |
| 232 void logPriorityException(dynamic exception, StackTrace stackTrace) { | 277 void logPriorityException(dynamic exception, StackTrace stackTrace) { |
| 233 if (_instrumentationServer != null) { | 278 if (_instrumentationServer != null) { |
| 234 String message = _toString(exception); | 279 String message = _toString(exception); |
| 235 String trace = _toString(stackTrace); | 280 String trace = _toString(stackTrace); |
| 236 _instrumentationServer | 281 _instrumentationServer |
| 237 .logWithPriority(_join([TAG_EXCEPTION, message, trace])); | 282 .logWithPriority(_join([TAG_EXCEPTION, message, trace])); |
| 238 } | 283 } |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 } | 466 } |
| 422 } | 467 } |
| 423 | 468 |
| 424 @override | 469 @override |
| 425 Future shutdown() async { | 470 Future shutdown() async { |
| 426 for (InstrumentationServer server in _servers) { | 471 for (InstrumentationServer server in _servers) { |
| 427 await server.shutdown(); | 472 await server.shutdown(); |
| 428 } | 473 } |
| 429 } | 474 } |
| 430 } | 475 } |
| 476 | |
| 477 /** | |
| 478 * Information about a plugin. | |
| 479 */ | |
| 480 class PluginData { | |
| 481 /** | |
| 482 * The path to the plugin. | |
| 483 */ | |
| 484 final String path; | |
| 485 | |
| 486 /** | |
| 487 * The name of the plugin. | |
| 488 */ | |
| 489 final String name; | |
| 490 | |
| 491 /** | |
| 492 * The version of the plugin. | |
| 493 */ | |
| 494 final String version; | |
| 495 | |
| 496 /** | |
| 497 * Initialize a newly created set of data about a plugin. | |
| 498 */ | |
| 499 PluginData(this.path, this.name, this.version); | |
| 500 | |
| 501 /** | |
| 502 * Add the information about the plugin to the list of [fields] to be sent to | |
| 503 * the instrumentation server. | |
| 504 */ | |
| 505 void addToFields(List<String> fields) { | |
| 506 fields.add(path); | |
| 507 if (name != null) { | |
| 508 fields.add(name); | |
| 509 } | |
| 510 if (version != null) { | |
| 511 fields.add(version); | |
| 512 } | |
| 513 } | |
| 514 } | |
| OLD | NEW |