| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 server.performance.analysis.timing; | 5 library server.performance.analysis.timing; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/protocol.dart'; | 10 import 'package:analysis_server/src/protocol.dart'; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 main(List<String> arguments) { | 24 main(List<String> arguments) { |
| 25 initializeTestEnvironment(); | 25 initializeTestEnvironment(); |
| 26 ArgParser parser = _createArgParser(); | 26 ArgParser parser = _createArgParser(); |
| 27 var args = parser.parse(arguments); | 27 var args = parser.parse(arguments); |
| 28 if (args[SOURCE_OPTION] == null) { | 28 if (args[SOURCE_OPTION] == null) { |
| 29 print('path to source directory must be specified'); | 29 print('path to source directory must be specified'); |
| 30 exit(1); | 30 exit(1); |
| 31 } | 31 } |
| 32 source = args[SOURCE_OPTION]; | 32 source = args[SOURCE_OPTION]; |
| 33 priorityFile = args[PRIORITY_FILE_OPTION]; | 33 priorityFile = args[PRIORITY_FILE_OPTION]; |
| 34 testName = args[TEST_NAME_OPTION] ?? DEFAULT_TEST; | 34 var metricNameParam = args[METRIC_NAME_OPTION] ?? DEFAULT_METRIC; |
| 35 | 35 |
| 36 switch (testName) { | 36 metricNames.addAll(metricNameParam); |
| 37 case 'analysis': | 37 |
| 38 defineReflectiveTests(AnalysisTimingIntegrationTest); | 38 defineReflectiveTests(TimingTest); |
| 39 break; | |
| 40 case 'highlighting': | |
| 41 defineReflectiveTests(HighlightingTimingIntegrationTest); | |
| 42 break; | |
| 43 case 'navigation': | |
| 44 defineReflectiveTests(NavigationTimingIntegrationTest); | |
| 45 break; | |
| 46 case 'outline': | |
| 47 defineReflectiveTests(OutlineTimingIntegrationTest); | |
| 48 break; | |
| 49 default: | |
| 50 print('unrecognized test name $testName'); | |
| 51 exit(1); | |
| 52 } | |
| 53 } | 39 } |
| 54 | 40 |
| 55 const DEFAULT_TEST = 'analysis'; | 41 const DEFAULT_METRIC = 'analysis'; |
| 42 const METRIC_NAME_OPTION = 'metric'; |
| 56 const PRIORITY_FILE_OPTION = 'priority'; | 43 const PRIORITY_FILE_OPTION = 'priority'; |
| 57 const SOURCE_OPTION = 'source'; | 44 const SOURCE_OPTION = 'source'; |
| 58 const TEST_NAME_OPTION = 'test'; | |
| 59 | 45 |
| 46 final metricNames = <String>[]; |
| 60 String priorityFile; | 47 String priorityFile; |
| 61 String source; | 48 String source; |
| 62 String testName; | |
| 63 | 49 |
| 64 ArgParser _createArgParser() => new ArgParser() | 50 ArgParser _createArgParser() => new ArgParser() |
| 65 ..addOption(TEST_NAME_OPTION, help: 'test name (defaults to `analysis`)') | 51 ..addOption(METRIC_NAME_OPTION, |
| 52 help: 'metric name (defaults to `analysis`)', allowMultiple: true) |
| 66 ..addOption(SOURCE_OPTION, help: 'full path to source directory for analysis') | 53 ..addOption(SOURCE_OPTION, help: 'full path to source directory for analysis') |
| 67 ..addOption(PRIORITY_FILE_OPTION, | 54 ..addOption(PRIORITY_FILE_OPTION, |
| 68 help: '(optional) full path to a priority file'); | 55 help: '(optional) full path to a priority file'); |
| 69 | 56 |
| 70 class AbstractTimingTest extends AbstractAnalysisServerPerformanceTest { | 57 class AbstractTimingTest extends AbstractAnalysisServerPerformanceTest { |
| 71 @override | 58 @override |
| 72 Future setUp() => super.setUp().then((_) { | 59 Future setUp() => super.setUp().then((_) { |
| 73 sourceDirectory = new Directory(source); | 60 sourceDirectory = new Directory(source); |
| 74 subscribeToStatusNotifications(); | 61 subscribeToStatusNotifications(); |
| 75 }); | 62 }); |
| 76 } | 63 } |
| 77 | 64 |
| 78 @reflectiveTest | 65 class Metric { |
| 79 class AnalysisTimingIntegrationTest extends AbstractTimingTest { | 66 List<Duration> timings = <Duration>[]; |
| 80 test_detect_analysis_done() { | 67 Stream eventStream; |
| 81 stopwatch.start(); | 68 AnalysisService service; |
| 82 setAnalysisRoot(); | 69 String name; |
| 83 if (priorityFile != null) { | 70 Metric(this.name, this.service, this.eventStream); |
| 84 sendAnalysisSetPriorityFiles([priorityFile]); | 71 String toString() => '$name: $service, ${eventStream.runtimeType}, $timings'; |
| 85 } | |
| 86 return analysisFinished.then((_) { | |
| 87 print('analysis completed in ${stopwatch.elapsed}'); | |
| 88 stopwatch.reset(); | |
| 89 }); | |
| 90 } | |
| 91 } | 72 } |
| 92 | 73 |
| 93 @reflectiveTest | 74 @reflectiveTest |
| 94 class HighlightingTimingIntegrationTest extends PriorityFileTimer { | 75 class TimingTest extends AbstractTimingTest { |
| 95 @override | 76 List<Metric> _metrics; |
| 96 String get description => 'highlighting'; | |
| 97 | 77 |
| 98 @override | 78 List<Metric> get metrics => |
| 99 Stream get eventStream => onAnalysisHighlights; | 79 _metrics ??= metricNames.map((name) => getMetric(name)).toList(); |
| 100 | 80 |
| 101 @override | 81 Metric getMetric(String name) { |
| 102 AnalysisService get service => AnalysisService.HIGHLIGHTS; | 82 switch (name) { |
| 103 } | 83 case 'folding': |
| 104 | 84 return new Metric(name, AnalysisService.FOLDING, onAnalysisFolding); |
| 105 @reflectiveTest | 85 case 'highlighting': |
| 106 class NavigationTimingIntegrationTest extends PriorityFileTimer { | 86 return new Metric( |
| 107 @override | 87 name, AnalysisService.HIGHLIGHTS, onAnalysisHighlights); |
| 108 String get description => 'navigation'; | 88 case 'implemented': |
| 109 | 89 return new Metric( |
| 110 @override | 90 name, AnalysisService.IMPLEMENTED, onAnalysisImplemented); |
| 111 Stream get eventStream => onAnalysisNavigation; | 91 case 'navigation': |
| 112 | 92 return new Metric( |
| 113 @override | 93 name, AnalysisService.NAVIGATION, onAnalysisNavigation); |
| 114 AnalysisService get service => AnalysisService.NAVIGATION; | 94 case 'outline': |
| 115 } | 95 return new Metric(name, AnalysisService.OUTLINE, onAnalysisOutline); |
| 116 | 96 case 'occurences': |
| 117 @reflectiveTest | 97 return new Metric( |
| 118 class OutlineTimingIntegrationTest extends PriorityFileTimer { | 98 name, AnalysisService.OCCURRENCES, onAnalysisOccurrences); |
| 119 @override | 99 case 'overrides': |
| 120 String get description => 'outline'; | 100 return new Metric(name, AnalysisService.OVERRIDES, onAnalysisOverrides); |
| 121 | 101 } |
| 122 @override | 102 print('no metric found for $name'); |
| 123 Stream get eventStream => onAnalysisOutline; | 103 exit(1); |
| 124 | 104 return null; // Won't get here. |
| 125 @override | 105 } |
| 126 AnalysisService get service => AnalysisService.OUTLINE; | |
| 127 } | |
| 128 | |
| 129 abstract class PriorityFileTimer extends AbstractTimingTest { | |
| 130 String get description; | |
| 131 Stream get eventStream; | |
| 132 AnalysisService get service; | |
| 133 | 106 |
| 134 Future test_timing() { | 107 Future test_timing() { |
| 108 //debugStdio(); |
| 109 |
| 110 expect(metrics, isNotEmpty); |
| 135 expect(priorityFile, isNotNull, | 111 expect(priorityFile, isNotNull, |
| 136 reason: 'A priority file must be specified for $description testing.'); | 112 reason: 'A priority file must be specified for ' |
| 113 '${metrics.first.name} testing.'); |
| 114 |
| 137 stopwatch.start(); | 115 stopwatch.start(); |
| 138 | 116 |
| 139 Duration elapsed; | 117 metrics.forEach((Metric m) => m.eventStream.listen((_) { |
| 140 eventStream.listen((_) { | 118 m.timings.add( |
| 141 elapsed = stopwatch.elapsed; | 119 new Duration(milliseconds: stopwatch.elapsed.inMilliseconds)); |
| 142 }); | 120 })); |
| 143 | 121 |
| 122 var subscriptions = <AnalysisService, List<String>>{}; |
| 123 metrics.forEach((Metric m) => subscriptions[m.service] = [priorityFile]); |
| 124 |
| 125 sendAnalysisSetSubscriptions(subscriptions); |
| 126 |
| 127 // Set root after subscribing to avoid empty notifications. |
| 144 setAnalysisRoot(); | 128 setAnalysisRoot(); |
| 145 sendAnalysisSetSubscriptions({ | |
| 146 service: [priorityFile] | |
| 147 }); | |
| 148 | 129 |
| 149 sendAnalysisSetPriorityFiles([priorityFile]); | 130 sendAnalysisSetPriorityFiles([priorityFile]); |
| 150 | 131 |
| 151 return analysisFinished.then((_) { | 132 return analysisFinished.then((_) { |
| 152 print('$description completed in ${elapsed}'); | 133 print('analysis completed in ${stopwatch.elapsed}'); |
| 134 metrics.forEach((Metric m) => print('${m.name} timings: ${m.timings}')); |
| 153 stopwatch.reset(); | 135 stopwatch.reset(); |
| 154 }); | 136 }); |
| 155 } | 137 } |
| 156 } | 138 } |
| OLD | NEW |