Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: pkg/analysis_server/lib/src/status/get_handler.dart

Issue 1489583003: Diagnostic status reporting (#24932). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 analysis_server.src.status.get_handler; 5 library analysis_server.src.status.get_handler;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:convert'; 9 import 'dart:convert';
10 import 'dart:io'; 10 import 'dart:io';
11 import 'dart:math'; 11 import 'dart:math';
12 12
13 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; 13 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element;
14 import 'package:analysis_server/src/analysis_server.dart'; 14 import 'package:analysis_server/src/analysis_server.dart';
15 import 'package:analysis_server/src/domain_completion.dart'; 15 import 'package:analysis_server/src/domain_completion.dart';
16 import 'package:analysis_server/src/domain_diagnostic.dart';
16 import 'package:analysis_server/src/domain_execution.dart'; 17 import 'package:analysis_server/src/domain_execution.dart';
17 import 'package:analysis_server/src/operation/operation.dart'; 18 import 'package:analysis_server/src/operation/operation.dart';
18 import 'package:analysis_server/src/operation/operation_analysis.dart'; 19 import 'package:analysis_server/src/operation/operation_analysis.dart';
19 import 'package:analysis_server/src/operation/operation_queue.dart'; 20 import 'package:analysis_server/src/operation/operation_queue.dart';
20 import 'package:analysis_server/src/services/index/index.dart'; 21 import 'package:analysis_server/src/services/index/index.dart';
21 import 'package:analysis_server/src/services/index/local_index.dart'; 22 import 'package:analysis_server/src/services/index/local_index.dart';
22 import 'package:analysis_server/src/services/index/store/split_store.dart'; 23 import 'package:analysis_server/src/services/index/store/split_store.dart';
23 import 'package:analysis_server/src/socket_server.dart'; 24 import 'package:analysis_server/src/socket_server.dart';
24 import 'package:analysis_server/src/status/ast_writer.dart'; 25 import 'package:analysis_server/src/status/ast_writer.dart';
25 import 'package:analysis_server/src/status/element_writer.dart'; 26 import 'package:analysis_server/src/status/element_writer.dart';
27 import 'package:analysis_server/src/utilities/average.dart';
26 import 'package:analyzer/file_system/file_system.dart'; 28 import 'package:analyzer/file_system/file_system.dart';
27 import 'package:analyzer/src/context/cache.dart'; 29 import 'package:analyzer/src/context/cache.dart';
28 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl; 30 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl;
29 import 'package:analyzer/src/generated/ast.dart'; 31 import 'package:analyzer/src/generated/ast.dart';
30 import 'package:analyzer/src/generated/element.dart'; 32 import 'package:analyzer/src/generated/element.dart';
31 import 'package:analyzer/src/generated/engine.dart' 33 import 'package:analyzer/src/generated/engine.dart'
32 hide AnalysisCache, AnalysisContextImpl, AnalysisTask; 34 hide AnalysisCache, AnalysisContextImpl, AnalysisTask;
33 import 'package:analyzer/src/generated/java_engine.dart'; 35 import 'package:analyzer/src/generated/java_engine.dart';
34 import 'package:analyzer/src/generated/resolver.dart'; 36 import 'package:analyzer/src/generated/resolver.dart';
35 import 'package:analyzer/src/generated/source.dart'; 37 import 'package:analyzer/src/generated/source.dart';
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 * The path used to request communication performance information. 89 * The path used to request communication performance information.
88 */ 90 */
89 static const String COMMUNICATION_PERFORMANCE_PATH = '/perf/communication'; 91 static const String COMMUNICATION_PERFORMANCE_PATH = '/perf/communication';
90 92
91 /** 93 /**
92 * The path used to request information about a specific context. 94 * The path used to request information about a specific context.
93 */ 95 */
94 static const String CONTEXT_PATH = '/context'; 96 static const String CONTEXT_PATH = '/context';
95 97
96 /** 98 /**
99 * The path used to request diagnostic information.
100 */
101 static const String DIAGNOSTIC_PATH = '/diagnostic';
102
103 /**
97 * The path used to request information about a element model. 104 * The path used to request information about a element model.
98 */ 105 */
99 static const String ELEMENT_PATH = '/element'; 106 static const String ELEMENT_PATH = '/element';
100 107
101 /** 108 /**
102 * The path used to request information about elements with the given name. 109 * The path used to request information about elements with the given name.
103 */ 110 */
104 static const String INDEX_ELEMENT_BY_NAME = '/index/element-by-name'; 111 static const String INDEX_ELEMENT_BY_NAME = '/index/element-by-name';
105 112
106 /** 113 /**
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 /** 157 /**
151 * Query parameter used to represent the cache state to search for, when 158 * Query parameter used to represent the cache state to search for, when
152 * accessing [CACHE_STATE_PATH]. 159 * accessing [CACHE_STATE_PATH].
153 */ 160 */
154 static const String STATE_QUERY_PARAM = 'state'; 161 static const String STATE_QUERY_PARAM = 'state';
155 162
156 static final ContentType _htmlContent = 163 static final ContentType _htmlContent =
157 new ContentType("text", "html", charset: "utf-8"); 164 new ContentType("text", "html", charset: "utf-8");
158 165
159 /** 166 /**
167 * Rolling average of calls to get diagnostics.
168 */
169 Average _diagnosticCallAverage = new Average();
170
171 /**
160 * The socket server whose status is to be reported on. 172 * The socket server whose status is to be reported on.
161 */ 173 */
162 SocketServer _server; 174 SocketServer _server;
163 175
164 /** 176 /**
165 * Buffer containing strings printed by the analysis server. 177 * Buffer containing strings printed by the analysis server.
166 */ 178 */
167 List<String> _printBuffer; 179 List<String> _printBuffer;
168 180
169 /** 181 /**
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } else if (path == CACHE_STATE_PATH) { 216 } else if (path == CACHE_STATE_PATH) {
205 _returnCacheState(request); 217 _returnCacheState(request);
206 } else if (path == CACHE_ENTRY_PATH) { 218 } else if (path == CACHE_ENTRY_PATH) {
207 _returnCacheEntry(request); 219 _returnCacheEntry(request);
208 } else if (path == COMPLETION_PATH) { 220 } else if (path == COMPLETION_PATH) {
209 _returnCompletionInfo(request); 221 _returnCompletionInfo(request);
210 } else if (path == COMMUNICATION_PERFORMANCE_PATH) { 222 } else if (path == COMMUNICATION_PERFORMANCE_PATH) {
211 _returnCommunicationPerformance(request); 223 _returnCommunicationPerformance(request);
212 } else if (path == CONTEXT_PATH) { 224 } else if (path == CONTEXT_PATH) {
213 _returnContextInfo(request); 225 _returnContextInfo(request);
226 } else if (path == DIAGNOSTIC_PATH) {
227 _returnDiagnosticInfo(request);
214 } else if (path == ELEMENT_PATH) { 228 } else if (path == ELEMENT_PATH) {
215 _returnElement(request); 229 _returnElement(request);
216 } else if (path == INDEX_ELEMENT_BY_NAME) { 230 } else if (path == INDEX_ELEMENT_BY_NAME) {
217 _returnIndexElementByName(request); 231 _returnIndexElementByName(request);
218 } else if (path == OVERLAY_PATH) { 232 } else if (path == OVERLAY_PATH) {
219 _returnOverlayContents(request); 233 _returnOverlayContents(request);
220 } else if (path == OVERLAYS_PATH) { 234 } else if (path == OVERLAYS_PATH) {
221 _returnOverlaysInfo(request); 235 _returnOverlaysInfo(request);
222 } else { 236 } else {
223 _returnUnknownRequest(request); 237 _returnUnknownRequest(request);
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 } else { 1068 } else {
1055 exceptions.forEach((CaughtException exception) { 1069 exceptions.forEach((CaughtException exception) {
1056 _writeException(buffer, exception); 1070 _writeException(buffer, exception);
1057 }); 1071 });
1058 } 1072 }
1059 }); 1073 });
1060 }); 1074 });
1061 } 1075 }
1062 1076
1063 /** 1077 /**
1078 * Return a response displaying diagnostic information.
1079 */
1080 void _returnDiagnosticInfo(HttpRequest request) {
1081 String value = request.requestedUri.queryParameters['index'];
1082 int index = value != null ? int.parse(value, onError: (_) => 0) : 0;
1083 _writeResponse(request, (StringBuffer buffer) {
1084 _writePage(buffer, 'Analysis Server - Diagnostic info', [],
1085 (StringBuffer buffer) {
1086 _writeDiagnosticStatus(buffer);
1087 });
1088 });
1089 }
1090
1091 /**
1064 * Return a response containing information about an element structure. 1092 * Return a response containing information about an element structure.
1065 */ 1093 */
1066 void _returnElement(HttpRequest request) { 1094 void _returnElement(HttpRequest request) {
1067 AnalysisServer analysisServer = _server.analysisServer; 1095 AnalysisServer analysisServer = _server.analysisServer;
1068 if (analysisServer == null) { 1096 if (analysisServer == null) {
1069 return _returnFailure(request, 'Analysis server not running'); 1097 return _returnFailure(request, 'Analysis server not running');
1070 } 1098 }
1071 String contextFilter = request.uri.queryParameters[CONTEXT_QUERY_PARAM]; 1099 String contextFilter = request.uri.queryParameters[CONTEXT_QUERY_PARAM];
1072 if (contextFilter == null) { 1100 if (contextFilter == null) {
1073 return _returnFailure( 1101 return _returnFailure(
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 } 1238 }
1211 1239
1212 /** 1240 /**
1213 * Return a response indicating the status of the analysis server. 1241 * Return a response indicating the status of the analysis server.
1214 */ 1242 */
1215 void _returnServerStatus(HttpRequest request) { 1243 void _returnServerStatus(HttpRequest request) {
1216 _writeResponse(request, (StringBuffer buffer) { 1244 _writeResponse(request, (StringBuffer buffer) {
1217 _writePage(buffer, 'Analysis Server - Status', [], (StringBuffer buffer) { 1245 _writePage(buffer, 'Analysis Server - Status', [], (StringBuffer buffer) {
1218 if (_writeServerStatus(buffer)) { 1246 if (_writeServerStatus(buffer)) {
1219 _writeAnalysisStatus(buffer); 1247 _writeAnalysisStatus(buffer);
1248 _writeDiagnosticStatus(buffer);
1220 _writeEditStatus(buffer); 1249 _writeEditStatus(buffer);
1221 _writeExecutionStatus(buffer); 1250 _writeExecutionStatus(buffer);
1222 _writePluginStatus(buffer); 1251 _writePluginStatus(buffer);
1223 _writeRecentOutput(buffer); 1252 _writeRecentOutput(buffer);
1224 } 1253 }
1225 }); 1254 });
1226 }); 1255 });
1227 } 1256 }
1228 1257
1229 /** 1258 /**
(...skipping 10 matching lines...) Expand all
1240 buffer.write('<p>'); 1269 buffer.write('<p>');
1241 buffer 1270 buffer
1242 .write(makeLink(COMMUNICATION_PERFORMANCE_PATH, {}, 'Performance')); 1271 .write(makeLink(COMMUNICATION_PERFORMANCE_PATH, {}, 'Performance'));
1243 buffer.write('</p>'); 1272 buffer.write('</p>');
1244 buffer.write('<p>'); 1273 buffer.write('<p>');
1245 buffer.write(makeLink(STATUS_PATH, {}, 'Server status')); 1274 buffer.write(makeLink(STATUS_PATH, {}, 'Server status'));
1246 buffer.write('</p>'); 1275 buffer.write('</p>');
1247 buffer.write('<p>'); 1276 buffer.write('<p>');
1248 buffer.write(makeLink(OVERLAYS_PATH, {}, 'File overlays')); 1277 buffer.write(makeLink(OVERLAYS_PATH, {}, 'File overlays'));
1249 buffer.write('</p>'); 1278 buffer.write('</p>');
1279 buffer.write('<p>');
1280 buffer.write(makeLink(DIAGNOSTIC_PATH, {}, 'Diagnostic info'));
1281 buffer.write('</p>');
1250 }); 1282 });
1251 }); 1283 });
1252 } 1284 }
1253 1285
1254 /** 1286 /**
1255 * Return a two digit decimal representation of the given non-negative integer 1287 * Return a two digit decimal representation of the given non-negative integer
1256 * [value]. 1288 * [value].
1257 */ 1289 */
1258 String _twoDigit(int value) { 1290 String _twoDigit(int value) {
1259 if (value < 10) { 1291 if (value < 10) {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 <p><strong># Notifications</strong> - the total number of notifications 1474 <p><strong># Notifications</strong> - the total number of notifications
1443 sent to the client with completion results for this request. 1475 sent to the client with completion results for this request.
1444 <p><strong># Suggestions</strong> - the number of suggestions 1476 <p><strong># Suggestions</strong> - the number of suggestions
1445 sent to the client in the first notification, followed by a comma, 1477 sent to the client in the first notification, followed by a comma,
1446 followed by the number of suggestions send to the client 1478 followed by the number of suggestions send to the client
1447 in the last notification. If there is only one notification, 1479 in the last notification. If there is only one notification,
1448 then there will be only one number in this column.'''); 1480 then there will be only one number in this column.''');
1449 } 1481 }
1450 1482
1451 /** 1483 /**
1484 * Write the status of the diagnostic domain to the given [buffer].
1485 */
1486 void _writeDiagnosticStatus(StringBuffer buffer) {
1487 DiagnosticDomainHandler handler =
1488 new DiagnosticDomainHandler(_server.analysisServer);
1489
1490 var request = new DiagnosticGetDiagnosticsParams().toRequest('0');
1491
1492 var stopwatch = new Stopwatch();
1493 stopwatch.start();
1494 var response = handler.handleRequest(request);
1495 stopwatch.stop();
1496
1497 int elapsedMs = stopwatch.elapsedMilliseconds;
1498 _diagnosticCallAverage.addSample(elapsedMs);
1499
1500 buffer.write('<h3>Timing</h3>');
1501
1502 buffer.write('<p>');
1503 buffer.write('getDiagnostic (last call): $elapsedMs (ms)');
1504 buffer.write('<p>');
1505 buffer.write('getDiagnostic (rolling average): '
1506 '${_diagnosticCallAverage.value} (ms)');
1507 buffer.write('<p>&nbsp;');
1508
1509 var json = response.toJson()[Response.RESULT];
1510 List contexts = json['contexts'];
1511 for (var context in contexts) {
1512 buffer.write('<p>');
1513 buffer.write('<h3>${context["name"]}</h3>');
1514 buffer.write('<p>');
1515 buffer.write('explicitFileCount: ${context["explicitFileCount"]}');
1516 buffer.write('<p>');
1517 buffer.write('implicitFileCount: ${context["implicitFileCount"]}');
1518 buffer.write('<p>');
1519 buffer.write('workItemQueueLength: ${context["workItemQueueLength"]}');
1520 buffer.write('<p>');
1521 buffer.write('workItemQueueLengthAverage: '
1522 '${context["workItemQueueLengthAverage"]}');
1523 buffer.write('<p>&nbsp;');
1524 }
1525 }
1526
1527 /**
1452 * Write the status of the edit domain (on the main status page) to the given 1528 * Write the status of the edit domain (on the main status page) to the given
1453 * [buffer]. 1529 * [buffer].
1454 */ 1530 */
1455 void _writeEditStatus(StringBuffer buffer) { 1531 void _writeEditStatus(StringBuffer buffer) {
1456 buffer.write('<h3>Edit Domain</h3>'); 1532 buffer.write('<h3>Edit Domain</h3>');
1457 _writeTwoColumns(buffer, (StringBuffer buffer) { 1533 _writeTwoColumns(buffer, (StringBuffer buffer) {
1458 buffer.write('<p><b>Performance Data</b></p>'); 1534 buffer.write('<p><b>Performance Data</b></p>');
1459 buffer.write('<p>'); 1535 buffer.write('<p>');
1460 buffer.write(makeLink(COMPLETION_PATH, {}, 'Completion data')); 1536 buffer.write(makeLink(COMPLETION_PATH, {}, 'Completion data'));
1461 buffer.write('</p>'); 1537 buffer.write('</p>');
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 */ 2021 */
1946 static String makeLink( 2022 static String makeLink(
1947 String path, Map<String, String> params, String innerHtml, 2023 String path, Map<String, String> params, String innerHtml,
1948 [bool hasError = false]) { 2024 [bool hasError = false]) {
1949 Uri uri = new Uri(path: path, queryParameters: params); 2025 Uri uri = new Uri(path: path, queryParameters: params);
1950 String href = HTML_ESCAPE.convert(uri.toString()); 2026 String href = HTML_ESCAPE.convert(uri.toString());
1951 String classAttribute = hasError ? ' class="error"' : ''; 2027 String classAttribute = hasError ? ' class="error"' : '';
1952 return '<a href="$href"$classAttribute>$innerHtml</a>'; 2028 return '<a href="$href"$classAttribute>$innerHtml</a>';
1953 } 2029 }
1954 } 2030 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/domain_diagnostic.dart ('k') | pkg/analysis_server/lib/src/utilities/average.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698