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

Side by Side Diff: pkg/analysis_server/lib/src/operation/operation_analysis.dart

Issue 1081903002: Use working cache size when request resolved units in requests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 operation.analysis; 5 library operation.analysis;
6 6
7 import 'package:analysis_server/src/analysis_server.dart'; 7 import 'package:analysis_server/src/analysis_server.dart';
8 import 'package:analysis_server/src/computer/computer_highlights.dart'; 8 import 'package:analysis_server/src/computer/computer_highlights.dart';
9 import 'package:analysis_server/src/computer/computer_navigation.dart'; 9 import 'package:analysis_server/src/computer/computer_navigation.dart';
10 import 'package:analysis_server/src/computer/computer_occurrences.dart'; 10 import 'package:analysis_server/src/computer/computer_occurrences.dart';
11 import 'package:analysis_server/src/computer/computer_outline.dart'; 11 import 'package:analysis_server/src/computer/computer_outline.dart';
12 import 'package:analysis_server/src/computer/computer_overrides.dart'; 12 import 'package:analysis_server/src/computer/computer_overrides.dart';
13 import 'package:analysis_server/src/operation/operation.dart'; 13 import 'package:analysis_server/src/operation/operation.dart';
14 import 'package:analysis_server/src/protocol_server.dart' as protocol; 14 import 'package:analysis_server/src/protocol_server.dart' as protocol;
15 import 'package:analysis_server/src/services/index/index.dart'; 15 import 'package:analysis_server/src/services/index/index.dart';
16 import 'package:analyzer/src/generated/ast.dart'; 16 import 'package:analyzer/src/generated/ast.dart';
17 import 'package:analyzer/src/generated/engine.dart'; 17 import 'package:analyzer/src/generated/engine.dart';
18 import 'package:analyzer/src/generated/error.dart'; 18 import 'package:analyzer/src/generated/error.dart';
19 import 'package:analyzer/src/generated/html.dart'; 19 import 'package:analyzer/src/generated/html.dart';
20 import 'package:analyzer/src/generated/source.dart'; 20 import 'package:analyzer/src/generated/source.dart';
21 21
22 /** 22 /**
23 * Runs the given function [f] with the working cache size in [context].
24 * Returns the result of [f] invocation.
25 */
26 runWithWorkingCacheSize(AnalysisContext context, f()) {
27 int currentCacheSize = context.analysisOptions.cacheSize;
28 if (currentCacheSize < PerformAnalysisOperation.WORKING_CACHE_SIZE) {
29 setCacheSize(context, PerformAnalysisOperation.WORKING_CACHE_SIZE);
30 try {
31 return f();
32 } finally {
33 setCacheSize(context, currentCacheSize);
34 }
35 } else {
36 return f();
37 }
38 }
39
40 /**
23 * Schedules indexing of the given [file] using the resolved [dartUnit]. 41 * Schedules indexing of the given [file] using the resolved [dartUnit].
24 */ 42 */
25 void scheduleIndexOperation(AnalysisServer server, String file, 43 void scheduleIndexOperation(AnalysisServer server, String file,
26 AnalysisContext context, CompilationUnit dartUnit) { 44 AnalysisContext context, CompilationUnit dartUnit) {
27 if (server.index != null) { 45 if (server.index != null) {
28 server.addOperation(new _DartIndexOperation(context, file, dartUnit)); 46 server.addOperation(new _DartIndexOperation(context, file, dartUnit));
29 } 47 }
30 } 48 }
31 49
32 /** 50 /**
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 void sendAnalysisNotificationOverrides( 163 void sendAnalysisNotificationOverrides(
146 AnalysisServer server, String file, CompilationUnit dartUnit) { 164 AnalysisServer server, String file, CompilationUnit dartUnit) {
147 _sendNotification(server, () { 165 _sendNotification(server, () {
148 var overrides = new DartUnitOverridesComputer(dartUnit).compute(); 166 var overrides = new DartUnitOverridesComputer(dartUnit).compute();
149 var params = new protocol.AnalysisOverridesParams(file, overrides); 167 var params = new protocol.AnalysisOverridesParams(file, overrides);
150 server.sendNotification(params.toNotification()); 168 server.sendNotification(params.toNotification());
151 }); 169 });
152 } 170 }
153 171
154 /** 172 /**
173 * Sets the cache size in the given [context] to the given value.
174 */
175 void setCacheSize(AnalysisContext context, int cacheSize) {
176 AnalysisOptionsImpl options =
177 new AnalysisOptionsImpl.con1(context.analysisOptions);
178 options.cacheSize = cacheSize;
179 context.analysisOptions = options;
180 }
181
182 /**
155 * Runs the given notification producing function [f], catching exceptions. 183 * Runs the given notification producing function [f], catching exceptions.
156 */ 184 */
157 void _sendNotification(AnalysisServer server, f()) { 185 void _sendNotification(AnalysisServer server, f()) {
158 ServerPerformanceStatistics.notices.makeCurrentWhile(() { 186 ServerPerformanceStatistics.notices.makeCurrentWhile(() {
159 try { 187 try {
160 f(); 188 f();
161 } catch (exception, stackTrace) { 189 } catch (exception, stackTrace) {
162 server.sendServerErrorNotification(exception, stackTrace); 190 server.sendServerErrorNotification(exception, stackTrace);
163 } 191 }
164 }); 192 });
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 void perform(AnalysisServer server) { 228 void perform(AnalysisServer server) {
201 // 229 //
202 // TODO(brianwilkerson) Add an optional function-valued parameter to 230 // TODO(brianwilkerson) Add an optional function-valued parameter to
203 // performAnalysisTask that will be called when the task has been computed 231 // performAnalysisTask that will be called when the task has been computed
204 // but before it is performed and send notification in the function: 232 // but before it is performed and send notification in the function:
205 // 233 //
206 // AnalysisResult result = context.performAnalysisTask((taskDescription) { 234 // AnalysisResult result = context.performAnalysisTask((taskDescription) {
207 // sendStatusNotification(context.toString(), taskDescription); 235 // sendStatusNotification(context.toString(), taskDescription);
208 // }); 236 // });
209 if (!isContinue) { 237 if (!isContinue) {
210 _setCacheSize(WORKING_CACHE_SIZE); 238 setCacheSize(context, WORKING_CACHE_SIZE);
211 } 239 }
212 // prepare results 240 // prepare results
213 AnalysisResult result = context.performAnalysisTask(); 241 AnalysisResult result = context.performAnalysisTask();
214 List<ChangeNotice> notices = result.changeNotices; 242 List<ChangeNotice> notices = result.changeNotices;
215 if (notices == null) { 243 if (notices == null) {
216 _setCacheSize(IDLE_CACHE_SIZE); 244 setCacheSize(context, IDLE_CACHE_SIZE);
217 server.sendContextAnalysisDoneNotifications( 245 server.sendContextAnalysisDoneNotifications(
218 context, AnalysisDoneReason.COMPLETE); 246 context, AnalysisDoneReason.COMPLETE);
219 return; 247 return;
220 } 248 }
221 // process results 249 // process results
222 ServerPerformanceStatistics.notices.makeCurrentWhile(() { 250 ServerPerformanceStatistics.notices.makeCurrentWhile(() {
223 _sendNotices(server, notices); 251 _sendNotices(server, notices);
224 _updateIndex(server, notices); 252 _updateIndex(server, notices);
225 }); 253 });
226 // continue analysis 254 // continue analysis
(...skipping 11 matching lines...) Expand all
238 // Dart 266 // Dart
239 CompilationUnit parsedDartUnit = notice.parsedDartUnit; 267 CompilationUnit parsedDartUnit = notice.parsedDartUnit;
240 CompilationUnit resolvedDartUnit = notice.resolvedDartUnit; 268 CompilationUnit resolvedDartUnit = notice.resolvedDartUnit;
241 scheduleNotificationOperations(server, file, notice.lineInfo, context, 269 scheduleNotificationOperations(server, file, notice.lineInfo, context,
242 parsedDartUnit, resolvedDartUnit, notice.errors); 270 parsedDartUnit, resolvedDartUnit, notice.errors);
243 // done 271 // done
244 server.fileAnalyzed(notice); 272 server.fileAnalyzed(notice);
245 } 273 }
246 } 274 }
247 275
248 void _setCacheSize(int cacheSize) {
249 AnalysisOptionsImpl options =
250 new AnalysisOptionsImpl.con1(context.analysisOptions);
251 options.cacheSize = cacheSize;
252 context.analysisOptions = options;
253 }
254
255 void _updateIndex(AnalysisServer server, List<ChangeNotice> notices) { 276 void _updateIndex(AnalysisServer server, List<ChangeNotice> notices) {
256 if (server.index == null) { 277 if (server.index == null) {
257 return; 278 return;
258 } 279 }
259 for (ChangeNotice notice in notices) { 280 for (ChangeNotice notice in notices) {
260 String file = notice.source.fullName; 281 String file = notice.source.fullName;
261 // Dart 282 // Dart
262 try { 283 try {
263 CompilationUnit dartUnit = notice.resolvedDartUnit; 284 CompilationUnit dartUnit = notice.resolvedDartUnit;
264 if (dartUnit != null) { 285 if (dartUnit != null) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 abstract class _SingleFileOperation extends SourceSensitiveOperation { 430 abstract class _SingleFileOperation extends SourceSensitiveOperation {
410 final String file; 431 final String file;
411 432
412 _SingleFileOperation(AnalysisContext context, this.file) : super(context); 433 _SingleFileOperation(AnalysisContext context, this.file) : super(context);
413 434
414 @override 435 @override
415 bool shouldBeDiscardedOnSourceChange(Source source) { 436 bool shouldBeDiscardedOnSourceChange(Source source) {
416 return source.fullName == file; 437 return source.fullName == file;
417 } 438 }
418 } 439 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698