|
| 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 |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +library server.performance.local; |
| 6 | + |
| 7 | +import 'dart:async'; |
| 8 | + |
| 9 | +import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 10 | + |
| 11 | +import 'benchmark_scenario.dart'; |
| 12 | +import 'memory_tests.dart'; |
| 13 | + |
| 14 | +main(List<String> args) async { |
| 15 | + int length = args.length; |
| 16 | + if (length < 1) { |
| 17 | + print('Usage: dart benchmark_local.dart path_to_flutter_checkout' |
| 18 | + ' [benchmark_id]'); |
| 19 | + return; |
| 20 | + } |
| 21 | + paths = new PathHolder(flutterPath: args[0]); |
| 22 | + String id = args.length >= 2 ? args[1] : null; |
| 23 | + if (id == null) { |
| 24 | + for (String id in benchmarks.keys) { |
| 25 | + BenchmarkFunction benchmark = benchmarks[id]; |
| 26 | + await benchmark(id); |
| 27 | + } |
| 28 | + } else { |
| 29 | + BenchmarkFunction benchmark = benchmarks[id]; |
| 30 | + if (benchmark != null) { |
| 31 | + benchmark(id); |
| 32 | + } |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +const Map<String, BenchmarkFunction> benchmarks = |
| 37 | + const <String, BenchmarkFunction>{ |
| 38 | + 'flutter-initialAnalysis-1': run_flutter_initialAnalysis_1, |
| 39 | + 'flutter-initialAnalysis-2': run_flutter_initialAnalysis_2, |
| 40 | + 'flutter-change-1': run_flutter_change_1, |
| 41 | + 'flutter-change-2': run_flutter_change_2, |
| 42 | + 'flutter-completion-1': run_flutter_completion_1, |
| 43 | + 'flutter-completion-2': run_flutter_completion_2, |
| 44 | + 'flutter-refactoring-1': run_flutter_refactoring_1, |
| 45 | + 'flutter-memory-initialAnalysis-1': run_flutter_memory_initialAnalysis_1, |
| 46 | + 'flutter-memory-initialAnalysis-2': run_flutter_memory_initialAnalysis_2, |
| 47 | +}; |
| 48 | + |
| 49 | +PathHolder paths; |
| 50 | + |
| 51 | +Future run_flutter_change_1(String id) async { |
| 52 | + String description = r''' |
| 53 | +1. Open 'packages/flutter'. |
| 54 | +2. Change a method body in lib/src/painting/colors.dart |
| 55 | +3. Measure the time to finish analysis. |
| 56 | +4. Rollback changes to the file and wait for analysis. |
| 57 | +5. Go to (2). |
| 58 | +'''; |
| 59 | + List<int> times = await new BenchmarkScenario().waitAnalyze_change_analyze( |
| 60 | + roots: [paths.packageFlutter], |
| 61 | + file: '${paths.packageFlutter}/lib/src/painting/colors.dart', |
| 62 | + fileChange: new FileChange( |
| 63 | + afterStr: 'final double h = hue % 360;', insertStr: 'print(12345);'), |
| 64 | + numOfRepeats: 10); |
| 65 | + printBenchmarkResults(id, description, times); |
| 66 | +} |
| 67 | + |
| 68 | +Future run_flutter_change_2(String id) async { |
| 69 | + String description = r''' |
| 70 | +1. Open 'packages/flutter'. |
| 71 | +2. Change the name of a public method in lib/src/painting/colors.dart |
| 72 | +3. Measure the time to finish analysis. |
| 73 | +4. Rollback changes to the file and wait for analysis. |
| 74 | +5. Go to (2). |
| 75 | +'''; |
| 76 | + List<int> times = await new BenchmarkScenario().waitAnalyze_change_analyze( |
| 77 | + roots: [paths.packageFlutter], |
| 78 | + file: '${paths.packageFlutter}/lib/src/painting/colors.dart', |
| 79 | + fileChange: new FileChange( |
| 80 | + afterStr: 'withValue(dou', afterStrBack: 4, insertStr: 'NewName'), |
| 81 | + numOfRepeats: 5); |
| 82 | + printBenchmarkResults(id, description, times); |
| 83 | +} |
| 84 | + |
| 85 | +Future run_flutter_completion_1(String id) async { |
| 86 | + String description = r''' |
| 87 | +1. Open 'packages/flutter'. |
| 88 | +2. Change a method body in packages/flutter/lib/src/material/button.dart |
| 89 | +3. Request code completion in this method and measure time to get results. |
| 90 | +4. Rollback changes to the file and wait for analysis. |
| 91 | +5. Go to (2). |
| 92 | +'''; |
| 93 | + String completionMarker = 'print(12345);'; |
| 94 | + List<int> times = await new BenchmarkScenario() |
| 95 | + .waitAnalyze_change_getCompletion( |
| 96 | + roots: [paths.packageFlutter], |
| 97 | + file: '${paths.packageFlutter}/lib/src/material/button.dart', |
| 98 | + fileChange: new FileChange( |
| 99 | + afterStr: 'Widget build(BuildContext context) {', |
| 100 | + insertStr: completionMarker), |
| 101 | + completeAfterStr: completionMarker, |
| 102 | + numOfRepeats: 10); |
| 103 | + printBenchmarkResults(id, description, times); |
| 104 | +} |
| 105 | + |
| 106 | +Future run_flutter_completion_2(String id) async { |
| 107 | + String description = r''' |
| 108 | +1. Open 'packages/flutter'. |
| 109 | +2. Change the name of a public method in lib/src/rendering/layer.dart |
| 110 | +3. Request code completion in this method and measure time to get results. |
| 111 | +4. Rollback changes to the file and wait for analysis. |
| 112 | +5. Go to (2). |
| 113 | +'''; |
| 114 | + List<int> times = await new BenchmarkScenario() |
| 115 | + .waitAnalyze_change_getCompletion( |
| 116 | + roots: [paths.packageFlutter], |
| 117 | + file: '${paths.packageFlutter}/lib/src/rendering/layer.dart', |
| 118 | + fileChange: new FileChange( |
| 119 | + replaceWhat: 'void removeAllChildren() {', |
| 120 | + replaceWith: 'void removeAllChildren2() {print(12345);parent.'), |
| 121 | + completeAfterStr: 'print(12345);parent.', |
| 122 | + numOfRepeats: 5); |
| 123 | + printBenchmarkResults(id, description, times); |
| 124 | +} |
| 125 | + |
| 126 | +Future run_flutter_initialAnalysis_1(String id) async { |
| 127 | + String description = r''' |
| 128 | +1. Start server, set 'hello_world' analysis root. |
| 129 | +2. Measure the time to finish initial analysis. |
| 130 | +3. Shutdown the server. |
| 131 | +4. Go to (1). |
| 132 | +'''; |
| 133 | + List<int> times = await BenchmarkScenario.start_waitInitialAnalysis_shutdown( |
| 134 | + roots: [paths.exampleHelloWorld], numOfRepeats: 5); |
| 135 | + printBenchmarkResults(id, description, times); |
| 136 | +} |
| 137 | + |
| 138 | +Future run_flutter_initialAnalysis_2(String id) async { |
| 139 | + String description = r''' |
| 140 | +1. Start server, set 'hello_world' and 'flutter_gallery' analysis roots. |
| 141 | +2. Measure the time to finish initial analysis. |
| 142 | +3. Shutdown the server. |
| 143 | +4. Go to (1). |
| 144 | +'''; |
| 145 | + List<int> times = await BenchmarkScenario.start_waitInitialAnalysis_shutdown( |
| 146 | + roots: [paths.exampleHelloWorld, paths.exampleGallery], numOfRepeats: 5); |
| 147 | + printBenchmarkResults(id, description, times); |
| 148 | +} |
| 149 | + |
| 150 | +Future run_flutter_memory_initialAnalysis_1(String id) async { |
| 151 | + String description = r''' |
| 152 | +1. Start server, set 'packages/flutter' as the analysis root. |
| 153 | +2. Measure the memory usage after finishing initial analysis. |
| 154 | +3. Shutdown the server. |
| 155 | +4. Go to (1). |
| 156 | +'''; |
| 157 | + List<int> sizes = await AnalysisServerMemoryUsageTest |
| 158 | + .start_waitInitialAnalysis_shutdown( |
| 159 | + roots: <String>[paths.packageFlutter], numOfRepeats: 3); |
| 160 | + printMemoryResults(id, description, sizes); |
| 161 | +} |
| 162 | + |
| 163 | +Future run_flutter_memory_initialAnalysis_2(String id) async { |
| 164 | + String description = r''' |
| 165 | +1. Start server, set 'packages/flutter' and 'packages/flutter_markdown' analysis roots. |
| 166 | +2. Measure the memory usage after finishing initial analysis. |
| 167 | +3. Shutdown the server. |
| 168 | +4. Go to (1). |
| 169 | +'''; |
| 170 | + List<int> sizes = await AnalysisServerMemoryUsageTest |
| 171 | + .start_waitInitialAnalysis_shutdown( |
| 172 | + roots: <String>[paths.packageFlutter, paths.packageMarkdown], |
| 173 | + numOfRepeats: 3); |
| 174 | + printMemoryResults(id, description, sizes); |
| 175 | +} |
| 176 | + |
| 177 | +Future run_flutter_refactoring_1(String id) async { |
| 178 | + String description = r''' |
| 179 | +1. Open 'packages/flutter'. |
| 180 | +2. Change the name of a public method in lib/src/rendering/layer.dart |
| 181 | +3. Request rename refactoring for `getSourcesWithFullName` and measure time to get results. |
| 182 | +4. Rollback changes to the file and wait for analysis. |
| 183 | +5. Go to (2). |
| 184 | +'''; |
| 185 | + List<int> times = await new BenchmarkScenario() |
| 186 | + .waitAnalyze_change_getRefactoring( |
| 187 | + roots: [paths.packageFlutter], |
| 188 | + file: '${paths.packageFlutter}/lib/src/rendering/layer.dart', |
| 189 | + fileChange: new FileChange( |
| 190 | + replaceWhat: 'void removeAllChildren() {', |
| 191 | + replaceWith: 'void removeAllChildren2() {'), |
| 192 | + refactoringAtStr: 'addToScene(ui.SceneBuilder builder', |
| 193 | + refactoringKind: RefactoringKind.RENAME, |
| 194 | + refactoringOptions: new RenameOptions('addToScene2'), |
| 195 | + numOfRepeats: 5); |
| 196 | + printBenchmarkResults(id, description, times); |
| 197 | +} |
| 198 | + |
| 199 | +typedef BenchmarkFunction(String id); |
| 200 | + |
| 201 | +class PathHolder { |
| 202 | + String exampleHelloWorld; |
| 203 | + String exampleGallery; |
| 204 | + String exampleStocks; |
| 205 | + String packageFlutter; |
| 206 | + String packageMarkdown; |
| 207 | + String packageSprites; |
| 208 | + |
| 209 | + PathHolder({String flutterPath}) { |
| 210 | + exampleHelloWorld = '$flutterPath/examples/hello_world'; |
| 211 | + exampleGallery = '$flutterPath/examples/flutter_gallery'; |
| 212 | + exampleStocks = '$flutterPath/examples/stocks'; |
| 213 | + packageFlutter = '$flutterPath/packages/flutter'; |
| 214 | + packageMarkdown = '$flutterPath/packages/flutter_markdown'; |
| 215 | + packageSprites = '$flutterPath/packages/flutter_sprites'; |
| 216 | + } |
| 217 | +} |
0 commit comments