| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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:convert'; | 5 import 'dart:convert'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; |
| 10 import 'package:analysis_server/src/analysis_server.dart'; | 10 import 'package:analysis_server/src/analysis_server.dart'; |
| 11 import 'package:analysis_server/src/domain_completion.dart'; | 11 import 'package:analysis_server/src/domain_completion.dart'; |
| 12 import 'package:analysis_server/src/domain_diagnostic.dart'; | 12 import 'package:analysis_server/src/domain_diagnostic.dart'; |
| 13 import 'package:analysis_server/src/domain_execution.dart'; | 13 import 'package:analysis_server/src/domain_execution.dart'; |
| 14 import 'package:analysis_server/src/services/completion/completion_performance.d
art'; | 14 import 'package:analysis_server/src/services/completion/completion_performance.d
art'; |
| 15 import 'package:analysis_server/src/socket_server.dart'; | 15 import 'package:analysis_server/src/socket_server.dart'; |
| 16 import 'package:analysis_server/src/status/get_handler.dart'; | 16 import 'package:analysis_server/src/status/get_handler.dart'; |
| 17 import 'package:analyzer/exception/exception.dart'; | 17 import 'package:analyzer/exception/exception.dart'; |
| 18 import 'package:analyzer/file_system/file_system.dart'; | 18 import 'package:analyzer/file_system/file_system.dart'; |
| 19 import 'package:analyzer/source/error_processor.dart'; | 19 import 'package:analyzer/source/error_processor.dart'; |
| 20 import 'package:analyzer/source/sdk_ext.dart'; | 20 import 'package:analyzer/source/sdk_ext.dart'; |
| 21 import 'package:analyzer/src/context/source.dart'; | 21 import 'package:analyzer/src/context/source.dart'; |
| 22 import 'package:analyzer/src/dart/analysis/driver.dart'; | 22 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 23 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 23 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| 24 import 'package:analyzer/src/generated/engine.dart'; | 24 import 'package:analyzer/src/generated/engine.dart'; |
| 25 import 'package:analyzer/src/generated/sdk.dart'; | 25 import 'package:analyzer/src/generated/sdk.dart'; |
| 26 import 'package:analyzer/src/generated/source.dart'; | 26 import 'package:analyzer/src/generated/source.dart'; |
| 27 import 'package:analyzer/src/generated/utilities_general.dart'; | 27 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 28 import 'package:analyzer/src/services/lint.dart'; | 28 import 'package:analyzer/src/services/lint.dart'; |
| 29 import 'package:analyzer/task/model.dart'; | 29 import 'package:analyzer/task/model.dart'; |
| 30 import 'package:path/path.dart' as path; |
| 30 import 'package:plugin/plugin.dart'; | 31 import 'package:plugin/plugin.dart'; |
| 31 | 32 |
| 32 /** | 33 /** |
| 33 * A function that can be used to generate HTML output into the given [buffer]. | 34 * A function that can be used to generate HTML output into the given [buffer]. |
| 34 * The HTML that is generated must be valid (special characters must already be | 35 * The HTML that is generated must be valid (special characters must already be |
| 35 * encoded). | 36 * encoded). |
| 36 */ | 37 */ |
| 37 typedef void HtmlGenerator(StringBuffer buffer); | 38 typedef void HtmlGenerator(StringBuffer buffer); |
| 38 | 39 |
| 39 /** | 40 /** |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 191 |
| 191 /** | 192 /** |
| 192 * Return a response displaying overall performance information. | 193 * Return a response displaying overall performance information. |
| 193 */ | 194 */ |
| 194 void _returnAnalysisPerformance(HttpRequest request) { | 195 void _returnAnalysisPerformance(HttpRequest request) { |
| 195 AnalysisServer analysisServer = _server.analysisServer; | 196 AnalysisServer analysisServer = _server.analysisServer; |
| 196 if (analysisServer == null) { | 197 if (analysisServer == null) { |
| 197 return _returnFailure(request, 'Analysis server is not running'); | 198 return _returnFailure(request, 'Analysis server is not running'); |
| 198 } | 199 } |
| 199 _writeResponse(request, (StringBuffer buffer) { | 200 _writeResponse(request, (StringBuffer buffer) { |
| 200 _writePage(buffer, 'Analysis Server - Analysis Performance', [], | 201 _writePage(buffer, 'Analysis Performance', [], (StringBuffer buffer) { |
| 201 (StringBuffer buffer) { | |
| 202 buffer.write('<h3>Analysis Performance</h3>'); | 202 buffer.write('<h3>Analysis Performance</h3>'); |
| 203 _writeTwoColumns(buffer, (StringBuffer buffer) { | 203 _writeTwoColumns(buffer, (StringBuffer buffer) { |
| 204 // | 204 // |
| 205 // Write performance tags. | 205 // Write performance tags. |
| 206 // | 206 // |
| 207 buffer.write('<p><b>Performance tag data</b></p>'); | 207 buffer.write('<p><b>Performance tag data</b></p>'); |
| 208 buffer.write( | 208 buffer.write( |
| 209 '<table style="border-collapse: separate; border-spacing: 10px 5px
;">'); | 209 '<table style="border-collapse: separate; border-spacing: 10px 5px
;">'); |
| 210 _writeRow(buffer, ['Time (in ms)', 'Percent', 'Tag name'], | 210 _writeRow(buffer, ['Time (in ms)', 'Percent', 'Tag name'], |
| 211 header: true); | 211 header: true); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 280 |
| 281 /** | 281 /** |
| 282 * Return a response displaying overall performance information. | 282 * Return a response displaying overall performance information. |
| 283 */ | 283 */ |
| 284 void _returnCommunicationPerformance(HttpRequest request) { | 284 void _returnCommunicationPerformance(HttpRequest request) { |
| 285 AnalysisServer analysisServer = _server.analysisServer; | 285 AnalysisServer analysisServer = _server.analysisServer; |
| 286 if (analysisServer == null) { | 286 if (analysisServer == null) { |
| 287 return _returnFailure(request, 'Analysis server is not running'); | 287 return _returnFailure(request, 'Analysis server is not running'); |
| 288 } | 288 } |
| 289 _writeResponse(request, (StringBuffer buffer) { | 289 _writeResponse(request, (StringBuffer buffer) { |
| 290 _writePage(buffer, 'Analysis Server - Communication Performance', [], | 290 _writePage(buffer, 'Communication Performance', [], |
| 291 (StringBuffer buffer) { | 291 (StringBuffer buffer) { |
| 292 buffer.write('<h3>Communication Performance</h3>'); | 292 buffer.write('<h3>Communication Performance</h3>'); |
| 293 _writeTwoColumns(buffer, (StringBuffer buffer) { | 293 _writeTwoColumns(buffer, (StringBuffer buffer) { |
| 294 ServerPerformance perf = analysisServer.performanceDuringStartup; | 294 ServerPerformance perf = analysisServer.performanceDuringStartup; |
| 295 int requestCount = perf.requestCount; | 295 int requestCount = perf.requestCount; |
| 296 num averageLatency = requestCount > 0 | 296 num averageLatency = requestCount > 0 |
| 297 ? (perf.requestLatency / requestCount).round() | 297 ? (perf.requestLatency / requestCount).round() |
| 298 : 0; | 298 : 0; |
| 299 int maximumLatency = perf.maxLatency; | 299 int maximumLatency = perf.maxLatency; |
| 300 num slowRequestPercent = requestCount > 0 | 300 num slowRequestPercent = requestCount > 0 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 }); | 346 }); |
| 347 } | 347 } |
| 348 | 348 |
| 349 /** | 349 /** |
| 350 * Return a response displaying code completion information. | 350 * Return a response displaying code completion information. |
| 351 */ | 351 */ |
| 352 void _returnCompletionInfo(HttpRequest request) { | 352 void _returnCompletionInfo(HttpRequest request) { |
| 353 String value = request.requestedUri.queryParameters['index']; | 353 String value = request.requestedUri.queryParameters['index']; |
| 354 int index = value != null ? int.parse(value, onError: (_) => 0) : 0; | 354 int index = value != null ? int.parse(value, onError: (_) => 0) : 0; |
| 355 _writeResponse(request, (StringBuffer buffer) { | 355 _writeResponse(request, (StringBuffer buffer) { |
| 356 _writePage(buffer, 'Analysis Server - Completion Stats', [], | 356 _writePage(buffer, 'Completion Stats', [], (StringBuffer buffer) { |
| 357 (StringBuffer buffer) { | |
| 358 _writeCompletionPerformanceDetail(buffer, index); | 357 _writeCompletionPerformanceDetail(buffer, index); |
| 359 _writeCompletionPerformanceList(buffer); | 358 _writeCompletionPerformanceList(buffer); |
| 360 }); | 359 }); |
| 361 }); | 360 }); |
| 362 } | 361 } |
| 363 | 362 |
| 364 /** | 363 /** |
| 365 * Return a response containing information about a single source file in the | 364 * Return a response containing information about a single source file in the |
| 366 * cache. | 365 * cache. |
| 367 */ | 366 */ |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 _writeOption(buffer, 'Preserve comments', options.preserveComments); | 438 _writeOption(buffer, 'Preserve comments', options.preserveComments); |
| 440 _writeOption(buffer, 'Strong mode', options.strongMode); | 439 _writeOption(buffer, 'Strong mode', options.strongMode); |
| 441 _writeOption(buffer, 'Strong mode hints', options.strongModeHints); | 440 _writeOption(buffer, 'Strong mode hints', options.strongModeHints); |
| 442 if (writeAdditionalOptions != null) { | 441 if (writeAdditionalOptions != null) { |
| 443 writeAdditionalOptions(buffer); | 442 writeAdditionalOptions(buffer); |
| 444 } | 443 } |
| 445 buffer.write('</p>'); | 444 buffer.write('</p>'); |
| 446 } | 445 } |
| 447 | 446 |
| 448 _writeResponse(request, (StringBuffer buffer) { | 447 _writeResponse(request, (StringBuffer buffer) { |
| 449 _writePage( | 448 String contextName = path.basename(contextFilter); |
| 450 buffer, 'Analysis Server - Context', ['Context: $contextFilter'], | 449 _writePage(buffer, 'Context: $contextName', [contextFilter], |
| 451 (StringBuffer buffer) { | 450 (StringBuffer buffer) { |
| 452 buffer.write('<h3>Configuration</h3>'); | 451 buffer.write('<h3>Configuration</h3>'); |
| 453 | 452 |
| 454 _writeColumns(buffer, <HtmlGenerator>[ | 453 _writeColumns(buffer, <HtmlGenerator>[ |
| 455 (StringBuffer buffer) { | 454 (StringBuffer buffer) { |
| 456 buffer.write('<p><b>Context Options</b></p>'); | 455 buffer.write('<p><b>Context Options</b></p>'); |
| 457 writeOptions(buffer, driver.analysisOptions); | 456 writeOptions(buffer, driver.analysisOptions); |
| 458 }, | 457 }, |
| 459 (StringBuffer buffer) { | 458 (StringBuffer buffer) { |
| 460 buffer.write('<p><b>SDK Context Options</b></p>'); | 459 buffer.write('<p><b>SDK Context Options</b></p>'); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 // exceptions.forEach((CaughtException exception) { | 531 // exceptions.forEach((CaughtException exception) { |
| 533 // _writeException(buffer, exception); | 532 // _writeException(buffer, exception); |
| 534 // }); | 533 // }); |
| 535 // } | 534 // } |
| 536 }); | 535 }); |
| 537 }); | 536 }); |
| 538 } | 537 } |
| 539 | 538 |
| 540 void _returnFailure(HttpRequest request, String message) { | 539 void _returnFailure(HttpRequest request, String message) { |
| 541 _writeResponse(request, (StringBuffer buffer) { | 540 _writeResponse(request, (StringBuffer buffer) { |
| 542 _writePage(buffer, 'Analysis Server - Failure', [], | 541 _writePage(buffer, 'Failure', [], (StringBuffer buffer) { |
| 543 (StringBuffer buffer) { | |
| 544 buffer.write(HTML_ESCAPE.convert(message)); | 542 buffer.write(HTML_ESCAPE.convert(message)); |
| 545 }); | 543 }); |
| 546 }); | 544 }); |
| 547 } | 545 } |
| 548 | 546 |
| 549 void _returnOverlayContents(HttpRequest request) { | 547 void _returnOverlayContents(HttpRequest request) { |
| 550 String path = request.requestedUri.queryParameters[PATH_PARAM]; | 548 String path = request.requestedUri.queryParameters[PATH_PARAM]; |
| 551 if (path == null) { | 549 if (path == null) { |
| 552 return _returnFailure(request, 'Query parameter $PATH_PARAM required'); | 550 return _returnFailure(request, 'Query parameter $PATH_PARAM required'); |
| 553 } | 551 } |
| 554 String contents = _overlayContents[path]; | 552 String contents = _overlayContents[path]; |
| 555 | 553 |
| 556 _writeResponse(request, (StringBuffer buffer) { | 554 _writeResponse(request, (StringBuffer buffer) { |
| 557 _writePage(buffer, 'Analysis Server - Overlay', [], | 555 _writePage(buffer, 'Overlay', [], (StringBuffer buffer) { |
| 558 (StringBuffer buffer) { | |
| 559 buffer.write('<pre>${HTML_ESCAPE.convert(contents)}</pre>'); | 556 buffer.write('<pre>${HTML_ESCAPE.convert(contents)}</pre>'); |
| 560 }); | 557 }); |
| 561 }); | 558 }); |
| 562 } | 559 } |
| 563 | 560 |
| 564 /** | 561 /** |
| 565 * Return a response displaying overlays information. | 562 * Return a response displaying overlays information. |
| 566 */ | 563 */ |
| 567 void _returnOverlaysInfo(HttpRequest request) { | 564 void _returnOverlaysInfo(HttpRequest request) { |
| 568 AnalysisServer analysisServer = _server.analysisServer; | 565 AnalysisServer analysisServer = _server.analysisServer; |
| 569 if (analysisServer == null) { | 566 if (analysisServer == null) { |
| 570 return _returnFailure(request, 'Analysis server is not running'); | 567 return _returnFailure(request, 'Analysis server is not running'); |
| 571 } | 568 } |
| 572 | 569 |
| 573 _writeResponse(request, (StringBuffer buffer) { | 570 _writeResponse(request, (StringBuffer buffer) { |
| 574 _writePage(buffer, 'Analysis Server - Overlays', [], | 571 _writePage(buffer, 'Overlay information', [], (StringBuffer buffer) { |
| 575 (StringBuffer buffer) { | |
| 576 buffer.write('<table border="1">'); | 572 buffer.write('<table border="1">'); |
| 577 _overlayContents.clear(); | 573 _overlayContents.clear(); |
| 578 ContentCache overlayState = analysisServer.overlayState; | 574 ContentCache overlayState = analysisServer.overlayState; |
| 579 overlayState.accept((String fullName, int stamp, String contents) { | 575 overlayState.accept((String fullName, int stamp, String contents) { |
| 580 buffer.write('<tr>'); | 576 buffer.write('<tr>'); |
| 581 String link = | 577 String link = |
| 582 makeLink(OVERLAY_PATH, {PATH_PARAM: fullName}, fullName); | 578 makeLink(OVERLAY_PATH, {PATH_PARAM: fullName}, fullName); |
| 583 DateTime time = new DateTime.fromMillisecondsSinceEpoch(stamp); | 579 DateTime time = new DateTime.fromMillisecondsSinceEpoch(stamp); |
| 584 _writeRow(buffer, [link, time]); | 580 _writeRow(buffer, [link, time]); |
| 585 _overlayContents[fullName] = contents; | 581 _overlayContents[fullName] = contents; |
| 586 }); | 582 }); |
| 587 int count = _overlayContents.length; | 583 int count = _overlayContents.length; |
| 588 buffer.write('<tr><td colspan="2">Total: $count entries.</td></tr>'); | 584 buffer.write('<tr><td colspan="2">Total: $count entries</td></tr>'); |
| 589 buffer.write('</table>'); | 585 buffer.write('</table>'); |
| 590 }); | 586 }); |
| 591 }); | 587 }); |
| 592 } | 588 } |
| 593 | 589 |
| 594 /** | 590 /** |
| 595 * Return a response indicating the status of the analysis server. | 591 * Return a response indicating the status of the analysis server. |
| 596 */ | 592 */ |
| 597 void _returnServerStatus(HttpRequest request) { | 593 void _returnServerStatus(HttpRequest request) { |
| 598 _writeResponse(request, (StringBuffer buffer) { | 594 _writeResponse(request, (StringBuffer buffer) { |
| 599 _writePage(buffer, 'Analysis Server - Status', [], (StringBuffer buffer) { | 595 _writePage(buffer, 'Status', [], (StringBuffer buffer) { |
| 600 if (_writeServerStatus(buffer)) { | 596 if (_writeServerStatus(buffer)) { |
| 601 _writeAnalysisStatus(buffer); | 597 _writeAnalysisStatus(buffer); |
| 602 _writeEditStatus(buffer); | 598 _writeEditStatus(buffer); |
| 603 _writeExecutionStatus(buffer); | 599 _writeExecutionStatus(buffer); |
| 604 _writePluginStatus(buffer); | 600 _writePluginStatus(buffer); |
| 605 _writeRecentOutput(buffer); | 601 _writeRecentOutput(buffer); |
| 606 } | 602 } |
| 607 }); | 603 }); |
| 608 }); | 604 }); |
| 609 } | 605 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 629 ${makeLink(STATUS_PATH, {}, 'the main status page')}. | 625 ${makeLink(STATUS_PATH, {}, 'the main status page')}. |
| 630 </p>'''); | 626 </p>'''); |
| 631 }); | 627 }); |
| 632 }); | 628 }); |
| 633 } | 629 } |
| 634 | 630 |
| 635 /** | 631 /** |
| 636 * Return a two digit decimal representation of the given non-negative integer | 632 * Return a two digit decimal representation of the given non-negative integer |
| 637 * [value]. | 633 * [value]. |
| 638 */ | 634 */ |
| 639 String _twoDigit(int value) { | 635 String _twoDigit(int value) => value.toString().padLeft(2, '0'); |
| 640 if (value < 10) { | |
| 641 return '0$value'; | |
| 642 } | |
| 643 return value.toString(); | |
| 644 } | |
| 645 | 636 |
| 646 /** | 637 /** |
| 647 * Write the status of the analysis domain (on the main status page) to the | 638 * Write the status of the analysis domain (on the main status page) to the |
| 648 * given [buffer] object. | 639 * given [buffer] object. |
| 649 */ | 640 */ |
| 650 void _writeAnalysisStatus(StringBuffer buffer) { | 641 void _writeAnalysisStatus(StringBuffer buffer) { |
| 651 AnalysisServer analysisServer = _server.analysisServer; | 642 AnalysisServer analysisServer = _server.analysisServer; |
| 652 Map<Folder, AnalysisDriver> driverMap = analysisServer.driverMap; | 643 Map<Folder, AnalysisDriver> driverMap = analysisServer.driverMap; |
| 653 List<Folder> folders = driverMap.keys.toList(); | 644 List<Folder> folders = driverMap.keys.toList(); |
| 654 folders.sort((Folder first, Folder second) => | 645 folders.sort((Folder first, Folder second) => |
| 655 first.shortName.compareTo(second.shortName)); | 646 first.shortName.compareTo(second.shortName)); |
| 656 | 647 |
| 657 buffer.write('<h3>Analysis Domain</h3>'); | 648 buffer.write('<h3>Analysis Domain</h3>'); |
| 658 _writeTwoColumns(buffer, (StringBuffer buffer) { | 649 _writeTwoColumns(buffer, (StringBuffer buffer) { |
| 659 buffer.write('<p>Using package resolver provider: '); | 650 buffer.write('<p>Using package resolver provider: '); |
| 660 buffer.write(_server.packageResolverProvider != null); | 651 buffer.write(_server.packageResolverProvider != null); |
| 661 buffer.write('</p>'); | 652 buffer.write('</p>'); |
| 662 buffer.write('<p>'); | 653 buffer.write(makeLink(OVERLAYS_PATH, {}, 'Overlay information')); |
| 663 buffer.write(makeLink(OVERLAYS_PATH, {}, 'All overlay information')); | |
| 664 buffer.write('</p>'); | |
| 665 | 654 |
| 666 buffer.write('<p><b>Analysis Contexts</b></p>'); | 655 buffer.write('<p><b>Analysis Contexts</b></p>'); |
| 667 buffer.write('<p>'); | |
| 668 bool first = true; | 656 bool first = true; |
| 669 folders.forEach((Folder folder) { | 657 folders.forEach((Folder folder) { |
| 670 if (first) { | 658 if (first) { |
| 671 first = false; | 659 first = false; |
| 672 } else { | 660 } else { |
| 673 buffer.write('<br>'); | 661 buffer.write('<br>'); |
| 674 } | 662 } |
| 675 String key = folder.shortName; | 663 String key = folder.shortName; |
| 676 buffer.write(makeLink(CONTEXT_PATH, {CONTEXT_QUERY_PARAM: folder.path}, | 664 buffer.write(makeLink(CONTEXT_PATH, {CONTEXT_QUERY_PARAM: folder.path}, |
| 677 key, _hasException(driverMap[folder]))); | 665 key, _hasException(driverMap[folder]))); |
| 678 if (!folder.getChild('.packages').exists) { | 666 if (!folder.getChild('.packages').exists) { |
| 679 buffer.write(' <small>[no .packages file]</small>'); | 667 buffer.write(' [no .packages file]'); |
| 680 } | 668 } |
| 681 }); | 669 }); |
| 682 buffer.write('</p>'); | |
| 683 | 670 |
| 684 int freq = AnalysisServer.performOperationDelayFrequency; | 671 int freq = AnalysisServer.performOperationDelayFrequency; |
| 685 String delay = freq > 0 ? '1 ms every $freq ms' : 'off'; | 672 String delay = freq > 0 ? '1 ms every $freq ms' : 'off'; |
| 686 | 673 |
| 687 buffer.write('<p><b>Performance Data</b></p>'); | 674 buffer.write('<p><b>Performance Data</b></p>'); |
| 688 buffer.write('<p>Perform operation delay: $delay</p>'); | 675 buffer.write( |
| 689 buffer.write('<p>'); | 676 makeLink(ANALYSIS_PERFORMANCE_PATH, {}, 'Analysis performance')); |
| 690 buffer.write(makeLink(ANALYSIS_PERFORMANCE_PATH, {}, 'Task data')); | 677 buffer.write('<br>'); |
| 691 buffer.write('</p>'); | 678 buffer.write('Perform operation delay: $delay'); |
| 679 buffer.write('<br>'); |
| 692 }, (StringBuffer buffer) { | 680 }, (StringBuffer buffer) { |
| 693 _writeSubscriptionMap( | 681 _writeSubscriptionMap( |
| 694 buffer, AnalysisService.VALUES, analysisServer.analysisServices); | 682 buffer, AnalysisService.VALUES, analysisServer.analysisServices); |
| 695 }); | 683 }); |
| 696 } | 684 } |
| 697 | 685 |
| 698 /** | 686 /** |
| 699 * Write multiple columns of information to the given [buffer], where the list | 687 * Write multiple columns of information to the given [buffer], where the list |
| 700 * of [columns] functions are used to generate the content of those columns. | 688 * of [columns] functions are used to generate the content of those columns. |
| 701 */ | 689 */ |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 then there will be only one number in this column.'''); | 802 then there will be only one number in this column.'''); |
| 815 } | 803 } |
| 816 | 804 |
| 817 /** | 805 /** |
| 818 * Write the status of the edit domain (on the main status page) to the given | 806 * Write the status of the edit domain (on the main status page) to the given |
| 819 * [buffer]. | 807 * [buffer]. |
| 820 */ | 808 */ |
| 821 void _writeEditStatus(StringBuffer buffer) { | 809 void _writeEditStatus(StringBuffer buffer) { |
| 822 buffer.write('<h3>Edit Domain</h3>'); | 810 buffer.write('<h3>Edit Domain</h3>'); |
| 823 _writeTwoColumns(buffer, (StringBuffer buffer) { | 811 _writeTwoColumns(buffer, (StringBuffer buffer) { |
| 824 buffer.write('<p><b>Performance Data</b></p>'); | 812 buffer.write(makeLink(COMPLETION_PATH, {}, 'Completion stats')); |
| 825 buffer.write('<p>'); | |
| 826 buffer.write(makeLink(COMPLETION_PATH, {}, 'Completion data')); | |
| 827 buffer.write('</p>'); | |
| 828 }, (StringBuffer buffer) {}); | 813 }, (StringBuffer buffer) {}); |
| 829 } | 814 } |
| 830 | 815 |
| 831 /** | 816 /** |
| 832 * Write a representation of the given [caughtException] to the given | 817 * Write a representation of the given [caughtException] to the given |
| 833 * [buffer]. If [isCause] is `true`, then the exception was a cause for | 818 * [buffer]. If [isCause] is `true`, then the exception was a cause for |
| 834 * another exception. | 819 * another exception. |
| 835 */ | 820 */ |
| 836 void _writeException(StringBuffer buffer, CaughtException caughtException, | 821 void _writeException(StringBuffer buffer, CaughtException caughtException, |
| 837 {bool isCause: false}) { | 822 {bool isCause: false}) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 (RequestHandler handler) => handler is ExecutionDomainHandler, | 857 (RequestHandler handler) => handler is ExecutionDomainHandler, |
| 873 orElse: () => null); | 858 orElse: () => null); |
| 874 Set<ExecutionService> services = new Set<ExecutionService>(); | 859 Set<ExecutionService> services = new Set<ExecutionService>(); |
| 875 if (handler.onFileAnalyzed != null) { | 860 if (handler.onFileAnalyzed != null) { |
| 876 services.add(ExecutionService.LAUNCH_DATA); | 861 services.add(ExecutionService.LAUNCH_DATA); |
| 877 } | 862 } |
| 878 | 863 |
| 879 if (handler != null) { | 864 if (handler != null) { |
| 880 buffer.write('<h3>Execution Domain</h3>'); | 865 buffer.write('<h3>Execution Domain</h3>'); |
| 881 _writeTwoColumns(buffer, (StringBuffer buffer) { | 866 _writeTwoColumns(buffer, (StringBuffer buffer) { |
| 867 buffer.write('<br>'); |
| 868 }, (StringBuffer buffer) { |
| 882 _writeSubscriptionList(buffer, ExecutionService.VALUES, services); | 869 _writeSubscriptionList(buffer, ExecutionService.VALUES, services); |
| 883 }, (StringBuffer buffer) {}); | 870 }); |
| 884 } | 871 } |
| 885 } | 872 } |
| 886 | 873 |
| 887 /** | 874 /** |
| 888 * Write to the given [buffer] a representation of the given [map] of strings | 875 * Write to the given [buffer] a representation of the given [map] of strings |
| 889 * to strings. | 876 * to strings. |
| 890 */ | 877 */ |
| 891 void _writeMapOfStringToString(StringBuffer buffer, Map<String, String> map) { | 878 void _writeMapOfStringToString(StringBuffer buffer, Map<String, String> map) { |
| 892 List<String> keys = map.keys.toList(); | 879 List<String> keys = map.keys.toList(); |
| 893 keys.sort(); | 880 keys.sort(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 String date = "${now.month}/${now.day}/${now.year}"; | 919 String date = "${now.month}/${now.day}/${now.year}"; |
| 933 String time = | 920 String time = |
| 934 "${now.hour}:${_twoDigit(now.minute)}:${_twoDigit(now.second)}.${now.mil
lisecond}"; | 921 "${now.hour}:${_twoDigit(now.minute)}:${_twoDigit(now.second)}.${now.mil
lisecond}"; |
| 935 | 922 |
| 936 buffer.write('<!DOCTYPE html>'); | 923 buffer.write('<!DOCTYPE html>'); |
| 937 buffer.write('<html>'); | 924 buffer.write('<html>'); |
| 938 buffer.write('<head>'); | 925 buffer.write('<head>'); |
| 939 buffer.write('<meta charset="utf-8">'); | 926 buffer.write('<meta charset="utf-8">'); |
| 940 buffer.write( | 927 buffer.write( |
| 941 '<meta name="viewport" content="width=device-width, initial-scale=1.0">'
); | 928 '<meta name="viewport" content="width=device-width, initial-scale=1.0">'
); |
| 942 buffer.write('<title>$title</title>'); | 929 buffer.write('<title>Analysis Server</title>'); |
| 943 buffer.write('<style>'); | 930 buffer.write('<style>'); |
| 944 buffer.write('a {color: #0000DD; text-decoration: none;}'); | 931 buffer.write('a {color: #0000DD; text-decoration: none;}'); |
| 945 buffer.write('a:link.error {background-color: #FFEEEE;}'); | 932 buffer.write('a:link.error {background-color: #FFEEEE;}'); |
| 946 buffer.write('a:visited.error {background-color: #FFEEEE;}'); | 933 buffer.write('a:visited.error {background-color: #FFEEEE;}'); |
| 947 buffer.write('a:hover.error {background-color: #FFEEEE;}'); | 934 buffer.write('a:hover.error {background-color: #FFEEEE;}'); |
| 948 buffer.write('a:active.error {background-color: #FFEEEE;}'); | 935 buffer.write('a:active.error {background-color: #FFEEEE;}'); |
| 949 buffer.write( | 936 buffer.write( |
| 950 'h3 {background-color: #DDDDDD; margin-top: 0em; margin-bottom: 0em;}'); | 937 'div.subtitle {float: right; font-weight: normal; font-size: 1rem;}'); |
| 951 buffer.write('p {margin-top: 0.5em; margin-bottom: 0.5em;}'); | 938 buffer.write('h2 {margin-top: 0;}'); |
| 939 buffer.write('h3 {border-bottom: 1px #DDD solid; margin-bottom: 0em;}'); |
| 940 buffer.write('p {margin-top: 0.5em; margin-bottom: 0;}'); |
| 952 buffer.write( | 941 buffer.write( |
| 953 'p.commentary {margin-top: 1em; margin-bottom: 1em; margin-left: 2em; fo
nt-style: italic;}'); | 942 'p.commentary {margin-top: 1em; margin-bottom: 1em; margin-left: 2em; fo
nt-style: italic;}'); |
| 954 // response.write('span.error {text-decoration-line: underline; text-decorati
on-color: red; text-decoration-style: wavy;}'); | 943 // response.write('span.error {text-decoration-line: underline; text-decorati
on-color: red; text-decoration-style: wavy;}'); |
| 955 buffer.write( | 944 buffer.write( |
| 956 'table.column {border: 0px solid black; width: 100%; table-layout: fixed
;}'); | 945 'table.column {border: 0px solid black; width: 100%; table-layout: fixed
;}'); |
| 957 buffer.write('td.column {vertical-align: top; width: 50%;}'); | 946 buffer.write('td.column {vertical-align: top; width: 50%;}'); |
| 958 buffer.write('td.right {text-align: right;}'); | 947 buffer.write('td.right {text-align: right;}'); |
| 959 buffer.write('th {text-align: left; vertical-align:top;}'); | 948 buffer.write('th {text-align: left; vertical-align:top;}'); |
| 960 buffer.write('tr {vertical-align:top;}'); | 949 buffer.write('tr {vertical-align:top;}'); |
| 961 buffer.write('</style>'); | 950 buffer.write('</style>'); |
| 962 buffer.write('</head>'); | 951 buffer.write('</head>'); |
| 963 | 952 |
| 964 buffer.write('<body>'); | 953 buffer.write('<body>'); |
| 965 buffer.write( | 954 buffer.write('<h2>$title <div class="subtitle">$date, $time</div></h2>'); |
| 966 '<h2>$title <small><small>(as of $time on $date)</small></small></h2>'); | |
| 967 if (subtitles != null && subtitles.isNotEmpty) { | 955 if (subtitles != null && subtitles.isNotEmpty) { |
| 968 buffer.write('<blockquote>'); | |
| 969 bool first = true; | 956 bool first = true; |
| 970 for (String subtitle in subtitles) { | 957 for (String subtitle in subtitles) { |
| 971 if (first) { | 958 if (first) { |
| 972 first = false; | 959 first = false; |
| 973 } else { | 960 } else { |
| 974 buffer.write('<br>'); | 961 buffer.write('<br>'); |
| 975 } | 962 } |
| 976 buffer.write('<b>'); | 963 buffer.write('<b>'); |
| 977 buffer.write(subtitle); | 964 buffer.write(subtitle); |
| 978 buffer.write('</b>'); | 965 buffer.write('</b>'); |
| 979 } | 966 } |
| 980 buffer.write('</blockquote>'); | |
| 981 } | 967 } |
| 982 try { | 968 try { |
| 983 body(buffer); | 969 body(buffer); |
| 984 } catch (exception, stackTrace) { | 970 } catch (exception, stackTrace) { |
| 985 buffer.write('<h3>Exception while creating page</h3>'); | 971 buffer.write('<h3>Exception while creating page</h3>'); |
| 986 _writeException(buffer, new CaughtException(exception, stackTrace)); | 972 _writeException(buffer, new CaughtException(exception, stackTrace)); |
| 987 } | 973 } |
| 988 buffer.write('</body>'); | 974 buffer.write('</body>'); |
| 989 buffer.write('</html>'); | 975 buffer.write('</html>'); |
| 990 } | 976 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 String className = classes[min(i, maxClassIndex)]; | 1048 String className = classes[min(i, maxClassIndex)]; |
| 1063 if (className != null) { | 1049 if (className != null) { |
| 1064 classAttribute = ' class="$className"'; | 1050 classAttribute = ' class="$className"'; |
| 1065 } | 1051 } |
| 1066 } | 1052 } |
| 1067 if (header) { | 1053 if (header) { |
| 1068 buffer.write('<th$classAttribute>'); | 1054 buffer.write('<th$classAttribute>'); |
| 1069 } else { | 1055 } else { |
| 1070 buffer.write('<td$classAttribute>'); | 1056 buffer.write('<td$classAttribute>'); |
| 1071 } | 1057 } |
| 1072 buffer.write(columns[i]); | 1058 if (columns[i] is int) { |
| 1059 buffer.write(_writeWithSeparators(columns[i])); |
| 1060 } else { |
| 1061 buffer.write(columns[i]); |
| 1062 } |
| 1073 if (header) { | 1063 if (header) { |
| 1074 buffer.write('</th>'); | 1064 buffer.write('</th>'); |
| 1075 } else { | 1065 } else { |
| 1076 buffer.write('</td>'); | 1066 buffer.write('</td>'); |
| 1077 } | 1067 } |
| 1078 } | 1068 } |
| 1079 buffer.write('</tr>'); | 1069 buffer.write('</tr>'); |
| 1080 } | 1070 } |
| 1081 | 1071 |
| 1082 /** | 1072 /** |
| 1083 * Write the status of the service domain (on the main status page) to the | 1073 * Write the status of the service domain (on the main status page) to the |
| 1084 * given [response] object. | 1074 * given [response] object. |
| 1085 */ | 1075 */ |
| 1086 bool _writeServerStatus(StringBuffer buffer) { | 1076 bool _writeServerStatus(StringBuffer buffer) { |
| 1087 AnalysisServer analysisServer = _server.analysisServer; | 1077 AnalysisServer analysisServer = _server.analysisServer; |
| 1088 Set<ServerService> services = analysisServer.serverServices; | 1078 Set<ServerService> services = analysisServer.serverServices; |
| 1089 | 1079 |
| 1090 buffer.write('<h3>Server Domain</h3>'); | 1080 buffer.write('<h3>Server Domain</h3>'); |
| 1091 _writeTwoColumns(buffer, (StringBuffer buffer) { | 1081 _writeTwoColumns(buffer, (StringBuffer buffer) { |
| 1082 buffer.write('<p><b>State</b></p>'); |
| 1092 if (analysisServer == null) { | 1083 if (analysisServer == null) { |
| 1093 buffer.write('Status: <span style="color:red">Not running</span>'); | 1084 buffer.write('Status: <span style="color:red">Not running</span>'); |
| 1094 return; | 1085 return; |
| 1095 } | 1086 } |
| 1096 buffer.write('<p>'); | |
| 1097 buffer.write('Status: Running<br>'); | 1087 buffer.write('Status: Running<br>'); |
| 1098 buffer.write('New analysis driver: '); | 1088 buffer.write('New analysis driver: '); |
| 1099 buffer.write(analysisServer.options.enableNewAnalysisDriver); | 1089 buffer.write(analysisServer.options.enableNewAnalysisDriver); |
| 1100 buffer.write('<br>'); | 1090 buffer.write('<br>'); |
| 1101 buffer.write('Instrumentation: '); | 1091 buffer.write('Instrumentation: '); |
| 1102 if (AnalysisEngine.instance.instrumentationService.isActive) { | 1092 if (AnalysisEngine.instance.instrumentationService.isActive) { |
| 1103 buffer.write('<span style="color:red">Active</span>'); | 1093 buffer.write('<span style="color:red">Active</span>'); |
| 1104 } else { | 1094 } else { |
| 1105 buffer.write('Inactive'); | 1095 buffer.write('Inactive'); |
| 1106 } | 1096 } |
| 1107 buffer.write('<br>'); | 1097 buffer.write('<br>'); |
| 1108 buffer.write('Server version: '); | |
| 1109 buffer.write(AnalysisServer.VERSION); | |
| 1110 buffer.write('<br>'); | |
| 1111 buffer.write('SDK: '); | |
| 1112 buffer.write(Platform.version); | |
| 1113 buffer.write('<br>'); | |
| 1114 buffer.write('Process ID: '); | 1098 buffer.write('Process ID: '); |
| 1115 buffer.write(pid); | 1099 buffer.write(pid); |
| 1116 buffer.write('</p>'); | |
| 1117 | 1100 |
| 1118 buffer.write('<p><b>Performance Data</b></p>'); | 1101 buffer.write('<p><b>Performance Data</b></p>'); |
| 1119 buffer.write('<p>'); | |
| 1120 buffer.write(makeLink( | 1102 buffer.write(makeLink( |
| 1121 COMMUNICATION_PERFORMANCE_PATH, {}, 'Communication performance')); | 1103 COMMUNICATION_PERFORMANCE_PATH, {}, 'Communication performance')); |
| 1122 buffer.write('</p>'); | |
| 1123 }, (StringBuffer buffer) { | 1104 }, (StringBuffer buffer) { |
| 1124 _writeSubscriptionList(buffer, ServerService.VALUES, services); | 1105 _writeSubscriptionList(buffer, ServerService.VALUES, services); |
| 1106 buffer.write('<p><b>Versions</b></p>'); |
| 1107 buffer.write('Dart SDK: ${Platform.version}<br>'); |
| 1108 buffer.write('Analysis server version: ${AnalysisServer.VERSION}<br>'); |
| 1125 }); | 1109 }); |
| 1126 return analysisServer != null; | 1110 return analysisServer != null; |
| 1127 } | 1111 } |
| 1128 | 1112 |
| 1129 /** | 1113 /** |
| 1130 * Write a representation of the given [stackTrace] to the given [buffer]. | 1114 * Write a representation of the given [stackTrace] to the given [buffer]. |
| 1131 */ | 1115 */ |
| 1132 void _writeStackTrace(StringBuffer buffer, StackTrace stackTrace) { | 1116 void _writeStackTrace(StringBuffer buffer, StackTrace stackTrace) { |
| 1133 if (stackTrace != null) { | 1117 if (stackTrace != null) { |
| 1134 String trace = stackTrace.toString().replaceAll('#', '<br>#'); | 1118 String trace = stackTrace.toString().replaceAll('#', '<br>#'); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1159 | 1143 |
| 1160 /** | 1144 /** |
| 1161 * Given a [service] that could be subscribed to and a set of paths that are | 1145 * Given a [service] that could be subscribed to and a set of paths that are |
| 1162 * subscribed to the services ([subscribedPaths]), write a representation of | 1146 * subscribed to the services ([subscribedPaths]), write a representation of |
| 1163 * the service to the given [buffer]. | 1147 * the service to the given [buffer]. |
| 1164 */ | 1148 */ |
| 1165 void _writeSubscriptionInMap( | 1149 void _writeSubscriptionInMap( |
| 1166 StringBuffer buffer, Enum service, Set<String> subscribedPaths) { | 1150 StringBuffer buffer, Enum service, Set<String> subscribedPaths) { |
| 1167 buffer.write('<p>'); | 1151 buffer.write('<p>'); |
| 1168 buffer.write(service.name); | 1152 buffer.write(service.name); |
| 1169 buffer.write('</p>'); | 1153 buffer.write('<br>'); |
| 1170 if (subscribedPaths == null || subscribedPaths.isEmpty) { | 1154 if (subscribedPaths != null && subscribedPaths.isNotEmpty) { |
| 1171 buffer.write('none'); | |
| 1172 } else { | |
| 1173 List<String> paths = subscribedPaths.toList(); | 1155 List<String> paths = subscribedPaths.toList(); |
| 1174 paths.sort(); | 1156 paths.sort(); |
| 1175 for (String path in paths) { | 1157 for (String path in paths) { |
| 1176 buffer.write('<p>'); | 1158 buffer.write('$path<br>'); |
| 1177 buffer.write(path); | |
| 1178 buffer.write('</p>'); | |
| 1179 } | 1159 } |
| 1180 } | 1160 } |
| 1161 buffer.write('</p>'); |
| 1181 } | 1162 } |
| 1182 | 1163 |
| 1183 /** | 1164 /** |
| 1184 * Given a list containing all of the services that can be subscribed to in a | 1165 * Given a list containing all of the services that can be subscribed to in a |
| 1185 * single domain ([allServices]) and a set of the services that are actually | 1166 * single domain ([allServices]) and a set of the services that are actually |
| 1186 * subscribed to ([subscribedServices]), write a representation of the | 1167 * subscribed to ([subscribedServices]), write a representation of the |
| 1187 * subscriptions to the given [buffer]. | 1168 * subscriptions to the given [buffer]. |
| 1188 */ | 1169 */ |
| 1189 void _writeSubscriptionList(StringBuffer buffer, List<Enum> allServices, | 1170 void _writeSubscriptionList(StringBuffer buffer, List<Enum> allServices, |
| 1190 Set<Enum> subscribedServices) { | 1171 Set<Enum> subscribedServices) { |
| 1191 buffer.write('<p><b>Subscriptions</b></p>'); | 1172 buffer.write('<p><b>Subscriptions</b></p>'); |
| 1192 buffer.write('<p>'); | |
| 1193 for (Enum service in allServices) { | 1173 for (Enum service in allServices) { |
| 1194 _writeSubscriptionInList(buffer, service, subscribedServices); | 1174 _writeSubscriptionInList(buffer, service, subscribedServices); |
| 1175 buffer.write('<br>'); |
| 1195 } | 1176 } |
| 1196 buffer.write('</p>'); | |
| 1197 } | 1177 } |
| 1198 | 1178 |
| 1199 /** | 1179 /** |
| 1200 * Given a list containing all of the services that can be subscribed to in a | 1180 * Given a list containing all of the services that can be subscribed to in a |
| 1201 * single domain ([allServices]) and a set of the services that are actually | 1181 * single domain ([allServices]) and a set of the services that are actually |
| 1202 * subscribed to ([subscribedServices]), write a representation of the | 1182 * subscribed to ([subscribedServices]), write a representation of the |
| 1203 * subscriptions to the given [buffer]. | 1183 * subscriptions to the given [buffer]. |
| 1204 */ | 1184 */ |
| 1205 void _writeSubscriptionMap(StringBuffer buffer, List<Enum> allServices, | 1185 void _writeSubscriptionMap(StringBuffer buffer, List<Enum> allServices, |
| 1206 Map<Enum, Set<String>> subscribedServices) { | 1186 Map<Enum, Set<String>> subscribedServices) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1231 * 'error'. | 1211 * 'error'. |
| 1232 */ | 1212 */ |
| 1233 static String makeLink( | 1213 static String makeLink( |
| 1234 String path, Map<String, String> params, String innerHtml, | 1214 String path, Map<String, String> params, String innerHtml, |
| 1235 [bool hasError = false]) { | 1215 [bool hasError = false]) { |
| 1236 Uri uri = params.isEmpty | 1216 Uri uri = params.isEmpty |
| 1237 ? new Uri(path: path) | 1217 ? new Uri(path: path) |
| 1238 : new Uri(path: path, queryParameters: params); | 1218 : new Uri(path: path, queryParameters: params); |
| 1239 String href = HTML_ESCAPE.convert(uri.toString()); | 1219 String href = HTML_ESCAPE.convert(uri.toString()); |
| 1240 String classAttribute = hasError ? ' class="error"' : ''; | 1220 String classAttribute = hasError ? ' class="error"' : ''; |
| 1241 return '<a href="$href"$classAttribute>$innerHtml</a>'; | 1221 return '<a href="$href" $classAttribute>$innerHtml</a>'; |
| 1242 } | 1222 } |
| 1243 } | 1223 } |
| 1224 |
| 1225 String _writeWithSeparators(int value) { |
| 1226 // TODO(devoncarew): Replace with the implementation from package:intl. |
| 1227 String str = value.toString(); |
| 1228 int pos = 3; |
| 1229 while (str.length > pos) { |
| 1230 int len = str.length; |
| 1231 str = '${str.substring(0, len - pos)},${str.substring(len - pos)}'; |
| 1232 pos += 4; |
| 1233 } |
| 1234 return str; |
| 1235 } |
| OLD | NEW |