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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:collection'; | 6 import 'dart:collection'; |
7 import 'dart:core'; | 7 import 'dart:core'; |
8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
9 import 'dart:math' show max; | 9 import 'dart:math' show max; |
10 | 10 |
11 import 'package:analysis_server/protocol/protocol.dart'; | 11 import 'package:analysis_server/protocol/protocol.dart'; |
12 import 'package:analysis_server/protocol/protocol_generated.dart' | 12 import 'package:analysis_server/protocol/protocol_generated.dart' |
13 hide AnalysisOptions; | 13 hide AnalysisOptions; |
14 import 'package:analysis_server/src/analysis_logger.dart'; | 14 import 'package:analysis_server/src/analysis_logger.dart'; |
15 import 'package:analysis_server/src/channel/channel.dart'; | 15 import 'package:analysis_server/src/channel/channel.dart'; |
| 16 import 'package:analysis_server/src/collections.dart'; |
16 import 'package:analysis_server/src/computer/computer_highlights.dart'; | 17 import 'package:analysis_server/src/computer/computer_highlights.dart'; |
17 import 'package:analysis_server/src/computer/computer_highlights2.dart'; | 18 import 'package:analysis_server/src/computer/computer_highlights2.dart'; |
18 import 'package:analysis_server/src/computer/computer_outline.dart'; | 19 import 'package:analysis_server/src/computer/computer_outline.dart'; |
19 import 'package:analysis_server/src/computer/new_notifications.dart'; | 20 import 'package:analysis_server/src/computer/new_notifications.dart'; |
20 import 'package:analysis_server/src/context_manager.dart'; | 21 import 'package:analysis_server/src/context_manager.dart'; |
21 import 'package:analysis_server/src/domains/analysis/navigation.dart'; | 22 import 'package:analysis_server/src/domains/analysis/navigation.dart'; |
22 import 'package:analysis_server/src/domains/analysis/navigation_dart.dart'; | 23 import 'package:analysis_server/src/domains/analysis/navigation_dart.dart'; |
23 import 'package:analysis_server/src/domains/analysis/occurrences.dart'; | 24 import 'package:analysis_server/src/domains/analysis/occurrences.dart'; |
24 import 'package:analysis_server/src/domains/analysis/occurrences_dart.dart'; | 25 import 'package:analysis_server/src/domains/analysis/occurrences_dart.dart'; |
25 import 'package:analysis_server/src/ide_options.dart'; | 26 import 'package:analysis_server/src/ide_options.dart'; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 /** | 256 /** |
256 * Return the total time the server's been alive. | 257 * Return the total time the server's been alive. |
257 */ | 258 */ |
258 Duration get uptime { | 259 Duration get uptime { |
259 DateTime start = new DateTime.fromMillisecondsSinceEpoch( | 260 DateTime start = new DateTime.fromMillisecondsSinceEpoch( |
260 performanceDuringStartup.startTime); | 261 performanceDuringStartup.startTime); |
261 return new DateTime.now().difference(start); | 262 return new DateTime.now().difference(start); |
262 } | 263 } |
263 | 264 |
264 /** | 265 /** |
| 266 * A [RecentBuffer] of the most recent exceptions encountered by the analysis |
| 267 * server. |
| 268 */ |
| 269 final RecentBuffer<ServerException> exceptions = new RecentBuffer(10); |
| 270 |
| 271 /** |
265 * The class into which performance information is currently being recorded. | 272 * The class into which performance information is currently being recorded. |
266 * During startup, this will be the same as [performanceDuringStartup] | 273 * During startup, this will be the same as [performanceDuringStartup] |
267 * and after startup is complete, this switches to [performanceAfterStartup]. | 274 * and after startup is complete, this switches to [performanceAfterStartup]. |
268 */ | 275 */ |
269 ServerPerformance _performance; | 276 ServerPerformance _performance; |
270 | 277 |
271 /** | 278 /** |
272 * The [Completer] that completes when analysis is complete. | 279 * The [Completer] that completes when analysis is complete. |
273 */ | 280 */ |
274 Completer _onAnalysisCompleteCompleter; | 281 Completer _onAnalysisCompleteCompleter; |
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 void sendResponse(Response response) { | 1233 void sendResponse(Response response) { |
1227 channel.sendResponse(response); | 1234 channel.sendResponse(response); |
1228 } | 1235 } |
1229 | 1236 |
1230 /** | 1237 /** |
1231 * Sends a `server.error` notification. | 1238 * Sends a `server.error` notification. |
1232 */ | 1239 */ |
1233 void sendServerErrorNotification(String message, exception, stackTrace, | 1240 void sendServerErrorNotification(String message, exception, stackTrace, |
1234 {bool fatal: false}) { | 1241 {bool fatal: false}) { |
1235 StringBuffer buffer = new StringBuffer(); | 1242 StringBuffer buffer = new StringBuffer(); |
1236 if (exception != null) { | 1243 buffer.write(exception ?? 'null exception'); |
1237 buffer.write(exception); | |
1238 } else { | |
1239 buffer.write('null exception'); | |
1240 } | |
1241 if (stackTrace != null) { | 1244 if (stackTrace != null) { |
1242 buffer.writeln(); | 1245 buffer.writeln(); |
1243 buffer.write(stackTrace); | 1246 buffer.write(stackTrace); |
1244 } else if (exception is! CaughtException) { | 1247 } else if (exception is! CaughtException) { |
1245 try { | 1248 stackTrace = StackTrace.current; |
1246 throw 'ignored'; | 1249 buffer.writeln(); |
1247 } catch (ignored, stackTrace) { | 1250 buffer.write(stackTrace); |
1248 buffer.writeln(); | |
1249 buffer.write(stackTrace); | |
1250 } | |
1251 } | 1251 } |
| 1252 |
1252 // send the notification | 1253 // send the notification |
1253 channel.sendNotification( | 1254 channel.sendNotification( |
1254 new ServerErrorParams(fatal, message, buffer.toString()) | 1255 new ServerErrorParams(fatal, message, buffer.toString()) |
1255 .toNotification()); | 1256 .toNotification()); |
| 1257 |
| 1258 // remember the last few exceptions |
| 1259 if (exception is CaughtException) { |
| 1260 stackTrace ??= exception.stackTrace; |
| 1261 } |
| 1262 exceptions.add(new ServerException(message, exception, stackTrace, fatal)); |
1256 } | 1263 } |
1257 | 1264 |
1258 /** | 1265 /** |
1259 * Send status notification to the client. The `operation` is the operation | 1266 * Send status notification to the client. The `operation` is the operation |
1260 * being performed or `null` if analysis is complete. | 1267 * being performed or `null` if analysis is complete. |
1261 */ | 1268 */ |
1262 void sendStatusNotification(ServerOperation operation) { | 1269 void sendStatusNotification(ServerOperation operation) { |
1263 // Only send status when subscribed. | 1270 // Only send status when subscribed. |
1264 if (!serverServices.contains(ServerService.STATUS)) { | 1271 if (!serverServices.contains(ServerService.STATUS)) { |
1265 return; | 1272 return; |
(...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 /** | 2384 /** |
2378 * The [PerformanceTag] for time spent in server request handlers. | 2385 * The [PerformanceTag] for time spent in server request handlers. |
2379 */ | 2386 */ |
2380 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 2387 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
2381 | 2388 |
2382 /** | 2389 /** |
2383 * The [PerformanceTag] for time spent in split store microtasks. | 2390 * The [PerformanceTag] for time spent in split store microtasks. |
2384 */ | 2391 */ |
2385 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 2392 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
2386 } | 2393 } |
| 2394 |
| 2395 /** |
| 2396 * Used to record server exceptions. |
| 2397 */ |
| 2398 class ServerException { |
| 2399 final String message; |
| 2400 final dynamic exception; |
| 2401 final StackTrace stackTrace; |
| 2402 final bool fatal; |
| 2403 |
| 2404 ServerException(this.message, this.exception, this.stackTrace, this.fatal); |
| 2405 |
| 2406 @override |
| 2407 String toString() => message; |
| 2408 } |
OLD | NEW |