| 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.scenarios; | 5 library server.performance.scenarios; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:math'; | 9 import 'dart:math'; |
| 10 | 10 |
| 11 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 11 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 12 import 'package:test/test.dart'; | 12 import 'package:test/test.dart'; |
| 13 | 13 |
| 14 import '../../test/integration/integration_tests.dart'; |
| 14 import 'performance_tests.dart'; | 15 import 'performance_tests.dart'; |
| 15 | 16 |
| 16 void printBenchmarkResults(String id, String description, List<int> times) { | 17 void printBenchmarkResults(String id, String description, List<int> times) { |
| 17 int minTime = times.fold(1 << 20, min); | 18 int minTime = times.fold(1 << 20, min); |
| 18 String now = new DateTime.now().toUtc().toIso8601String(); | 19 String now = new DateTime.now().toUtc().toIso8601String(); |
| 19 print('$now ========== $id'); | 20 print('$now ========== $id'); |
| 20 print('times: $times'); | 21 print('times: $times'); |
| 21 print('min_time: $minTime'); | 22 print('min_time: $minTime'); |
| 22 print(description.trim()); | 23 print(description.trim()); |
| 23 print('--------------------'); | 24 print('--------------------'); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 39 * | 40 * |
| 40 * Repeat. | 41 * Repeat. |
| 41 * - Undo changes to the [file]. | 42 * - Undo changes to the [file]. |
| 42 * - Repeat measurement [numOfRepeats] times. | 43 * - Repeat measurement [numOfRepeats] times. |
| 43 */ | 44 */ |
| 44 Future<List<int>> waitAnalyze_change_analyze( | 45 Future<List<int>> waitAnalyze_change_analyze( |
| 45 {List<String> roots, | 46 {List<String> roots, |
| 46 String file, | 47 String file, |
| 47 FileChange fileChange, | 48 FileChange fileChange, |
| 48 int numOfRepeats}) async { | 49 int numOfRepeats}) async { |
| 49 expect(roots, isNotNull, reason: 'roots'); | 50 outOfTestExpect(roots, isNotNull, reason: 'roots'); |
| 50 expect(file, isNotNull, reason: 'file'); | 51 outOfTestExpect(file, isNotNull, reason: 'file'); |
| 51 expect(fileChange, isNotNull, reason: 'fileChange'); | 52 outOfTestExpect(fileChange, isNotNull, reason: 'fileChange'); |
| 52 expect(numOfRepeats, isNotNull, reason: 'numOfRepeats'); | 53 outOfTestExpect(numOfRepeats, isNotNull, reason: 'numOfRepeats'); |
| 53 // Initialize Analysis Server. | 54 // Initialize Analysis Server. |
| 54 await super.setUp(); | 55 await super.setUp(); |
| 55 await subscribeToStatusNotifications(); | 56 await subscribeToStatusNotifications(); |
| 56 // Set roots and analyze. | 57 // Set roots and analyze. |
| 57 await sendAnalysisSetAnalysisRoots(roots, []); | 58 await sendAnalysisSetAnalysisRoots(roots, []); |
| 58 await analysisFinished; | 59 await analysisFinished; |
| 59 // Make the file priority. | 60 // Make the file priority. |
| 60 await sendAnalysisSetPriorityFiles([file]); | 61 await sendAnalysisSetPriorityFiles([file]); |
| 61 // Repeat. | 62 // Repeat. |
| 62 List<int> times = <int>[]; | 63 List<int> times = <int>[]; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 88 * 7. Record the time to get completion results. | 89 * 7. Record the time to get completion results. |
| 89 * 8. Undo changes to the [file] and analyze. | 90 * 8. Undo changes to the [file] and analyze. |
| 90 * 9. Go to (5). | 91 * 9. Go to (5). |
| 91 */ | 92 */ |
| 92 Future<List<int>> waitAnalyze_change_getCompletion( | 93 Future<List<int>> waitAnalyze_change_getCompletion( |
| 93 {List<String> roots, | 94 {List<String> roots, |
| 94 String file, | 95 String file, |
| 95 FileChange fileChange, | 96 FileChange fileChange, |
| 96 String completeAfterStr, | 97 String completeAfterStr, |
| 97 int numOfRepeats}) async { | 98 int numOfRepeats}) async { |
| 98 expect(roots, isNotNull, reason: 'roots'); | 99 outOfTestExpect(roots, isNotNull, reason: 'roots'); |
| 99 expect(file, isNotNull, reason: 'file'); | 100 outOfTestExpect(file, isNotNull, reason: 'file'); |
| 100 expect(fileChange, isNotNull, reason: 'fileChange'); | 101 outOfTestExpect(fileChange, isNotNull, reason: 'fileChange'); |
| 101 expect(completeAfterStr, isNotNull, reason: 'completeAfterStr'); | 102 outOfTestExpect(completeAfterStr, isNotNull, reason: 'completeAfterStr'); |
| 102 expect(numOfRepeats, isNotNull, reason: 'numOfRepeats'); | 103 outOfTestExpect(numOfRepeats, isNotNull, reason: 'numOfRepeats'); |
| 103 // Initialize Analysis Server. | 104 // Initialize Analysis Server. |
| 104 await super.setUp(); | 105 await super.setUp(); |
| 105 await subscribeToStatusNotifications(); | 106 await subscribeToStatusNotifications(); |
| 106 // Set roots and analyze. | 107 // Set roots and analyze. |
| 107 await sendAnalysisSetAnalysisRoots(roots, []); | 108 await sendAnalysisSetAnalysisRoots(roots, []); |
| 108 await analysisFinished; | 109 await analysisFinished; |
| 109 // Make the file priority. | 110 // Make the file priority. |
| 110 await sendAnalysisSetPriorityFiles([file]); | 111 await sendAnalysisSetPriorityFiles([file]); |
| 111 // Repeat. | 112 // Repeat. |
| 112 List<int> times = <int>[]; | 113 List<int> times = <int>[]; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 142 * 9. Go to (5). | 143 * 9. Go to (5). |
| 143 */ | 144 */ |
| 144 Future<List<int>> waitAnalyze_change_getRefactoring( | 145 Future<List<int>> waitAnalyze_change_getRefactoring( |
| 145 {List<String> roots, | 146 {List<String> roots, |
| 146 String file, | 147 String file, |
| 147 FileChange fileChange, | 148 FileChange fileChange, |
| 148 String refactoringAtStr, | 149 String refactoringAtStr, |
| 149 RefactoringKind refactoringKind, | 150 RefactoringKind refactoringKind, |
| 150 RefactoringOptions refactoringOptions, | 151 RefactoringOptions refactoringOptions, |
| 151 int numOfRepeats}) async { | 152 int numOfRepeats}) async { |
| 152 expect(roots, isNotNull, reason: 'roots'); | 153 outOfTestExpect(roots, isNotNull, reason: 'roots'); |
| 153 expect(file, isNotNull, reason: 'file'); | 154 outOfTestExpect(file, isNotNull, reason: 'file'); |
| 154 expect(fileChange, isNotNull, reason: 'fileChange'); | 155 outOfTestExpect(fileChange, isNotNull, reason: 'fileChange'); |
| 155 expect(refactoringAtStr, isNotNull, reason: 'refactoringAtStr'); | 156 outOfTestExpect(refactoringAtStr, isNotNull, reason: 'refactoringAtStr'); |
| 156 expect(refactoringKind, isNotNull, reason: 'refactoringKind'); | 157 outOfTestExpect(refactoringKind, isNotNull, reason: 'refactoringKind'); |
| 157 expect(refactoringOptions, isNotNull, reason: 'refactoringOptions'); | 158 outOfTestExpect(refactoringOptions, isNotNull, |
| 158 expect(numOfRepeats, isNotNull, reason: 'numOfRepeats'); | 159 reason: 'refactoringOptions'); |
| 160 outOfTestExpect(numOfRepeats, isNotNull, reason: 'numOfRepeats'); |
| 159 // Initialize Analysis Server. | 161 // Initialize Analysis Server. |
| 160 await super.setUp(); | 162 await super.setUp(); |
| 161 await subscribeToStatusNotifications(); | 163 await subscribeToStatusNotifications(); |
| 162 // Set roots and analyze. | 164 // Set roots and analyze. |
| 163 await sendAnalysisSetAnalysisRoots(roots, []); | 165 await sendAnalysisSetAnalysisRoots(roots, []); |
| 164 await analysisFinished; | 166 await analysisFinished; |
| 165 // Make the file priority. | 167 // Make the file priority. |
| 166 await sendAnalysisSetPriorityFiles([file]); | 168 await sendAnalysisSetPriorityFiles([file]); |
| 167 // Repeat. | 169 // Repeat. |
| 168 List<int> times = <int>[]; | 170 List<int> times = <int>[]; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 /** | 238 /** |
| 237 * 1. Start Analysis Server. | 239 * 1. Start Analysis Server. |
| 238 * 2. Set the analysis [roots]. | 240 * 2. Set the analysis [roots]. |
| 239 * 3. Wait for analysis to complete. | 241 * 3. Wait for analysis to complete. |
| 240 * 4. Record the time to finish analysis. | 242 * 4. Record the time to finish analysis. |
| 241 * 5. Shutdown. | 243 * 5. Shutdown. |
| 242 * 6. Go to (1). | 244 * 6. Go to (1). |
| 243 */ | 245 */ |
| 244 static Future<List<int>> start_waitInitialAnalysis_shutdown( | 246 static Future<List<int>> start_waitInitialAnalysis_shutdown( |
| 245 {List<String> roots, int numOfRepeats}) async { | 247 {List<String> roots, int numOfRepeats}) async { |
| 246 expect(roots, isNotNull, reason: 'roots'); | 248 outOfTestExpect(roots, isNotNull, reason: 'roots'); |
| 247 expect(numOfRepeats, isNotNull, reason: 'numOfRepeats'); | 249 outOfTestExpect(numOfRepeats, isNotNull, reason: 'numOfRepeats'); |
| 248 // Repeat. | 250 // Repeat. |
| 249 List<int> times = <int>[]; | 251 List<int> times = <int>[]; |
| 250 for (int i = 0; i < numOfRepeats; i++) { | 252 for (int i = 0; i < numOfRepeats; i++) { |
| 251 BenchmarkScenario instance = new BenchmarkScenario(); | 253 BenchmarkScenario instance = new BenchmarkScenario(); |
| 252 // Initialize Analysis Server. | 254 // Initialize Analysis Server. |
| 253 await instance.setUp(); | 255 await instance.setUp(); |
| 254 await instance.subscribeToStatusNotifications(); | 256 await instance.subscribeToStatusNotifications(); |
| 255 // Set roots and analyze. | 257 // Set roots and analyze. |
| 256 Stopwatch stopwatch = new Stopwatch()..start(); | 258 Stopwatch stopwatch = new Stopwatch()..start(); |
| 257 await instance.sendAnalysisSetAnalysisRoots(roots, []); | 259 await instance.sendAnalysisSetAnalysisRoots(roots, []); |
| 258 await instance.analysisFinished; | 260 await instance.analysisFinished; |
| 259 times.add(stopwatch.elapsed.inMilliseconds); | 261 times.add(stopwatch.elapsed.inMilliseconds); |
| 260 // Stop the server. | 262 // Stop the server. |
| 261 await instance.shutdown(); | 263 await instance.shutdown(); |
| 262 } | 264 } |
| 263 return times; | 265 return times; |
| 264 } | 266 } |
| 265 | 267 |
| 266 static String _getFileContent(String path) { | 268 static String _getFileContent(String path) { |
| 267 File file = new File(path); | 269 File file = new File(path); |
| 268 expect(file.existsSync(), isTrue, reason: 'File $path does not exist.'); | 270 outOfTestExpect(file.existsSync(), isTrue, |
| 271 reason: 'File $path does not exist.'); |
| 269 return file.readAsStringSync(); | 272 return file.readAsStringSync(); |
| 270 } | 273 } |
| 271 | 274 |
| 272 /** | 275 /** |
| 273 * Return the index of [what] in [where] in the [file], fail if not found. | 276 * Return the index of [what] in [where] in the [file], fail if not found. |
| 274 */ | 277 */ |
| 275 static int _indexOf(String file, String where, String what) { | 278 static int _indexOf(String file, String where, String what) { |
| 276 int index = where.indexOf(what); | 279 int index = where.indexOf(what); |
| 277 expect(index, isNot(-1), reason: 'Cannot find |$what| in $file.'); | 280 outOfTestExpect(index, isNot(-1), reason: 'Cannot find |$what| in $file.'); |
| 278 return index; | 281 return index; |
| 279 } | 282 } |
| 280 | 283 |
| 281 /** | 284 /** |
| 282 * Return the end index if [what] in [where] in the [file], fail if not found. | 285 * Return the end index if [what] in [where] in the [file], fail if not found. |
| 283 */ | 286 */ |
| 284 static int _indexOfEnd(String file, String where, String what) { | 287 static int _indexOfEnd(String file, String where, String what) { |
| 285 return _indexOf(file, where, what) + what.length; | 288 return _indexOf(file, where, what) + what.length; |
| 286 } | 289 } |
| 287 } | 290 } |
| 288 | 291 |
| 289 class FileChange { | 292 class FileChange { |
| 290 final String afterStr; | 293 final String afterStr; |
| 291 final int afterStrBack; | 294 final int afterStrBack; |
| 292 final String insertStr; | 295 final String insertStr; |
| 293 final String replaceWhat; | 296 final String replaceWhat; |
| 294 final String replaceWith; | 297 final String replaceWith; |
| 295 | 298 |
| 296 FileChange({this.afterStr, this.afterStrBack: 0, this.insertStr, this.replaceW
hat, this.replaceWith}) { | 299 FileChange( |
| 300 {this.afterStr, |
| 301 this.afterStrBack: 0, |
| 302 this.insertStr, |
| 303 this.replaceWhat, |
| 304 this.replaceWith}) { |
| 297 if (afterStr != null) { | 305 if (afterStr != null) { |
| 298 expect(insertStr, isNotNull, reason: 'insertStr'); | 306 outOfTestExpect(insertStr, isNotNull, reason: 'insertStr'); |
| 299 } else if (replaceWhat != null) { | 307 } else if (replaceWhat != null) { |
| 300 expect(replaceWith, isNotNull, reason: 'replaceWith'); | 308 outOfTestExpect(replaceWith, isNotNull, reason: 'replaceWith'); |
| 301 } | 309 } |
| 302 } | 310 } |
| 303 } | 311 } |
| OLD | NEW |