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'; |
11 | 11 |
12 /** | 12 /** |
13 * A container with analysis performance constants. | 13 * A container with analysis performance constants. |
14 */ | 14 */ |
15 class AnalysisPerformanceKind { | 15 class AnalysisPerformanceKind { |
16 static const String FULL = 'analysis_full'; | 16 static const String FULL = 'analysis_full'; |
17 static const String INCREMENTAL = 'analysis_incremental'; | 17 static const String INCREMENTAL = 'analysis_incremental'; |
18 } | 18 } |
19 | 19 |
20 /** | 20 /** |
21 * The interface used by client code to communicate with an instrumentation | 21 * The interface used by client code to communicate with an instrumentation |
22 * server. | 22 * server. |
23 */ | 23 */ |
24 abstract class InstrumentationServer { | 24 abstract class InstrumentationServer { |
25 /** | 25 /** |
| 26 * A user-friendly description of this instrumentation server. |
| 27 */ |
| 28 String get describe; |
| 29 |
| 30 /** |
26 * Return the identifier used to identify the current session. | 31 * Return the identifier used to identify the current session. |
27 */ | 32 */ |
28 String get sessionId; | 33 String get sessionId; |
29 | 34 |
30 /** | 35 /** |
31 * A user-friendly description of this instrumentation server. | |
32 */ | |
33 String get describe; | |
34 | |
35 /** | |
36 * Pass the given [message] to the instrumentation server so that it will be | 36 * Pass the given [message] to the instrumentation server so that it will be |
37 * logged with other messages. | 37 * logged with other messages. |
38 * | 38 * |
39 * This method should be used for most logging. | 39 * This method should be used for most logging. |
40 */ | 40 */ |
41 void log(String message); | 41 void log(String message); |
42 | 42 |
43 /** | 43 /** |
44 * Pass the given [message] to the instrumentation server so that it will be | 44 * Pass the given [message] to the instrumentation server so that it will be |
45 * logged with other messages. | 45 * logged with other messages. |
(...skipping 22 matching lines...) Expand all 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_NOTIFICATION = 'PluginNoti'; |
| 79 static const String TAG_PLUGIN_REQUEST = 'PluginReq'; |
| 80 static const String TAG_PLUGIN_RESPONSE = 'PluginRes'; |
78 static const String TAG_REQUEST = 'Req'; | 81 static const String TAG_REQUEST = 'Req'; |
79 static const String TAG_RESPONSE = 'Res'; | 82 static const String TAG_RESPONSE = 'Res'; |
80 static const String TAG_SUBPROCESS_START = 'SPStart'; | 83 static const String TAG_SUBPROCESS_START = 'SPStart'; |
81 static const String TAG_SUBPROCESS_RESULT = 'SPResult'; | 84 static const String TAG_SUBPROCESS_RESULT = 'SPResult'; |
82 static const String TAG_VERSION = 'Ver'; | 85 static const String TAG_VERSION = 'Ver'; |
83 static const String TAG_WATCH_EVENT = 'Watch'; | 86 static const String TAG_WATCH_EVENT = 'Watch'; |
84 | 87 |
85 /** | 88 /** |
86 * The instrumentation server used to communicate with the server, or `null` | 89 * The instrumentation server used to communicate with the server, or `null` |
87 * if instrumentation data should not be logged. | 90 * if instrumentation data should not be logged. |
88 */ | 91 */ |
89 InstrumentationServer _instrumentationServer; | 92 InstrumentationServer _instrumentationServer; |
90 | 93 |
91 /** | 94 /** |
92 * Counter used to generate unique ID's for [logSubprocessStart]. | 95 * Counter used to generate unique ID's for [logSubprocessStart]. |
93 */ | 96 */ |
94 int _subprocessCounter = 0; | 97 int _subprocessCounter = 0; |
95 | 98 |
96 /** | 99 /** |
97 * Initialize a newly created instrumentation service to communicate with the | 100 * Initialize a newly created instrumentation service to communicate with the |
98 * given [_instrumentationServer]. | 101 * given [_instrumentationServer]. |
99 */ | 102 */ |
100 InstrumentationService(this._instrumentationServer); | 103 InstrumentationService(this._instrumentationServer); |
101 | 104 |
| 105 InstrumentationServer get instrumentationServer => _instrumentationServer; |
| 106 |
102 /** | 107 /** |
103 * Return `true` if this [InstrumentationService] was initialized with a | 108 * Return `true` if this [InstrumentationService] was initialized with a |
104 * non-`null` server (and hence instrumentation is active). | 109 * non-`null` server (and hence instrumentation is active). |
105 */ | 110 */ |
106 bool get isActive => _instrumentationServer != null; | 111 bool get isActive => _instrumentationServer != null; |
107 | 112 |
108 /** | 113 /** |
109 * Return the identifier used to identify the current session. | 114 * Return the identifier used to identify the current session. |
110 */ | 115 */ |
111 String get sessionId => _instrumentationServer?.sessionId ?? ''; | 116 String get sessionId => _instrumentationServer?.sessionId ?? ''; |
112 | 117 |
113 /** | 118 /** |
114 * The current time, expressed as a decimal encoded number of milliseconds. | 119 * The current time, expressed as a decimal encoded number of milliseconds. |
115 */ | 120 */ |
116 String get _timestamp => new DateTime.now().millisecondsSinceEpoch.toString(); | 121 String get _timestamp => new DateTime.now().millisecondsSinceEpoch.toString(); |
117 | 122 |
118 InstrumentationServer get instrumentationServer => _instrumentationServer; | |
119 | |
120 /** | 123 /** |
121 * Log that the given analysis [task] is being performed in the given | 124 * Log that the given analysis [task] is being performed in the given |
122 * [context]. | 125 * [context]. |
123 */ | 126 */ |
124 void logAnalysisTask(String context, AnalysisTask task) { | 127 void logAnalysisTask(String context, AnalysisTask task) { |
125 if (_instrumentationServer != null) { | 128 if (_instrumentationServer != null) { |
126 _instrumentationServer | 129 _instrumentationServer |
127 .log(_join([TAG_ANALYSIS_TASK, context, task.description])); | 130 .log(_join([TAG_ANALYSIS_TASK, context, task.description])); |
128 } | 131 } |
129 } | 132 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 */ | 197 */ |
195 void logPerformance(String kind, Stopwatch sw, String message) { | 198 void logPerformance(String kind, Stopwatch sw, String message) { |
196 sw.stop(); | 199 sw.stop(); |
197 String elapsed = sw.elapsedMilliseconds.toString(); | 200 String elapsed = sw.elapsedMilliseconds.toString(); |
198 if (_instrumentationServer != null) { | 201 if (_instrumentationServer != null) { |
199 _instrumentationServer | 202 _instrumentationServer |
200 .log(_join([TAG_PERFORMANCE, kind, elapsed, message])); | 203 .log(_join([TAG_PERFORMANCE, kind, elapsed, message])); |
201 } | 204 } |
202 } | 205 } |
203 | 206 |
| 207 void logPluginNotification(Uri pluginUri, String notification) { |
| 208 if (_instrumentationServer != null) { |
| 209 _instrumentationServer.log( |
| 210 _join([TAG_PLUGIN_NOTIFICATION, _toString(pluginUri), notification])); |
| 211 } |
| 212 } |
| 213 |
| 214 void logPluginRequest(Uri pluginUri, String request) { |
| 215 if (_instrumentationServer != null) { |
| 216 _instrumentationServer |
| 217 .log(_join([TAG_PLUGIN_REQUEST, _toString(pluginUri), request])); |
| 218 } |
| 219 } |
| 220 |
| 221 void logPluginResponse(Uri pluginUri, String response) { |
| 222 if (_instrumentationServer != null) { |
| 223 _instrumentationServer |
| 224 .log(_join([TAG_PLUGIN_RESPONSE, _toString(pluginUri), response])); |
| 225 } |
| 226 } |
| 227 |
204 /** | 228 /** |
205 * Log that the given priority [exception] was thrown, with the given | 229 * Log that the given priority [exception] was thrown, with the given |
206 * [stackTrace]. | 230 * [stackTrace]. |
207 */ | 231 */ |
208 void logPriorityException(dynamic exception, StackTrace stackTrace) { | 232 void logPriorityException(dynamic exception, StackTrace stackTrace) { |
209 if (_instrumentationServer != null) { | 233 if (_instrumentationServer != null) { |
210 String message = _toString(exception); | 234 String message = _toString(exception); |
211 String trace = _toString(stackTrace); | 235 String trace = _toString(stackTrace); |
212 _instrumentationServer | 236 _instrumentationServer |
213 .logWithPriority(_join([TAG_EXCEPTION, message, trace])); | 237 .logWithPriority(_join([TAG_EXCEPTION, message, trace])); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 | 391 |
368 /** | 392 /** |
369 * An [InstrumentationServer] that sends messages to multiple instances. | 393 * An [InstrumentationServer] that sends messages to multiple instances. |
370 */ | 394 */ |
371 class MulticastInstrumentationServer implements InstrumentationServer { | 395 class MulticastInstrumentationServer implements InstrumentationServer { |
372 final List<InstrumentationServer> _servers; | 396 final List<InstrumentationServer> _servers; |
373 | 397 |
374 MulticastInstrumentationServer(this._servers); | 398 MulticastInstrumentationServer(this._servers); |
375 | 399 |
376 @override | 400 @override |
377 String get sessionId => _servers[0].sessionId; | |
378 | |
379 @override | |
380 String get describe { | 401 String get describe { |
381 return _servers | 402 return _servers |
382 .map((InstrumentationServer server) => server.describe) | 403 .map((InstrumentationServer server) => server.describe) |
383 .join("\n"); | 404 .join("\n"); |
384 } | 405 } |
385 | 406 |
386 @override | 407 @override |
| 408 String get sessionId => _servers[0].sessionId; |
| 409 |
| 410 @override |
387 void log(String message) { | 411 void log(String message) { |
388 for (InstrumentationServer server in _servers) { | 412 for (InstrumentationServer server in _servers) { |
389 server.log(message); | 413 server.log(message); |
390 } | 414 } |
391 } | 415 } |
392 | 416 |
393 @override | 417 @override |
394 void logWithPriority(String message) { | 418 void logWithPriority(String message) { |
395 for (InstrumentationServer server in _servers) { | 419 for (InstrumentationServer server in _servers) { |
396 server.logWithPriority(message); | 420 server.logWithPriority(message); |
397 } | 421 } |
398 } | 422 } |
399 | 423 |
400 @override | 424 @override |
401 Future shutdown() async { | 425 Future shutdown() async { |
402 for (InstrumentationServer server in _servers) { | 426 for (InstrumentationServer server in _servers) { |
403 await server.shutdown(); | 427 await server.shutdown(); |
404 } | 428 } |
405 } | 429 } |
406 } | 430 } |
OLD | NEW |