OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, 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 import 'dart:async'; |
| 6 import 'dart:io'; |
| 7 |
| 8 import 'package:analysis_server/src/protocol_server.dart'; |
| 9 import 'package:path/path.dart' as path; |
| 10 |
| 11 import '../../test/integration/support/integration_tests.dart'; |
| 12 import '../benchmarks.dart'; |
| 13 import 'memory_tests.dart'; |
| 14 |
| 15 /// benchmarks: |
| 16 /// - analysis-server-cold-analysis |
| 17 /// - analysis-server-cold-memory |
| 18 class ColdAnalysisBenchmark extends Benchmark { |
| 19 ColdAnalysisBenchmark() |
| 20 : super( |
| 21 'analysis-server-cold', |
| 22 'Analysis server benchmarks of a large project on start-up, no ' |
| 23 'existing driver cache.', |
| 24 ); |
| 25 |
| 26 int get maxIterations => 3; |
| 27 |
| 28 @override |
| 29 Future<BenchMarkResult> run({bool quick: false}) async { |
| 30 deleteServerCache(); |
| 31 |
| 32 Stopwatch stopwatch = new Stopwatch()..start(); |
| 33 |
| 34 AnalysisServerMemoryUsageTest test = new AnalysisServerMemoryUsageTest(); |
| 35 await test.setUp(); |
| 36 await test.subscribeToStatusNotifications(); |
| 37 await test.sendAnalysisSetAnalysisRoots(getProjectRoots(quick: quick), []); |
| 38 await test.analysisFinished; |
| 39 |
| 40 stopwatch.stop(); |
| 41 int usedBytes = test.getMemoryUsage(); |
| 42 |
| 43 CompoundBenchMarkResult result = new CompoundBenchMarkResult(id); |
| 44 result.add('analysis', |
| 45 new BenchMarkResult('micros', stopwatch.elapsedMicroseconds)); |
| 46 result.add('memory', new BenchMarkResult('bytes', usedBytes)); |
| 47 |
| 48 await test.shutdown(); |
| 49 |
| 50 return result; |
| 51 } |
| 52 } |
| 53 |
| 54 /// benchmarks: |
| 55 /// - analysis-server-warm-analysis |
| 56 /// - analysis-server-warm-memory |
| 57 /// - analysis-server-edit |
| 58 /// - analysis-server-completion |
| 59 class AnalysisBenchmark extends Benchmark { |
| 60 AnalysisBenchmark() |
| 61 : super( |
| 62 'analysis-server', |
| 63 'Analysis server benchmarks of a large project, with an existing ' |
| 64 'driver cache.', |
| 65 ); |
| 66 |
| 67 @override |
| 68 Future<BenchMarkResult> run({bool quick: false}) async { |
| 69 Stopwatch stopwatch = new Stopwatch()..start(); |
| 70 |
| 71 AnalysisServerMemoryUsageTest test = new AnalysisServerMemoryUsageTest(); |
| 72 await test.setUp(); |
| 73 await test.subscribeToStatusNotifications(); |
| 74 await test.sendAnalysisSetAnalysisRoots(getProjectRoots(quick: quick), []); |
| 75 await test.analysisFinished; |
| 76 |
| 77 stopwatch.stop(); |
| 78 int usedBytes = test.getMemoryUsage(); |
| 79 |
| 80 CompoundBenchMarkResult result = new CompoundBenchMarkResult(id); |
| 81 result.add('warm-analysis', |
| 82 new BenchMarkResult('micros', stopwatch.elapsedMicroseconds)); |
| 83 result.add('warm-memory', new BenchMarkResult('bytes', usedBytes)); |
| 84 |
| 85 if (!quick) { |
| 86 // change timing |
| 87 final int editMicros = await _calcEditTiming(test); |
| 88 result.add('edit', new BenchMarkResult('micros', editMicros)); |
| 89 |
| 90 // code completion |
| 91 final int completionMicros = await _calcCompletionTiming(test); |
| 92 result.add('completion', new BenchMarkResult('micros', completionMicros)); |
| 93 } |
| 94 |
| 95 await test.shutdown(); |
| 96 |
| 97 return result; |
| 98 } |
| 99 |
| 100 Future<int> _calcEditTiming( |
| 101 AbstractAnalysisServerIntegrationTest test) async { |
| 102 const int kGroupCount = 5; |
| 103 |
| 104 final String filePath = |
| 105 path.join(analysisServerSrcPath, 'lib/src/analysis_server.dart'); |
| 106 String contents = new File(filePath).readAsStringSync(); |
| 107 |
| 108 await test |
| 109 .sendAnalysisUpdateContent({filePath: new AddContentOverlay(contents)}); |
| 110 |
| 111 final Stopwatch stopwatch = new Stopwatch()..start(); |
| 112 |
| 113 for (int i = 0; i < kGroupCount; i++) { |
| 114 int startIndex = i * (contents.length ~/ (kGroupCount + 2)); |
| 115 int index = contents.indexOf(';', startIndex); |
| 116 contents = contents.substring(0, index + 1) + |
| 117 ' ' + |
| 118 contents.substring(index + 1); |
| 119 test.sendAnalysisUpdateContent( |
| 120 {filePath: new AddContentOverlay(contents)}); |
| 121 await test.analysisFinished; |
| 122 } |
| 123 |
| 124 stopwatch.stop(); |
| 125 |
| 126 return stopwatch.elapsedMicroseconds ~/ kGroupCount; |
| 127 } |
| 128 |
| 129 Future<int> _calcCompletionTiming( |
| 130 AbstractAnalysisServerIntegrationTest test) async { |
| 131 const int kGroupCount = 10; |
| 132 |
| 133 final String filePath = |
| 134 path.join(analysisServerSrcPath, 'lib/src/analysis_server.dart'); |
| 135 String contents = new File(filePath).readAsStringSync(); |
| 136 |
| 137 await test |
| 138 .sendAnalysisUpdateContent({filePath: new AddContentOverlay(contents)}); |
| 139 |
| 140 int completionCount = 0; |
| 141 final Stopwatch stopwatch = new Stopwatch()..start(); |
| 142 |
| 143 Future _complete(int offset) async { |
| 144 CompletionGetSuggestionsResult result = |
| 145 await test.sendCompletionGetSuggestions(filePath, offset); |
| 146 |
| 147 Future<CompletionResultsParams> future = test.onCompletionResults |
| 148 .where((CompletionResultsParams params) => |
| 149 params.id == result.id && params.isLast) |
| 150 .first; |
| 151 await future; |
| 152 |
| 153 completionCount++; |
| 154 } |
| 155 |
| 156 for (int i = 0; i < kGroupCount; i++) { |
| 157 int startIndex = i * (contents.length ~/ (kGroupCount + 2)); |
| 158 // Look for a line with a period in it that ends with a semi-colon. |
| 159 int index = |
| 160 contents.indexOf(new RegExp(r'\..*;$', multiLine: true), startIndex); |
| 161 |
| 162 await _complete(index - 10); |
| 163 await _complete(index - 1); |
| 164 await _complete(index); |
| 165 await _complete(index + 1); |
| 166 await _complete(index + 10); |
| 167 |
| 168 if (i + 1 < kGroupCount) { |
| 169 // mutate |
| 170 index = contents.indexOf(';', index); |
| 171 contents = contents.substring(0, index + 1) + |
| 172 ' ' + |
| 173 contents.substring(index + 1); |
| 174 await test.sendAnalysisUpdateContent( |
| 175 {filePath: new AddContentOverlay(contents)}); |
| 176 } |
| 177 } |
| 178 |
| 179 stopwatch.stop(); |
| 180 |
| 181 return stopwatch.elapsedMicroseconds ~/ completionCount; |
| 182 } |
| 183 } |
OLD | NEW |