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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 | 7 |
8 import 'package:args/args.dart'; | 8 import 'package:args/args.dart'; |
9 import 'package:test/test.dart'; | 9 import 'package:test/test.dart'; |
10 | 10 |
11 import 'performance_tests.dart'; | 11 import 'performance_tests.dart'; |
12 | 12 |
| 13 const COMPLETION_OFFSET = 'offset'; |
| 14 const PRIORITY_FILE_OPTION = 'priority'; |
| 15 const SOURCE_OPTION = 'source'; |
| 16 |
13 /** | 17 /** |
14 * Pass in the directory of the source to be analyzed as option `--source`, | 18 * Pass in the directory of the source to be analyzed as option `--source`, |
15 * specify a priority file with `--priority` and an offset for completions | 19 * specify a priority file with `--priority` and an offset for completions |
16 * with a `--offset`. | 20 * with a `--offset`. |
17 */ | 21 */ |
18 main(List<String> arguments) { | 22 main(List<String> arguments) async { |
19 ArgParser parser = _createArgParser(); | 23 ArgParser parser = _createArgParser(); |
20 var args = parser.parse(arguments); | 24 var args = parser.parse(arguments); |
21 if (args[SOURCE_OPTION] == null) { | 25 if (args[SOURCE_OPTION] == null) { |
22 print('path to source directory must be specified'); | 26 print('path to source directory must be specified'); |
23 exit(1); | 27 exit(1); |
24 } | 28 } |
25 source = args[SOURCE_OPTION]; | |
26 priorityFile = args[PRIORITY_FILE_OPTION]; | |
27 offset = int.parse(args[COMPLETION_OFFSET]); | |
28 | 29 |
29 Future.wait([new CompletionTimingTest().test_timing()]); | 30 int offset = int.parse(args[COMPLETION_OFFSET]); |
| 31 String priorityFile = args[PRIORITY_FILE_OPTION]; |
| 32 String source = args[SOURCE_OPTION]; |
| 33 |
| 34 CompletionTimingTest test = |
| 35 new CompletionTimingTest(offset, priorityFile, source); |
| 36 await test.test_timing(); |
30 } | 37 } |
31 | 38 |
32 const COMPLETION_OFFSET = 'offset'; | |
33 const PRIORITY_FILE_OPTION = 'priority'; | |
34 const SOURCE_OPTION = 'source'; | |
35 | |
36 int offset; | |
37 String priorityFile; | |
38 String source; | |
39 | |
40 ArgParser _createArgParser() => new ArgParser() | 39 ArgParser _createArgParser() => new ArgParser() |
41 ..addOption(SOURCE_OPTION, help: 'full path to source directory for analysis') | 40 ..addOption(SOURCE_OPTION, help: 'full path to source directory for analysis') |
42 ..addOption(PRIORITY_FILE_OPTION, help: 'full path to a priority file') | 41 ..addOption(PRIORITY_FILE_OPTION, help: 'full path to a priority file') |
43 ..addOption(COMPLETION_OFFSET, help: 'offset in file for code completions'); | 42 ..addOption(COMPLETION_OFFSET, help: 'offset in file for code completions'); |
44 | 43 |
45 /** | 44 /** |
46 * CompletionTimingTest measures the time taken for the analysis server to respo
nd with | 45 * CompletionTimingTest measures the time taken for the analysis server to respo
nd with |
47 * completion suggestions for a given file and offset. The time measured starts
when | 46 * completion suggestions for a given file and offset. The time measured starts
when |
48 * the analysis root is set and is done when the completion suggestions are rece
ived | 47 * the analysis root is set and is done when the completion suggestions are rece
ived |
49 * from the server. The test does not wait for analysis to be complete before as
king for | 48 * from the server. The test does not wait for analysis to be complete before as
king for |
50 * completions. | 49 * completions. |
51 */ | 50 */ |
52 class CompletionTimingTest extends AbstractTimingTest { | 51 class CompletionTimingTest extends AbstractTimingTest { |
| 52 final int offset; |
| 53 final String priorityFile; |
| 54 final String source; |
| 55 |
53 List<Duration> timings = <Duration>[]; | 56 List<Duration> timings = <Duration>[]; |
54 | 57 |
| 58 CompletionTimingTest(this.offset, this.priorityFile, this.source); |
| 59 |
55 Future test_timing() async { | 60 Future test_timing() async { |
56 // debugStdio(); | 61 // debugStdio(); |
57 | 62 |
58 expect(priorityFile, isNotNull, | 63 expect(priorityFile, isNotNull, |
59 reason: 'A priority file must be specified for completion testing.'); | 64 reason: 'A priority file must be specified for completion testing.'); |
60 expect(offset, isNotNull, | 65 expect(offset, isNotNull, |
61 reason: 'An offset must be specified for completion testing.'); | 66 reason: 'An offset must be specified for completion testing.'); |
62 | 67 |
63 await init(source); | 68 await init(source); |
64 stopwatch.start(); | 69 stopwatch.start(); |
65 | 70 |
66 onCompletionResults.listen((_) { | 71 onCompletionResults.listen((_) { |
67 timings.add(new Duration(milliseconds: stopwatch.elapsed.inMilliseconds)); | 72 timings.add(new Duration(milliseconds: stopwatch.elapsed.inMilliseconds)); |
68 }); | 73 }); |
69 | 74 |
70 setAnalysisRoot(); | 75 setAnalysisRoot(); |
71 sendAnalysisSetPriorityFiles([priorityFile]); | 76 sendAnalysisSetPriorityFiles([priorityFile]); |
72 sendCompletionGetSuggestions(priorityFile, offset); | 77 sendCompletionGetSuggestions(priorityFile, offset); |
73 | 78 |
74 await analysisFinished; | 79 await analysisFinished; |
75 | 80 |
76 print('analysis completed in ${stopwatch.elapsed}'); | 81 print('analysis completed in ${stopwatch.elapsed}'); |
77 print('completion received at : $timings'); | 82 print('completion received at : $timings'); |
78 await shutdown(); | 83 await shutdown(); |
79 } | 84 } |
80 } | 85 } |
OLD | NEW |