Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: pkg/analysis_server/benchmark/perf/benchmark_scenario.dart

Issue 2087763002: New scenario and local benchmark - refactoring after change. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analysis_server/benchmark/perf/benchmark_local.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 9
10 import 'package:analysis_server/plugin/protocol/protocol.dart'; 10 import 'package:analysis_server/plugin/protocol/protocol.dart';
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // Remove the overlay and analyze. 118 // Remove the overlay and analyze.
119 await sendAnalysisUpdateContent({file: new RemoveContentOverlay()}); 119 await sendAnalysisUpdateContent({file: new RemoveContentOverlay()});
120 await analysisFinished; 120 await analysisFinished;
121 } 121 }
122 // Done. 122 // Done.
123 await shutdown(); 123 await shutdown();
124 return times; 124 return times;
125 } 125 }
126 126
127 /** 127 /**
128 * Init.
129 * 1. Start Analysis Server.
130 * 2. Set the analysis [roots].
131 * 3. Wait for analysis to complete.
132 * 4. Make [file] the priority file.
133 *
134 * Measurement.
135 * 5. Change the [file] according to the [fileChange].
136 * 6. Request [refactoringAtStr] in the updated file content.
137 * 7. Record the time to get refactoring.
138 * 8. Undo changes to the [file] and analyze.
139 * 9. Go to (5).
140 */
141 Future<List<int>> waitAnalyze_change_getRefactoring(
142 {List<String> roots,
143 String file,
144 FileChange fileChange,
145 String refactoringAtStr,
146 RefactoringKind refactoringKind,
147 RefactoringOptions refactoringOptions,
148 int numOfRepeats}) async {
149 expect(roots, isNotNull, reason: 'roots');
150 expect(file, isNotNull, reason: 'file');
151 expect(fileChange, isNotNull, reason: 'fileChange');
152 expect(refactoringAtStr, isNotNull, reason: 'refactoringAtStr');
153 expect(refactoringKind, isNotNull, reason: 'refactoringKind');
154 expect(refactoringOptions, isNotNull, reason: 'refactoringOptions');
155 expect(numOfRepeats, isNotNull, reason: 'numOfRepeats');
156 // Initialize Analysis Server.
157 await super.setUp();
158 await subscribeToStatusNotifications();
159 // Set roots and analyze.
160 await sendAnalysisSetAnalysisRoots(roots, []);
161 await analysisFinished;
162 // Make the file priority.
163 await sendAnalysisSetPriorityFiles([file]);
164 // Repeat.
165 List<int> times = <int>[];
166 for (int i = 0; i < numOfRepeats; i++) {
167 String updatedContent = await _applyFileChange(file, fileChange);
168 // Measure time to get refactoring.
169 int refactoringOffset = _indexOf(file, updatedContent, refactoringAtStr);
170 Duration refactoringDuration = await _measureRefactoringTime(
171 file, refactoringOffset, refactoringKind, refactoringOptions);
172 times.add(refactoringDuration.inMilliseconds);
173 // Remove the overlay and analyze.
174 await sendAnalysisUpdateContent({file: new RemoveContentOverlay()});
175 await analysisFinished;
176 }
177 // Done.
178 await shutdown();
179 return times;
180 }
181
182 /**
128 * Compute updated content of the [file] as described by [desc], add overlay 183 * Compute updated content of the [file] as described by [desc], add overlay
129 * for the [file], and return the updated content. 184 * for the [file], and return the updated content.
130 */ 185 */
131 Future<String> _applyFileChange(String file, FileChange desc) async { 186 Future<String> _applyFileChange(String file, FileChange desc) async {
132 String originalContent = _getFileContent(file); 187 String originalContent = _getFileContent(file);
133 int offset = _indexOfEnd(file, originalContent, desc.afterStr); 188 int offset = _indexOfEnd(file, originalContent, desc.afterStr);
134 offset -= desc.afterStrBack; 189 offset -= desc.afterStrBack;
135 String updatedContent = originalContent.substring(0, offset) + 190 String updatedContent = originalContent.substring(0, offset) +
136 desc.insertStr + 191 desc.insertStr +
137 originalContent.substring(offset); 192 originalContent.substring(offset);
(...skipping 10 matching lines...) Expand all
148 completer.complete(stopwatch.elapsed); 203 completer.complete(stopwatch.elapsed);
149 }); 204 });
150 try { 205 try {
151 await sendCompletionGetSuggestions(file, offset); 206 await sendCompletionGetSuggestions(file, offset);
152 return await completer.future; 207 return await completer.future;
153 } finally { 208 } finally {
154 completionSubscription.cancel(); 209 completionSubscription.cancel();
155 } 210 }
156 } 211 }
157 212
213 Future<Duration> _measureRefactoringTime(
214 String file,
215 int offset,
216 RefactoringKind refactoringKind,
217 RefactoringOptions refactoringOptions) async {
218 Stopwatch stopwatch = new Stopwatch();
219 stopwatch.start();
220 await sendEditGetRefactoring(refactoringKind, file, offset, 0, false,
221 options: refactoringOptions);
222 return stopwatch.elapsed;
223 }
224
158 /** 225 /**
159 * 1. Start Analysis Server. 226 * 1. Start Analysis Server.
160 * 2. Set the analysis [roots]. 227 * 2. Set the analysis [roots].
161 * 3. Wait for analysis to complete. 228 * 3. Wait for analysis to complete.
162 * 4. Record the time to finish analysis. 229 * 4. Record the time to finish analysis.
163 * 5. Shutdown. 230 * 5. Shutdown.
164 * 6. Go to (1). 231 * 6. Go to (1).
165 */ 232 */
166 static Future<List<int>> start_waitInitialAnalysis_shutdown( 233 static Future<List<int>> start_waitInitialAnalysis_shutdown(
167 {List<String> roots, int numOfRepeats}) async { 234 {List<String> roots, int numOfRepeats}) async {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 class FileChange { 278 class FileChange {
212 final String afterStr; 279 final String afterStr;
213 final int afterStrBack; 280 final int afterStrBack;
214 final String insertStr; 281 final String insertStr;
215 282
216 FileChange({this.afterStr, this.afterStrBack: 0, this.insertStr}) { 283 FileChange({this.afterStr, this.afterStrBack: 0, this.insertStr}) {
217 expect(afterStr, isNotNull, reason: 'afterStr'); 284 expect(afterStr, isNotNull, reason: 'afterStr');
218 expect(insertStr, isNotNull, reason: 'insertStr'); 285 expect(insertStr, isNotNull, reason: 'insertStr');
219 } 286 }
220 } 287 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/benchmark/perf/benchmark_local.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698