| 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 | 10 |
| 10 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 11 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
| 12 | 13 |
| 13 import 'performance_tests.dart'; | 14 import 'performance_tests.dart'; |
| 14 | 15 |
| 15 void printBenchmarkResults(String id, String description, List<int> times) { | 16 void printBenchmarkResults(String id, String description, List<int> times) { |
| 17 int minTime = times.fold(1 << 20, min); |
| 16 String now = new DateTime.now().toUtc().toIso8601String(); | 18 String now = new DateTime.now().toUtc().toIso8601String(); |
| 17 print('$now ========== $id'); | 19 print('$now ========== $id'); |
| 18 print('times: $times'); | 20 print('times: $times'); |
| 21 print('min_time: $minTime'); |
| 19 print(description.trim()); | 22 print(description.trim()); |
| 20 print('--------------------'); | 23 print('--------------------'); |
| 21 print(''); | 24 print(''); |
| 22 print(''); | 25 print(''); |
| 23 } | 26 } |
| 24 | 27 |
| 25 class BenchmarkScenario extends AbstractTimingTest { | 28 class BenchmarkScenario extends AbstractTimingTest { |
| 26 /** | 29 /** |
| 27 * Init. | 30 * Init. |
| 28 * - Start Analysis Server. | 31 * - Start Analysis Server. |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 await shutdown(); | 181 await shutdown(); |
| 179 return times; | 182 return times; |
| 180 } | 183 } |
| 181 | 184 |
| 182 /** | 185 /** |
| 183 * Compute updated content of the [file] as described by [desc], add overlay | 186 * Compute updated content of the [file] as described by [desc], add overlay |
| 184 * for the [file], and return the updated content. | 187 * for the [file], and return the updated content. |
| 185 */ | 188 */ |
| 186 Future<String> _applyFileChange(String file, FileChange desc) async { | 189 Future<String> _applyFileChange(String file, FileChange desc) async { |
| 187 String originalContent = _getFileContent(file); | 190 String originalContent = _getFileContent(file); |
| 188 int offset = _indexOfEnd(file, originalContent, desc.afterStr); | 191 String updatedContent; |
| 189 offset -= desc.afterStrBack; | 192 if (desc.afterStr != null) { |
| 190 String updatedContent = originalContent.substring(0, offset) + | 193 int offset = _indexOfEnd(file, originalContent, desc.afterStr); |
| 191 desc.insertStr + | 194 offset -= desc.afterStrBack; |
| 192 originalContent.substring(offset); | 195 updatedContent = originalContent.substring(0, offset) + |
| 196 desc.insertStr + |
| 197 originalContent.substring(offset); |
| 198 } else if (desc.replaceWhat != null) { |
| 199 int offset = _indexOf(file, originalContent, desc.replaceWhat); |
| 200 updatedContent = originalContent.substring(0, offset) + |
| 201 desc.replaceWith + |
| 202 originalContent.substring(offset + desc.replaceWhat.length); |
| 203 } |
| 193 await sendAnalysisUpdateContent( | 204 await sendAnalysisUpdateContent( |
| 194 {file: new AddContentOverlay(updatedContent)}); | 205 {file: new AddContentOverlay(updatedContent)}); |
| 195 return updatedContent; | 206 return updatedContent; |
| 196 } | 207 } |
| 197 | 208 |
| 198 Future<Duration> _measureCompletionTime(String file, int offset) async { | 209 Future<Duration> _measureCompletionTime(String file, int offset) async { |
| 199 Stopwatch stopwatch = new Stopwatch(); | 210 Stopwatch stopwatch = new Stopwatch(); |
| 200 stopwatch.start(); | 211 stopwatch.start(); |
| 201 Completer<Duration> completer = new Completer<Duration>(); | 212 Completer<Duration> completer = new Completer<Duration>(); |
| 202 var completionSubscription = onCompletionResults.listen((_) { | 213 var completionSubscription = onCompletionResults.listen((_) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 */ | 283 */ |
| 273 static int _indexOfEnd(String file, String where, String what) { | 284 static int _indexOfEnd(String file, String where, String what) { |
| 274 return _indexOf(file, where, what) + what.length; | 285 return _indexOf(file, where, what) + what.length; |
| 275 } | 286 } |
| 276 } | 287 } |
| 277 | 288 |
| 278 class FileChange { | 289 class FileChange { |
| 279 final String afterStr; | 290 final String afterStr; |
| 280 final int afterStrBack; | 291 final int afterStrBack; |
| 281 final String insertStr; | 292 final String insertStr; |
| 293 final String replaceWhat; |
| 294 final String replaceWith; |
| 282 | 295 |
| 283 FileChange({this.afterStr, this.afterStrBack: 0, this.insertStr}) { | 296 FileChange({this.afterStr, this.afterStrBack: 0, this.insertStr, this.replaceW
hat, this.replaceWith}) { |
| 284 expect(afterStr, isNotNull, reason: 'afterStr'); | 297 if (afterStr != null) { |
| 285 expect(insertStr, isNotNull, reason: 'insertStr'); | 298 expect(insertStr, isNotNull, reason: 'insertStr'); |
| 299 } else if (replaceWhat != null) { |
| 300 expect(replaceWith, isNotNull, reason: 'replaceWith'); |
| 301 } |
| 286 } | 302 } |
| 287 } | 303 } |
| OLD | NEW |