| 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 library server.performance.local; | 5 library server.performance.local; |
| 6 | 6 |
| 7 import 'dart:async'; |
| 8 |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 8 | 10 |
| 9 import 'benchmark_scenario.dart'; | 11 import 'benchmark_scenario.dart'; |
| 10 | 12 |
| 11 main(List<String> args) async { | 13 main(List<String> args) async { |
| 12 String pathRepository = args[0]; | 14 int length = args.length; |
| 13 String pathServer = '$pathRepository/pkg/analysis_server'; | 15 if (length < 1) { |
| 14 String pathAnalyzer = '$pathRepository/pkg/analyzer'; | 16 print( |
| 15 { | 17 'Usage: dart benchmark_local.dart path_to_sdk_checkout [path_to_flutter_
checkout]'); |
| 16 String now = new DateTime.now().toUtc().toIso8601String(); | 18 return; |
| 17 print('Benchmark started: $now'); | 19 } else if (length == 1) { |
| 18 print(''); | 20 paths = new PathHolder(sdkPath: args[0]); |
| 19 print(''); | 21 } else { |
| 22 paths = new PathHolder(sdkPath: args[0], flutterPath: args[1]); |
| 20 } | 23 } |
| 21 | 24 String now = new DateTime.now().toUtc().toIso8601String(); |
| 22 { | 25 print('Benchmark started: $now'); |
| 23 String id = 'local-initialAnalysis-1'; | 26 print(''); |
| 24 String description = r''' | 27 print(''); |
| 28 await run_local_initialAnalysis_1(); |
| 29 await run_local_initialAnalysis_2(); |
| 30 await run_local_initialAnalysis_3(); |
| 31 await run_local_change_1(); |
| 32 await run_local_change_2(); |
| 33 await run_local_completion_1(); |
| 34 await run_local_completion_2(); |
| 35 await run_local_completion_3(); |
| 36 await run_local_completion_4(); |
| 37 await run_local_refactoring_1(); |
| 38 } |
| 39 |
| 40 PathHolder paths; |
| 41 |
| 42 Future run_local_change_1() async { |
| 43 String id = 'local-change-1'; |
| 44 String description = r''' |
| 45 1. Open 'analyzer'. |
| 46 2. Change a method body in src/task/dart.dart. |
| 47 3. Measure the time to finish analysis. |
| 48 4. Rollback changes to the file and wait for analysis. |
| 49 5. Go to (2). |
| 50 '''; |
| 51 List<int> times = await new BenchmarkScenario().waitAnalyze_change_analyze( |
| 52 roots: [paths.analyzer], |
| 53 file: '${paths.analyzer}/lib/src/task/dart.dart', |
| 54 fileChange: new FileChange( |
| 55 afterStr: 'if (hasDirectiveChange) {', insertStr: 'print(12345);'), |
| 56 numOfRepeats: 10); |
| 57 printBenchmarkResults(id, description, times); |
| 58 } |
| 59 |
| 60 Future run_local_change_2() async { |
| 61 String id = 'local-change-2'; |
| 62 String description = r''' |
| 63 1. Open 'analyzer'. |
| 64 2. Change the name of a public method in src/task/dart.dart. |
| 65 3. Measure the time to finish analysis. |
| 66 4. Rollback changes to the file and wait for analysis. |
| 67 5. Go to (2). |
| 68 '''; |
| 69 List<int> times = await new BenchmarkScenario().waitAnalyze_change_analyze( |
| 70 roots: [paths.analyzer], |
| 71 file: '${paths.analyzer}/lib/src/task/dart.dart', |
| 72 fileChange: new FileChange( |
| 73 afterStr: 'resolveDirective(An', |
| 74 afterStrBack: 3, |
| 75 insertStr: 'NewName'), |
| 76 numOfRepeats: 5); |
| 77 printBenchmarkResults(id, description, times); |
| 78 } |
| 79 |
| 80 Future run_local_completion_1() async { |
| 81 String id = 'local-completion-1'; |
| 82 String description = r''' |
| 83 1. Open 'analyzer'. |
| 84 2. Change a method body in src/task/dart.dart. |
| 85 3. Request code completion in this method and measure time to get results. |
| 86 4. Rollback changes to the file and wait for analysis. |
| 87 5. Go to (2). |
| 88 '''; |
| 89 List<int> times = await new BenchmarkScenario() |
| 90 .waitAnalyze_change_getCompletion( |
| 91 roots: [paths.analyzer], |
| 92 file: '${paths.analyzer}/lib/src/task/dart.dart', |
| 93 fileChange: new FileChange( |
| 94 afterStr: 'if (hasDirectiveChange) {', |
| 95 insertStr: 'print(12345);'), |
| 96 completeAfterStr: 'print(12345);', |
| 97 numOfRepeats: 10); |
| 98 printBenchmarkResults(id, description, times); |
| 99 } |
| 100 |
| 101 Future run_local_completion_2() async { |
| 102 String id = 'local-completion-2'; |
| 103 String description = r''' |
| 104 1. Open 'analyzer'. |
| 105 2. Change the name of a public method in src/task/dart.dart. |
| 106 3. Request code completion in this method and measure time to get results. |
| 107 4. Rollback changes to the file and wait for analysis. |
| 108 5. Go to (2). |
| 109 '''; |
| 110 List<int> times = await new BenchmarkScenario() |
| 111 .waitAnalyze_change_getCompletion( |
| 112 roots: [paths.analyzer], |
| 113 file: '${paths.analyzer}/lib/src/task/dart.dart', |
| 114 fileChange: new FileChange( |
| 115 afterStr: 'DeltaResult validate(In', |
| 116 afterStrBack: 3, |
| 117 insertStr: 'NewName'), |
| 118 completeAfterStr: 'if (hasDirectiveChange) {', |
| 119 numOfRepeats: 5); |
| 120 printBenchmarkResults(id, description, times); |
| 121 } |
| 122 |
| 123 Future run_local_completion_3() async { |
| 124 String id = 'local-completion-3'; |
| 125 String description = r''' |
| 126 1. Open 'analysis_server' and 'analyzer'. |
| 127 2. Change a method body in src/task/dart.dart. |
| 128 3. Request code completion in this method and measure time to get results. |
| 129 4. Rollback changes to the file and wait for analysis. |
| 130 5. Go to (2). |
| 131 '''; |
| 132 List<int> times = await new BenchmarkScenario() |
| 133 .waitAnalyze_change_getCompletion( |
| 134 roots: [paths.analysisServer, paths.analyzer], |
| 135 file: '${paths.analyzer}/lib/src/task/dart.dart', |
| 136 fileChange: new FileChange( |
| 137 afterStr: 'if (hasDirectiveChange) {', |
| 138 insertStr: 'print(12345);'), |
| 139 completeAfterStr: 'print(12345);', |
| 140 numOfRepeats: 10); |
| 141 printBenchmarkResults(id, description, times); |
| 142 } |
| 143 |
| 144 Future run_local_completion_4() async { |
| 145 String id = 'local-completion-4'; |
| 146 String description = r''' |
| 147 1. Open 'analysis_server' and 'analyzer'. |
| 148 2. Change the name of a public method in src/task/dart.dart. |
| 149 3. Request code completion in this method and measure time to get results. |
| 150 4. Rollback changes to the file and wait for analysis. |
| 151 5. Go to (2). |
| 152 '''; |
| 153 List<int> times = await new BenchmarkScenario() |
| 154 .waitAnalyze_change_getCompletion( |
| 155 roots: [paths.analysisServer, paths.analyzer], |
| 156 file: '${paths.analyzer}/lib/src/task/dart.dart', |
| 157 fileChange: new FileChange( |
| 158 afterStr: 'DeltaResult validate(In', |
| 159 afterStrBack: 3, |
| 160 insertStr: 'NewName'), |
| 161 completeAfterStr: 'if (hasDirectiveChange) {', |
| 162 numOfRepeats: 5); |
| 163 printBenchmarkResults(id, description, times); |
| 164 } |
| 165 |
| 166 Future run_local_initialAnalysis_1() async { |
| 167 String id = 'local-initialAnalysis-1'; |
| 168 String description = r''' |
| 25 1. Start server, set 'analyzer' analysis root. | 169 1. Start server, set 'analyzer' analysis root. |
| 26 2. Measure the time to finish initial analysis. | 170 2. Measure the time to finish initial analysis. |
| 27 3. Shutdown the server. | 171 3. Shutdown the server. |
| 28 4. Go to (1). | 172 4. Go to (1). |
| 29 '''; | 173 '''; |
| 30 List<int> times = await BenchmarkScenario | 174 List<int> times = await BenchmarkScenario.start_waitInitialAnalysis_shutdown( |
| 31 .start_waitInitialAnalysis_shutdown( | 175 roots: [paths.analyzer], numOfRepeats: 3); |
| 32 roots: [pathAnalyzer], numOfRepeats: 3); | 176 printBenchmarkResults(id, description, times); |
| 33 printBenchmarkResults(id, description, times); | 177 } |
| 34 } | 178 |
| 35 | 179 Future run_local_initialAnalysis_2() async { |
| 36 { | 180 String id = 'local-initialAnalysis-2'; |
| 37 String id = 'local-initialAnalysis-2'; | 181 String description = r''' |
| 38 String description = r''' | |
| 39 1. Start server, set 'analyzer' and 'analysis_server' analysis roots. | 182 1. Start server, set 'analyzer' and 'analysis_server' analysis roots. |
| 40 2. Measure the time to finish initial analysis. | 183 2. Measure the time to finish initial analysis. |
| 41 3. Shutdown the server. | 184 3. Shutdown the server. |
| 42 4. Go to (1). | 185 4. Go to (1). |
| 43 '''; | 186 '''; |
| 44 List<int> times = await BenchmarkScenario | 187 List<int> times = await BenchmarkScenario.start_waitInitialAnalysis_shutdown( |
| 45 .start_waitInitialAnalysis_shutdown( | 188 roots: [paths.analyzer, paths.analysisServer], numOfRepeats: 3); |
| 46 roots: [pathAnalyzer, pathServer], numOfRepeats: 3); | 189 printBenchmarkResults(id, description, times); |
| 47 printBenchmarkResults(id, description, times); | 190 } |
| 48 } | 191 |
| 49 | 192 Future run_local_initialAnalysis_3() async { |
| 50 { | 193 String id = 'local-initialAnalysis-3'; |
| 51 String id = 'local-change-1'; | 194 String description = r''' |
| 52 String description = r''' | 195 1. Start server, set 'hello_world' and 'stocks' analysis roots. |
| 53 1. Open 'analyzer'. | 196 2. Measure the time to finish initial analysis. |
| 54 2. Change a method body in src/task/dart.dart. | 197 3. Shutdown the server. |
| 55 3. Measure the time to finish analysis. | 198 4. Go to (1). |
| 56 4. Rollback changes to the file and wait for analysis. | 199 '''; |
| 57 5. Go to (2). | 200 List<int> times = await BenchmarkScenario.start_waitInitialAnalysis_shutdown( |
| 58 '''; | 201 roots: [paths.flutterHelloWorld, paths.flutterStocks], numOfRepeats: 3); |
| 59 List<int> times = await new BenchmarkScenario().waitAnalyze_change_analyze( | 202 printBenchmarkResults(id, description, times); |
| 60 roots: [pathAnalyzer], | 203 } |
| 61 file: '$pathAnalyzer/lib/src/task/dart.dart', | 204 |
| 62 fileChange: new FileChange( | 205 Future run_local_refactoring_1() async { |
| 63 afterStr: 'if (hasDirectiveChange) {', insertStr: 'print(12345);'), | 206 String id = 'local-refactoring-1'; |
| 64 numOfRepeats: 10); | 207 String description = r''' |
| 65 printBenchmarkResults(id, description, times); | |
| 66 } | |
| 67 | |
| 68 { | |
| 69 String id = 'local-change-2'; | |
| 70 String description = r''' | |
| 71 1. Open 'analyzer'. | |
| 72 2. Change the name of a public method in src/task/dart.dart. | |
| 73 3. Measure the time to finish analysis. | |
| 74 4. Rollback changes to the file and wait for analysis. | |
| 75 5. Go to (2). | |
| 76 '''; | |
| 77 List<int> times = await new BenchmarkScenario().waitAnalyze_change_analyze( | |
| 78 roots: [pathAnalyzer], | |
| 79 file: '$pathAnalyzer/lib/src/task/dart.dart', | |
| 80 fileChange: new FileChange( | |
| 81 afterStr: 'resolveDirective(An', | |
| 82 afterStrBack: 3, | |
| 83 insertStr: 'NewName'), | |
| 84 numOfRepeats: 5); | |
| 85 printBenchmarkResults(id, description, times); | |
| 86 } | |
| 87 | |
| 88 { | |
| 89 String id = 'local-completion-1'; | |
| 90 String description = r''' | |
| 91 1. Open 'analyzer'. | |
| 92 2. Change a method body in src/task/dart.dart. | |
| 93 3. Request code completion in this method and measure time to get results. | |
| 94 4. Rollback changes to the file and wait for analysis. | |
| 95 5. Go to (2). | |
| 96 '''; | |
| 97 List<int> times = await new BenchmarkScenario() | |
| 98 .waitAnalyze_change_getCompletion( | |
| 99 roots: [pathAnalyzer], | |
| 100 file: '$pathAnalyzer/lib/src/task/dart.dart', | |
| 101 fileChange: new FileChange( | |
| 102 afterStr: 'if (hasDirectiveChange) {', | |
| 103 insertStr: 'print(12345);'), | |
| 104 completeAfterStr: 'print(12345);', | |
| 105 numOfRepeats: 10); | |
| 106 printBenchmarkResults(id, description, times); | |
| 107 } | |
| 108 | |
| 109 { | |
| 110 String id = 'local-completion-2'; | |
| 111 String description = r''' | |
| 112 1. Open 'analyzer'. | |
| 113 2. Change the name of a public method in src/task/dart.dart. | |
| 114 3. Request code completion in this method and measure time to get results. | |
| 115 4. Rollback changes to the file and wait for analysis. | |
| 116 5. Go to (2). | |
| 117 '''; | |
| 118 List<int> times = await new BenchmarkScenario() | |
| 119 .waitAnalyze_change_getCompletion( | |
| 120 roots: [pathAnalyzer], | |
| 121 file: '$pathAnalyzer/lib/src/task/dart.dart', | |
| 122 fileChange: new FileChange( | |
| 123 afterStr: 'DeltaResult validate(In', | |
| 124 afterStrBack: 3, | |
| 125 insertStr: 'NewName'), | |
| 126 completeAfterStr: 'if (hasDirectiveChange) {', | |
| 127 numOfRepeats: 5); | |
| 128 printBenchmarkResults(id, description, times); | |
| 129 } | |
| 130 | |
| 131 { | |
| 132 String id = 'local-completion-3'; | |
| 133 String description = r''' | |
| 134 1. Open 'analysis_server' and 'analyzer'. | |
| 135 2. Change a method body in src/task/dart.dart. | |
| 136 3. Request code completion in this method and measure time to get results. | |
| 137 4. Rollback changes to the file and wait for analysis. | |
| 138 5. Go to (2). | |
| 139 '''; | |
| 140 List<int> times = await new BenchmarkScenario() | |
| 141 .waitAnalyze_change_getCompletion( | |
| 142 roots: [pathServer, pathAnalyzer], | |
| 143 file: '$pathAnalyzer/lib/src/task/dart.dart', | |
| 144 fileChange: new FileChange( | |
| 145 afterStr: 'if (hasDirectiveChange) {', | |
| 146 insertStr: 'print(12345);'), | |
| 147 completeAfterStr: 'print(12345);', | |
| 148 numOfRepeats: 10); | |
| 149 printBenchmarkResults(id, description, times); | |
| 150 } | |
| 151 | |
| 152 { | |
| 153 String id = 'local-completion-4'; | |
| 154 String description = r''' | |
| 155 1. Open 'analysis_server' and 'analyzer'. | |
| 156 2. Change the name of a public method in src/task/dart.dart. | |
| 157 3. Request code completion in this method and measure time to get results. | |
| 158 4. Rollback changes to the file and wait for analysis. | |
| 159 5. Go to (2). | |
| 160 '''; | |
| 161 List<int> times = await new BenchmarkScenario() | |
| 162 .waitAnalyze_change_getCompletion( | |
| 163 roots: [pathServer, pathAnalyzer], | |
| 164 file: '$pathAnalyzer/lib/src/task/dart.dart', | |
| 165 fileChange: new FileChange( | |
| 166 afterStr: 'DeltaResult validate(In', | |
| 167 afterStrBack: 3, | |
| 168 insertStr: 'NewName'), | |
| 169 completeAfterStr: 'if (hasDirectiveChange) {', | |
| 170 numOfRepeats: 5); | |
| 171 printBenchmarkResults(id, description, times); | |
| 172 } | |
| 173 | |
| 174 { | |
| 175 String id = 'local-refactoring-1'; | |
| 176 String description = r''' | |
| 177 1. Open 'analyzer'. | 208 1. Open 'analyzer'. |
| 178 2. Change the name of a public method in src/context/cache.dart. | 209 2. Change the name of a public method in src/context/cache.dart. |
| 179 3. Request rename refactoring for `getSourcesWithFullName` and measure time to g
et results. | 210 3. Request rename refactoring for `getSourcesWithFullName` and measure time to g
et results. |
| 180 4. Rollback changes to the file and wait for analysis. | 211 4. Rollback changes to the file and wait for analysis. |
| 181 5. Go to (2). | 212 5. Go to (2). |
| 182 '''; | 213 '''; |
| 183 List<int> times = await new BenchmarkScenario() | 214 List<int> times = await new BenchmarkScenario() |
| 184 .waitAnalyze_change_getRefactoring( | 215 .waitAnalyze_change_getRefactoring( |
| 185 roots: [pathAnalyzer], | 216 roots: [paths.analyzer], |
| 186 file: '$pathAnalyzer/lib/src/context/cache.dart', | 217 file: '${paths.analyzer}/lib/src/context/cache.dart', |
| 187 fileChange: new FileChange( | 218 fileChange: new FileChange( |
| 188 afterStr: 'getState(An', afterStrBack: 3, insertStr: 'NewName'), | 219 afterStr: 'getState(An', afterStrBack: 3, insertStr: 'NewName'), |
| 189 refactoringAtStr: 'getSourcesWithFullName(String path)', | 220 refactoringAtStr: 'getSourcesWithFullName(String path)', |
| 190 refactoringKind: RefactoringKind.RENAME, | 221 refactoringKind: RefactoringKind.RENAME, |
| 191 refactoringOptions: new RenameOptions('getSourcesWithFullName2'), | 222 refactoringOptions: new RenameOptions('getSourcesWithFullName2'), |
| 192 numOfRepeats: 5); | 223 numOfRepeats: 5); |
| 193 printBenchmarkResults(id, description, times); | 224 printBenchmarkResults(id, description, times); |
| 225 } |
| 226 |
| 227 class PathHolder { |
| 228 String analysisServer; |
| 229 String analyzer; |
| 230 String flutterHelloWorld; |
| 231 String flutterStocks; |
| 232 |
| 233 PathHolder({String sdkPath, String flutterPath}) { |
| 234 analysisServer = '$sdkPath/pkg/analysis_server'; |
| 235 analyzer = '$sdkPath/pkg/analyzer'; |
| 236 flutterHelloWorld = '$flutterPath/examples/hello_world'; |
| 237 flutterStocks = '$flutterPath/examples/stocks'; |
| 194 } | 238 } |
| 195 } | 239 } |
| OLD | NEW |