| 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 analysis_server.src.get_handler; | 5 library analysis_server.src.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'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 import 'package:analysis_server/src/services/index/store/split_store.dart'; | 22 import 'package:analysis_server/src/services/index/store/split_store.dart'; |
| 23 import 'package:analysis_server/src/socket_server.dart'; | 23 import 'package:analysis_server/src/socket_server.dart'; |
| 24 import 'package:analysis_server/src/status/ast_writer.dart'; | 24 import 'package:analysis_server/src/status/ast_writer.dart'; |
| 25 import 'package:analysis_server/src/status/element_writer.dart'; | 25 import 'package:analysis_server/src/status/element_writer.dart'; |
| 26 import 'package:analyzer/file_system/file_system.dart'; | 26 import 'package:analyzer/file_system/file_system.dart'; |
| 27 import 'package:analyzer/src/generated/ast.dart'; | 27 import 'package:analyzer/src/generated/ast.dart'; |
| 28 import 'package:analyzer/src/generated/element.dart'; | 28 import 'package:analyzer/src/generated/element.dart'; |
| 29 import 'package:analyzer/src/generated/engine.dart'; | 29 import 'package:analyzer/src/generated/engine.dart'; |
| 30 import 'package:analyzer/src/generated/java_engine.dart'; | 30 import 'package:analyzer/src/generated/java_engine.dart'; |
| 31 import 'package:analyzer/src/generated/source.dart'; | 31 import 'package:analyzer/src/generated/source.dart'; |
| 32 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 32 | 33 |
| 33 import 'analysis_server.dart'; | 34 import 'analysis_server.dart'; |
| 34 | 35 |
| 35 /** | 36 /** |
| 36 * A function that can be used to generate HTML output into the given [buffer]. | 37 * A function that can be used to generate HTML output into the given [buffer]. |
| 37 * The HTML that is generated must be valid (special characters must already be | 38 * The HTML that is generated must be valid (special characters must already be |
| 38 * encoded). | 39 * encoded). |
| 39 */ | 40 */ |
| 40 typedef void HtmlGenerator(StringBuffer buffer); | 41 typedef void HtmlGenerator(StringBuffer buffer); |
| 41 | 42 |
| 42 /** | 43 /** |
| 43 * Instances of the class [GetHandler] handle GET requests. | 44 * Instances of the class [GetHandler] handle GET requests. |
| 44 */ | 45 */ |
| 45 class GetHandler { | 46 class GetHandler { |
| 46 /** | 47 /** |
| 47 * The path used to request the status of the analysis server as a whole. | 48 * The path used to request overall performance information. |
| 48 */ | 49 */ |
| 49 static const String STATUS_PATH = '/status'; | 50 static const String ANALYSIS_PERFORMANCE_PATH = '/perf/analysis'; |
| 50 | 51 |
| 51 /** | 52 /** |
| 52 * The path used to request information about a element model. | 53 * The path used to request information about a element model. |
| 53 */ | 54 */ |
| 54 static const String AST_PATH = '/ast'; | 55 static const String AST_PATH = '/ast'; |
| 55 | 56 |
| 56 /** | 57 /** |
| 57 * The path used to request information about the cache entry corresponding | 58 * The path used to request information about the cache entry corresponding |
| 58 * to a single file. | 59 * to a single file. |
| 59 */ | 60 */ |
| 60 static const String CACHE_ENTRY_PATH = '/cache_entry'; | 61 static const String CACHE_ENTRY_PATH = '/cache_entry'; |
| 61 | 62 |
| 62 /** | 63 /** |
| 63 * The path used to request the list of source files in a certain cache | 64 * The path used to request the list of source files in a certain cache |
| 64 * state. | 65 * state. |
| 65 */ | 66 */ |
| 66 static const String CACHE_STATE_PATH = '/cache_state'; | 67 static const String CACHE_STATE_PATH = '/cache_state'; |
| 67 | 68 |
| 68 /** | 69 /** |
| 69 * The path used to request code completion information. | 70 * The path used to request code completion information. |
| 70 */ | 71 */ |
| 71 static const String COMPLETION_PATH = '/completion'; | 72 static const String COMPLETION_PATH = '/completion'; |
| 72 | 73 |
| 73 /** | 74 /** |
| 75 * The path used to request communication performance information. |
| 76 */ |
| 77 static const String COMMUNICATION_PERFORMANCE_PATH = '/perf/communication'; |
| 78 |
| 79 /** |
| 74 * The path used to request information about a specific context. | 80 * The path used to request information about a specific context. |
| 75 */ | 81 */ |
| 76 static const String CONTEXT_PATH = '/context'; | 82 static const String CONTEXT_PATH = '/context'; |
| 77 | 83 |
| 78 /** | 84 /** |
| 79 * The path used to request information about a element model. | 85 * The path used to request information about a element model. |
| 80 */ | 86 */ |
| 81 static const String ELEMENT_PATH = '/element'; | 87 static const String ELEMENT_PATH = '/element'; |
| 82 | 88 |
| 83 /** | 89 /** |
| 84 * The path used to request information about elements with the given name. | 90 * The path used to request information about elements with the given name. |
| 85 */ | 91 */ |
| 86 static const String INDEX_ELEMENT_BY_NAME = '/index/element-by-name'; | 92 static const String INDEX_ELEMENT_BY_NAME = '/index/element-by-name'; |
| 87 | 93 |
| 88 /** | 94 /** |
| 89 * The path used to request an overlay contents. | 95 * The path used to request an overlay contents. |
| 90 */ | 96 */ |
| 91 static const String OVERLAY_PATH = '/overlay'; | 97 static const String OVERLAY_PATH = '/overlay'; |
| 92 | 98 |
| 93 /** | 99 /** |
| 94 * The path used to request overlays information. | 100 * The path used to request overlays information. |
| 95 */ | 101 */ |
| 96 static const String OVERLAYS_PATH = '/overlays'; | 102 static const String OVERLAYS_PATH = '/overlays'; |
| 97 | 103 |
| 98 /** | 104 /** |
| 99 * The path used to request overall performance information. | 105 * The path used to request the status of the analysis server as a whole. |
| 100 */ | 106 */ |
| 101 static const String PERFORMANCE_PATH = '/performance'; | 107 static const String STATUS_PATH = '/status'; |
| 102 | |
| 103 /** | |
| 104 * Query parameter used to represent the cache state to search for, when | |
| 105 * accessing [CACHE_STATE_PATH]. | |
| 106 */ | |
| 107 static const String STATE_QUERY_PARAM = 'state'; | |
| 108 | 108 |
| 109 /** | 109 /** |
| 110 * Query parameter used to represent the context to search for, when | 110 * Query parameter used to represent the context to search for, when |
| 111 * accessing [CACHE_ENTRY_PATH] or [CACHE_STATE_PATH]. | 111 * accessing [CACHE_ENTRY_PATH] or [CACHE_STATE_PATH]. |
| 112 */ | 112 */ |
| 113 static const String CONTEXT_QUERY_PARAM = 'context'; | 113 static const String CONTEXT_QUERY_PARAM = 'context'; |
| 114 | 114 |
| 115 /** | 115 /** |
| 116 * Query parameter used to represent the descriptor to search for, when | 116 * Query parameter used to represent the descriptor to search for, when |
| 117 * accessing [CACHE_STATE_PATH]. | 117 * accessing [CACHE_STATE_PATH]. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 128 * accessing [INDEX_ELEMENT_BY_NAME]. | 128 * accessing [INDEX_ELEMENT_BY_NAME]. |
| 129 */ | 129 */ |
| 130 static const String INDEX_ELEMENT_NAME = 'name'; | 130 static const String INDEX_ELEMENT_NAME = 'name'; |
| 131 | 131 |
| 132 /** | 132 /** |
| 133 * Query parameter used to represent the source to search for, when accessing | 133 * Query parameter used to represent the source to search for, when accessing |
| 134 * [CACHE_ENTRY_PATH]. | 134 * [CACHE_ENTRY_PATH]. |
| 135 */ | 135 */ |
| 136 static const String SOURCE_QUERY_PARAM = 'entry'; | 136 static const String SOURCE_QUERY_PARAM = 'entry'; |
| 137 | 137 |
| 138 /** |
| 139 * Query parameter used to represent the cache state to search for, when |
| 140 * accessing [CACHE_STATE_PATH]. |
| 141 */ |
| 142 static const String STATE_QUERY_PARAM = 'state'; |
| 143 |
| 138 static final ContentType _htmlContent = | 144 static final ContentType _htmlContent = |
| 139 new ContentType("text", "html", charset: "utf-8"); | 145 new ContentType("text", "html", charset: "utf-8"); |
| 140 | 146 |
| 141 /** | 147 /** |
| 142 * The socket server whose status is to be reported on. | 148 * The socket server whose status is to be reported on. |
| 143 */ | 149 */ |
| 144 SocketServer _server; | 150 SocketServer _server; |
| 145 | 151 |
| 146 /** | 152 /** |
| 147 * Buffer containing strings printed by the analysis server. | 153 * Buffer containing strings printed by the analysis server. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 173 orElse: () => null); | 179 orElse: () => null); |
| 174 } | 180 } |
| 175 | 181 |
| 176 /** | 182 /** |
| 177 * Handle a GET request received by the HTTP server. | 183 * Handle a GET request received by the HTTP server. |
| 178 */ | 184 */ |
| 179 void handleGetRequest(HttpRequest request) { | 185 void handleGetRequest(HttpRequest request) { |
| 180 String path = request.uri.path; | 186 String path = request.uri.path; |
| 181 if (path == STATUS_PATH) { | 187 if (path == STATUS_PATH) { |
| 182 _returnServerStatus(request); | 188 _returnServerStatus(request); |
| 189 } else if (path == ANALYSIS_PERFORMANCE_PATH) { |
| 190 _returnAnalysisPerformance(request); |
| 183 } else if (path == AST_PATH) { | 191 } else if (path == AST_PATH) { |
| 184 _returnAst(request); | 192 _returnAst(request); |
| 185 } else if (path == CACHE_STATE_PATH) { | 193 } else if (path == CACHE_STATE_PATH) { |
| 186 _returnCacheState(request); | 194 _returnCacheState(request); |
| 187 } else if (path == CACHE_ENTRY_PATH) { | 195 } else if (path == CACHE_ENTRY_PATH) { |
| 188 _returnCacheEntry(request); | 196 _returnCacheEntry(request); |
| 189 } else if (path == COMPLETION_PATH) { | 197 } else if (path == COMPLETION_PATH) { |
| 190 _returnCompletionInfo(request); | 198 _returnCompletionInfo(request); |
| 199 } else if (path == COMMUNICATION_PERFORMANCE_PATH) { |
| 200 _returnCommunicationPerformance(request); |
| 191 } else if (path == CONTEXT_PATH) { | 201 } else if (path == CONTEXT_PATH) { |
| 192 _returnContextInfo(request); | 202 _returnContextInfo(request); |
| 193 } else if (path == ELEMENT_PATH) { | 203 } else if (path == ELEMENT_PATH) { |
| 194 _returnElement(request); | 204 _returnElement(request); |
| 195 } else if (path == INDEX_ELEMENT_BY_NAME) { | 205 } else if (path == INDEX_ELEMENT_BY_NAME) { |
| 196 _returnIndexElementByName(request); | 206 _returnIndexElementByName(request); |
| 197 } else if (path == OVERLAY_PATH) { | 207 } else if (path == OVERLAY_PATH) { |
| 198 _returnOverlayContents(request); | 208 _returnOverlayContents(request); |
| 199 } else if (path == OVERLAYS_PATH) { | 209 } else if (path == OVERLAYS_PATH) { |
| 200 _returnOverlaysInfo(request); | 210 _returnOverlaysInfo(request); |
| 201 } else if (path == PERFORMANCE_PATH) { | |
| 202 _returnPerformance(request); | |
| 203 } else { | 211 } else { |
| 204 _returnUnknownRequest(request); | 212 _returnUnknownRequest(request); |
| 205 } | 213 } |
| 206 } | 214 } |
| 207 | 215 |
| 208 /** | 216 /** |
| 209 * Return the folder being managed by the given [analysisServer] that matches | 217 * Return the folder being managed by the given [analysisServer] that matches |
| 210 * the given [contextFilter], or `null` if there is none. | 218 * the given [contextFilter], or `null` if there is none. |
| 211 */ | 219 */ |
| 212 Folder _findFolder(AnalysisServer analysisServer, String contextFilter) { | 220 Folder _findFolder(AnalysisServer analysisServer, String contextFilter) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 239 AnalysisContext context) { | 247 AnalysisContext context) { |
| 240 for (Folder folder in folderMap.keys) { | 248 for (Folder folder in folderMap.keys) { |
| 241 if (folderMap[folder] == context) { | 249 if (folderMap[folder] == context) { |
| 242 return folder; | 250 return folder; |
| 243 } | 251 } |
| 244 } | 252 } |
| 245 return null; | 253 return null; |
| 246 } | 254 } |
| 247 | 255 |
| 248 /** | 256 /** |
| 257 * Return a response displaying overall performance information. |
| 258 */ |
| 259 void _returnAnalysisPerformance(HttpRequest request) { |
| 260 AnalysisServer analysisServer = _server.analysisServer; |
| 261 if (analysisServer == null) { |
| 262 return _returnFailure(request, 'Analysis server is not running'); |
| 263 } |
| 264 _writeResponse(request, (StringBuffer buffer) { |
| 265 _writePage( |
| 266 buffer, |
| 267 'Analysis Server - Analysis Performance', |
| 268 [], |
| 269 (StringBuffer buffer) { |
| 270 void writeRow(TimeCounter counter, String label) { |
| 271 _writeRow(buffer, [counter.result, label], classes: ["right", null]); |
| 272 } |
| 273 |
| 274 buffer.write('<h3>Analysis Performance</h3>'); |
| 275 buffer.write('<p><b>Time spent in each phase of analysis</b></p>'); |
| 276 buffer.write( |
| 277 '<table style="border-collapse: separate; border-spacing: 10px 5px;"
>'); |
| 278 _writeRow(buffer, ['Time (in ms)', 'Analysis Phase'], header: true); |
| 279 writeRow(PerformanceStatistics.io, 'io'); |
| 280 writeRow(PerformanceStatistics.scan, 'scan'); |
| 281 writeRow(PerformanceStatistics.parse, 'parse'); |
| 282 writeRow(PerformanceStatistics.resolve, 'resolve'); |
| 283 writeRow(PerformanceStatistics.errors, 'errors'); |
| 284 writeRow(PerformanceStatistics.hints, 'hints'); |
| 285 writeRow(PerformanceStatistics.lint, 'lint'); |
| 286 buffer.write('</table>'); |
| 287 |
| 288 Map<DataDescriptor, int> countMap = SourceEntry.unflushedCountMap; |
| 289 buffer.write('<p><b>Number of times flushed data was re-created</b></p>'
); |
| 290 if (countMap.isEmpty) { |
| 291 buffer.write('<p>none</p>'); |
| 292 } else { |
| 293 List<DataDescriptor> keys = countMap.keys.toList(); |
| 294 keys.sort( |
| 295 (DataDescriptor first, DataDescriptor second) => |
| 296 first.toString().compareTo(second.toString())); |
| 297 buffer.write( |
| 298 '<table style="border-collapse: separate; border-spacing: 10px 5px
;">'); |
| 299 _writeRow(buffer, ['Count', 'Data'], header: true); |
| 300 for (DataDescriptor key in keys) { |
| 301 _writeRow( |
| 302 buffer, |
| 303 [countMap[key], key.toString()], |
| 304 classes: ["right", null]); |
| 305 } |
| 306 buffer.write('</table>'); |
| 307 } |
| 308 }); |
| 309 }); |
| 310 } |
| 311 |
| 312 /** |
| 249 * Return a response containing information about an AST structure. | 313 * Return a response containing information about an AST structure. |
| 250 */ | 314 */ |
| 251 void _returnAst(HttpRequest request) { | 315 void _returnAst(HttpRequest request) { |
| 252 AnalysisServer analysisServer = _server.analysisServer; | 316 AnalysisServer analysisServer = _server.analysisServer; |
| 253 if (analysisServer == null) { | 317 if (analysisServer == null) { |
| 254 return _returnFailure(request, 'Analysis server not running'); | 318 return _returnFailure(request, 'Analysis server not running'); |
| 255 } | 319 } |
| 256 String contextFilter = request.uri.queryParameters[CONTEXT_QUERY_PARAM]; | 320 String contextFilter = request.uri.queryParameters[CONTEXT_QUERY_PARAM]; |
| 257 if (contextFilter == null) { | 321 if (contextFilter == null) { |
| 258 return _returnFailure( | 322 return _returnFailure( |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 buffer.write('<ul>'); | 556 buffer.write('<ul>'); |
| 493 links.forEach((String link) { | 557 links.forEach((String link) { |
| 494 buffer.write('<li>$link</li>'); | 558 buffer.write('<li>$link</li>'); |
| 495 }); | 559 }); |
| 496 buffer.write('</ul>'); | 560 buffer.write('</ul>'); |
| 497 }); | 561 }); |
| 498 }); | 562 }); |
| 499 } | 563 } |
| 500 | 564 |
| 501 /** | 565 /** |
| 566 * Return a response displaying overall performance information. |
| 567 */ |
| 568 void _returnCommunicationPerformance(HttpRequest request) { |
| 569 AnalysisServer analysisServer = _server.analysisServer; |
| 570 if (analysisServer == null) { |
| 571 return _returnFailure(request, 'Analysis server is not running'); |
| 572 } |
| 573 _writeResponse(request, (StringBuffer buffer) { |
| 574 _writePage( |
| 575 buffer, |
| 576 'Analysis Server - Communication Performance', |
| 577 [], |
| 578 (StringBuffer buffer) { |
| 579 buffer.write('<h3>Communication Performance</h3>'); |
| 580 _writeTwoColumns(buffer, (StringBuffer buffer) { |
| 581 ServerPerformance perf = analysisServer.performanceDuringStartup; |
| 582 int requestCount = perf.requestCount; |
| 583 num averageLatency = |
| 584 requestCount > 0 ? (perf.requestLatency / requestCount).round() :
0; |
| 585 int maximumLatency = perf.maxLatency; |
| 586 num slowRequestPercent = |
| 587 requestCount > 0 ? (perf.slowRequestCount * 100 / requestCount).ro
und() : 0; |
| 588 buffer.write('<h4>Startup</h4>'); |
| 589 buffer.write('<table>'); |
| 590 _writeRow( |
| 591 buffer, |
| 592 [requestCount, 'requests'], |
| 593 classes: ["right", null]); |
| 594 _writeRow( |
| 595 buffer, |
| 596 [averageLatency, 'ms average latency'], |
| 597 classes: ["right", null]); |
| 598 _writeRow( |
| 599 buffer, |
| 600 [maximumLatency, 'ms maximum latency'], |
| 601 classes: ["right", null]); |
| 602 _writeRow( |
| 603 buffer, |
| 604 [slowRequestPercent, '% > 150 ms latency'], |
| 605 classes: ["right", null]); |
| 606 if (analysisServer.performanceAfterStartup != null) { |
| 607 int startupTime = |
| 608 analysisServer.performanceAfterStartup.startTime - |
| 609 perf.startTime; |
| 610 _writeRow( |
| 611 buffer, |
| 612 [startupTime, 'ms for initial analysis to complete']); |
| 613 } |
| 614 buffer.write('</table>'); |
| 615 }, (StringBuffer buffer) { |
| 616 ServerPerformance perf = analysisServer.performanceAfterStartup; |
| 617 if (perf == null) { |
| 618 return; |
| 619 } |
| 620 int requestCount = perf.requestCount; |
| 621 num averageLatency = |
| 622 requestCount > 0 ? (perf.requestLatency * 10 / requestCount).round
() / 10 : 0; |
| 623 int maximumLatency = perf.maxLatency; |
| 624 num slowRequestPercent = |
| 625 requestCount > 0 ? (perf.slowRequestCount * 100 / requestCount).ro
und() : 0; |
| 626 buffer.write('<h4>Current</h4>'); |
| 627 buffer.write('<table>'); |
| 628 _writeRow( |
| 629 buffer, |
| 630 [requestCount, 'requests'], |
| 631 classes: ["right", null]); |
| 632 _writeRow( |
| 633 buffer, |
| 634 [averageLatency, 'ms average latency'], |
| 635 classes: ["right", null]); |
| 636 _writeRow( |
| 637 buffer, |
| 638 [maximumLatency, 'ms maximum latency'], |
| 639 classes: ["right", null]); |
| 640 _writeRow( |
| 641 buffer, |
| 642 [slowRequestPercent, '% > 150 ms latency'], |
| 643 classes: ["right", null]); |
| 644 buffer.write('</table>'); |
| 645 }); |
| 646 }); |
| 647 }); |
| 648 } |
| 649 |
| 650 /** |
| 502 * Return a response displaying code completion information. | 651 * Return a response displaying code completion information. |
| 503 */ | 652 */ |
| 504 void _returnCompletionInfo(HttpRequest request) { | 653 void _returnCompletionInfo(HttpRequest request) { |
| 505 String value = request.requestedUri.queryParameters['index']; | 654 String value = request.requestedUri.queryParameters['index']; |
| 506 int index = value != null ? int.parse(value, onError: (_) => 0) : 0; | 655 int index = value != null ? int.parse(value, onError: (_) => 0) : 0; |
| 507 _writeResponse(request, (StringBuffer buffer) { | 656 _writeResponse(request, (StringBuffer buffer) { |
| 508 _writePage( | 657 _writePage( |
| 509 buffer, | 658 buffer, |
| 510 'Analysis Server - Completion Stats', | 659 'Analysis Server - Completion Stats', |
| 511 [], | 660 [], |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 _overlayContents[count] = contents; | 955 _overlayContents[count] = contents; |
| 807 }); | 956 }); |
| 808 }); | 957 }); |
| 809 buffer.write('<tr><td colspan="2">Total: $count entries.</td></tr>'); | 958 buffer.write('<tr><td colspan="2">Total: $count entries.</td></tr>'); |
| 810 buffer.write('</table>'); | 959 buffer.write('</table>'); |
| 811 }); | 960 }); |
| 812 }); | 961 }); |
| 813 } | 962 } |
| 814 | 963 |
| 815 /** | 964 /** |
| 816 * Return a response displaying overall performance information. | |
| 817 */ | |
| 818 void _returnPerformance(HttpRequest request) { | |
| 819 AnalysisServer analysisServer = _server.analysisServer; | |
| 820 if (analysisServer == null) { | |
| 821 return _returnFailure(request, 'Analysis server is not running'); | |
| 822 } | |
| 823 _writeResponse(request, (StringBuffer buffer) { | |
| 824 _writePage( | |
| 825 buffer, | |
| 826 'Analysis Server - Performance', | |
| 827 [], | |
| 828 (StringBuffer buffer) { | |
| 829 buffer.write('<h3>Communication Performance</h3>'); | |
| 830 _writeTwoColumns(buffer, (StringBuffer buffer) { | |
| 831 ServerPerformance perf = analysisServer.performanceDuringStartup; | |
| 832 int requestCount = perf.requestCount; | |
| 833 num averageLatency = | |
| 834 requestCount > 0 ? (perf.requestLatency / requestCount).round() :
0; | |
| 835 int maximumLatency = perf.maxLatency; | |
| 836 num slowRequestPercent = | |
| 837 requestCount > 0 ? (perf.slowRequestCount * 100 / requestCount).ro
und() : 0; | |
| 838 buffer.write('<h4>Startup</h4>'); | |
| 839 buffer.write('<table>'); | |
| 840 _writeRow( | |
| 841 buffer, | |
| 842 [requestCount, 'requests'], | |
| 843 classes: ["right", null]); | |
| 844 _writeRow( | |
| 845 buffer, | |
| 846 [averageLatency, 'ms average latency'], | |
| 847 classes: ["right", null]); | |
| 848 _writeRow( | |
| 849 buffer, | |
| 850 [maximumLatency, 'ms maximum latency'], | |
| 851 classes: ["right", null]); | |
| 852 _writeRow( | |
| 853 buffer, | |
| 854 [slowRequestPercent, '% > 150 ms latency'], | |
| 855 classes: ["right", null]); | |
| 856 if (analysisServer.performanceAfterStartup != null) { | |
| 857 int startupTime = | |
| 858 analysisServer.performanceAfterStartup.startTime - | |
| 859 perf.startTime; | |
| 860 _writeRow( | |
| 861 buffer, | |
| 862 [startupTime, 'ms for initial analysis to complete']); | |
| 863 } | |
| 864 buffer.write('</table>'); | |
| 865 }, (StringBuffer buffer) { | |
| 866 ServerPerformance perf = analysisServer.performanceAfterStartup; | |
| 867 if (perf == null) { | |
| 868 return; | |
| 869 } | |
| 870 int requestCount = perf.requestCount; | |
| 871 num averageLatency = | |
| 872 requestCount > 0 ? (perf.requestLatency * 10 / requestCount).round
() / 10 : 0; | |
| 873 int maximumLatency = perf.maxLatency; | |
| 874 num slowRequestPercent = | |
| 875 requestCount > 0 ? (perf.slowRequestCount * 100 / requestCount).ro
und() : 0; | |
| 876 buffer.write('<h4>Current</h4>'); | |
| 877 buffer.write('<table>'); | |
| 878 _writeRow( | |
| 879 buffer, | |
| 880 [requestCount, 'requests'], | |
| 881 classes: ["right", null]); | |
| 882 _writeRow( | |
| 883 buffer, | |
| 884 [averageLatency, 'ms average latency'], | |
| 885 classes: ["right", null]); | |
| 886 _writeRow( | |
| 887 buffer, | |
| 888 [maximumLatency, 'ms maximum latency'], | |
| 889 classes: ["right", null]); | |
| 890 _writeRow( | |
| 891 buffer, | |
| 892 [slowRequestPercent, '% > 150 ms latency'], | |
| 893 classes: ["right", null]); | |
| 894 buffer.write('</table>'); | |
| 895 }); | |
| 896 }); | |
| 897 }); | |
| 898 } | |
| 899 | |
| 900 /** | |
| 901 * Return a response indicating the status of the analysis server. | 965 * Return a response indicating the status of the analysis server. |
| 902 */ | 966 */ |
| 903 void _returnServerStatus(HttpRequest request) { | 967 void _returnServerStatus(HttpRequest request) { |
| 904 _writeResponse(request, (StringBuffer buffer) { | 968 _writeResponse(request, (StringBuffer buffer) { |
| 905 _writePage(buffer, 'Analysis Server - Status', [], (StringBuffer buffer) { | 969 _writePage(buffer, 'Analysis Server - Status', [], (StringBuffer buffer) { |
| 906 if (_writeServerStatus(buffer)) { | 970 if (_writeServerStatus(buffer)) { |
| 907 _writeAnalysisStatus(buffer); | 971 _writeAnalysisStatus(buffer); |
| 908 _writeEditStatus(buffer); | 972 _writeEditStatus(buffer); |
| 909 _writeExecutionStatus(buffer); | 973 _writeExecutionStatus(buffer); |
| 910 _writeRecentOutput(buffer); | 974 _writeRecentOutput(buffer); |
| 911 } | 975 } |
| 912 }); | 976 }); |
| 913 }); | 977 }); |
| 914 } | 978 } |
| 915 | 979 |
| 916 /** | 980 /** |
| 917 * Return an error in response to an unrecognized request received by the HTTP | 981 * Return an error in response to an unrecognized request received by the HTTP |
| 918 * server. | 982 * server. |
| 919 */ | 983 */ |
| 920 void _returnUnknownRequest(HttpRequest request) { | 984 void _returnUnknownRequest(HttpRequest request) { |
| 921 _writeResponse(request, (StringBuffer buffer) { | 985 _writeResponse(request, (StringBuffer buffer) { |
| 922 _writePage(buffer, 'Analysis Server', [], (StringBuffer buffer) { | 986 _writePage(buffer, 'Analysis Server', [], (StringBuffer buffer) { |
| 923 buffer.write('<h3>Pages</h3>'); | 987 buffer.write('<h3>Pages</h3>'); |
| 924 buffer.write('<p>'); | 988 buffer.write('<p>'); |
| 925 buffer.write(makeLink(COMPLETION_PATH, {}, 'Completion data')); | 989 buffer.write(makeLink(COMPLETION_PATH, {}, 'Completion data')); |
| 926 buffer.write('</p>'); | 990 buffer.write('</p>'); |
| 927 buffer.write('<p>'); | 991 buffer.write('<p>'); |
| 928 buffer.write(makeLink(PERFORMANCE_PATH, {}, 'Performance')); | 992 buffer.write( |
| 993 makeLink(COMMUNICATION_PERFORMANCE_PATH, {}, 'Performance')); |
| 929 buffer.write('</p>'); | 994 buffer.write('</p>'); |
| 930 buffer.write('<p>'); | 995 buffer.write('<p>'); |
| 931 buffer.write(makeLink(STATUS_PATH, {}, 'Server status')); | 996 buffer.write(makeLink(STATUS_PATH, {}, 'Server status')); |
| 932 buffer.write('</p>'); | 997 buffer.write('</p>'); |
| 933 }); | 998 }); |
| 934 }); | 999 }); |
| 935 } | 1000 } |
| 936 | 1001 |
| 937 /** | 1002 /** |
| 938 * Return a two digit decimal representation of the given non-negative integer | 1003 * Return a two digit decimal representation of the given non-negative integer |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 options.incrementalApi); | 1075 options.incrementalApi); |
| 1011 _writeOption( | 1076 _writeOption( |
| 1012 buffer, | 1077 buffer, |
| 1013 'Preserve comments', | 1078 'Preserve comments', |
| 1014 options.preserveComments, | 1079 options.preserveComments, |
| 1015 last: true); | 1080 last: true); |
| 1016 buffer.write('</p>'); | 1081 buffer.write('</p>'); |
| 1017 int freq = AnalysisServer.performOperationDelayFreqency; | 1082 int freq = AnalysisServer.performOperationDelayFreqency; |
| 1018 String delay = freq > 0 ? '1 ms every $freq ms' : 'off'; | 1083 String delay = freq > 0 ? '1 ms every $freq ms' : 'off'; |
| 1019 buffer.write('<p><b>perform operation delay:</b> $delay</p>'); | 1084 buffer.write('<p><b>perform operation delay:</b> $delay</p>'); |
| 1085 |
| 1086 buffer.write('<p><b>Performance Data</b></p>'); |
| 1087 buffer.write('<p>'); |
| 1088 buffer.write(makeLink(ANALYSIS_PERFORMANCE_PATH, {}, 'Task data')); |
| 1089 buffer.write('</p>'); |
| 1020 }, (StringBuffer buffer) { | 1090 }, (StringBuffer buffer) { |
| 1021 _writeSubscriptionMap( | 1091 _writeSubscriptionMap( |
| 1022 buffer, | 1092 buffer, |
| 1023 AnalysisService.VALUES, | 1093 AnalysisService.VALUES, |
| 1024 analysisServer.analysisServices); | 1094 analysisServer.analysisServices); |
| 1025 }); | 1095 }); |
| 1026 } | 1096 } |
| 1027 | 1097 |
| 1028 /** | 1098 /** |
| 1029 * Write performance information about a specific completion request | 1099 * Write performance information about a specific completion request |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1397 } else { | 1467 } else { |
| 1398 buffer.write('Inactive'); | 1468 buffer.write('Inactive'); |
| 1399 } | 1469 } |
| 1400 buffer.write('<br>'); | 1470 buffer.write('<br>'); |
| 1401 buffer.write('Version: '); | 1471 buffer.write('Version: '); |
| 1402 buffer.write(AnalysisServer.VERSION); | 1472 buffer.write(AnalysisServer.VERSION); |
| 1403 buffer.write('</p>'); | 1473 buffer.write('</p>'); |
| 1404 | 1474 |
| 1405 buffer.write('<p><b>Performance Data</b></p>'); | 1475 buffer.write('<p><b>Performance Data</b></p>'); |
| 1406 buffer.write('<p>'); | 1476 buffer.write('<p>'); |
| 1407 buffer.write(makeLink(PERFORMANCE_PATH, {}, 'Communication performance')); | 1477 buffer.write( |
| 1478 makeLink(COMMUNICATION_PERFORMANCE_PATH, {}, 'Communication performanc
e')); |
| 1408 buffer.write('</p>'); | 1479 buffer.write('</p>'); |
| 1409 }, (StringBuffer buffer) { | 1480 }, (StringBuffer buffer) { |
| 1410 _writeSubscriptionList(buffer, ServerService.VALUES, services); | 1481 _writeSubscriptionList(buffer, ServerService.VALUES, services); |
| 1411 }); | 1482 }); |
| 1412 return true; | 1483 return true; |
| 1413 } | 1484 } |
| 1414 | 1485 |
| 1415 /** | 1486 /** |
| 1416 * Write a representation of the given [stackTrace] to the given [buffer]. | 1487 * Write a representation of the given [stackTrace] to the given [buffer]. |
| 1417 */ | 1488 */ |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1551 * 'error'. | 1622 * 'error'. |
| 1552 */ | 1623 */ |
| 1553 static String makeLink(String path, Map<String, String> params, | 1624 static String makeLink(String path, Map<String, String> params, |
| 1554 String innerHtml, [bool hasError = false]) { | 1625 String innerHtml, [bool hasError = false]) { |
| 1555 Uri uri = new Uri(path: path, queryParameters: params); | 1626 Uri uri = new Uri(path: path, queryParameters: params); |
| 1556 String href = HTML_ESCAPE.convert(uri.toString()); | 1627 String href = HTML_ESCAPE.convert(uri.toString()); |
| 1557 String classAttribute = hasError ? ' class="error"' : ''; | 1628 String classAttribute = hasError ? ' class="error"' : ''; |
| 1558 return '<a href="$href"$classAttribute>$innerHtml</a>'; | 1629 return '<a href="$href"$classAttribute>$innerHtml</a>'; |
| 1559 } | 1630 } |
| 1560 } | 1631 } |
| OLD | NEW |