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

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

Issue 2297343002: Flush results when contexts are made idle. (Closed)
Patch Set: Un-fail completion tests. Created 4 years, 3 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
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_highlights2.dart'; 9 import 'package:analysis_server/src/computer/computer_highlights2.dart';
10 import 'package:analysis_server/src/computer/computer_outline.dart'; 10 import 'package:analysis_server/src/computer/computer_outline.dart';
11 import 'package:analysis_server/src/computer/computer_overrides.dart'; 11 import 'package:analysis_server/src/computer/computer_overrides.dart';
12 import 'package:analysis_server/src/domains/analysis/implemented_dart.dart'; 12 import 'package:analysis_server/src/domains/analysis/implemented_dart.dart';
13 import 'package:analysis_server/src/domains/analysis/navigation.dart'; 13 import 'package:analysis_server/src/domains/analysis/navigation.dart';
14 import 'package:analysis_server/src/domains/analysis/occurrences.dart'; 14 import 'package:analysis_server/src/domains/analysis/occurrences.dart';
15 import 'package:analysis_server/src/operation/operation.dart'; 15 import 'package:analysis_server/src/operation/operation.dart';
16 import 'package:analysis_server/src/protocol_server.dart' as protocol; 16 import 'package:analysis_server/src/protocol_server.dart' as protocol;
17 import 'package:analysis_server/src/services/dependencies/library_dependencies.d art'; 17 import 'package:analysis_server/src/services/dependencies/library_dependencies.d art';
18 import 'package:analysis_server/src/services/search/search_engine.dart'; 18 import 'package:analysis_server/src/services/search/search_engine.dart';
19 import 'package:analyzer/dart/ast/ast.dart'; 19 import 'package:analyzer/dart/ast/ast.dart';
20 import 'package:analyzer/dart/element/element.dart'; 20 import 'package:analyzer/dart/element/element.dart';
21 import 'package:analyzer/src/generated/engine.dart'; 21 import 'package:analyzer/src/generated/engine.dart';
22 import 'package:analyzer/src/generated/error.dart'; 22 import 'package:analyzer/src/generated/error.dart';
23 import 'package:analyzer/src/generated/source.dart'; 23 import 'package:analyzer/src/generated/source.dart';
24 24
25 /** 25 /**
26 * Runs the given function [f] with the working cache size in [context]. 26 * Run the given function [f] with the given [context] made active.
27 * Returns the result of [f] invocation. 27 * Return the result of [f] invocation.
28 */ 28 */
29 runWithWorkingCacheSize(AnalysisContext context, f()) { 29 runWithActiveContext(AnalysisContext context, f()) {
30 int currentCacheSize = context.analysisOptions.cacheSize; 30 if (context is InternalAnalysisContext && !context.isActive) {
31 if (currentCacheSize < PerformAnalysisOperation.WORKING_CACHE_SIZE) { 31 context.isActive = true;
32 setCacheSize(context, PerformAnalysisOperation.WORKING_CACHE_SIZE);
33 try { 32 try {
34 return f(); 33 return f();
35 } finally { 34 } finally {
36 setCacheSize(context, currentCacheSize); 35 context.isActive = false;
37 } 36 }
38 } else { 37 } else {
39 return f(); 38 f();
40 } 39 }
41 } 40 }
42 41
43 scheduleImplementedNotification( 42 scheduleImplementedNotification(
44 AnalysisServer server, Iterable<String> files) async { 43 AnalysisServer server, Iterable<String> files) async {
45 SearchEngine searchEngine = server.searchEngine; 44 SearchEngine searchEngine = server.searchEngine;
46 if (searchEngine == null) { 45 if (searchEngine == null) {
47 return; 46 return;
48 } 47 }
49 for (String file in files) { 48 for (String file in files) {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 237
239 void sendAnalysisNotificationOverrides( 238 void sendAnalysisNotificationOverrides(
240 AnalysisServer server, String file, CompilationUnit dartUnit) { 239 AnalysisServer server, String file, CompilationUnit dartUnit) {
241 _sendNotification(server, () { 240 _sendNotification(server, () {
242 var overrides = new DartUnitOverridesComputer(dartUnit).compute(); 241 var overrides = new DartUnitOverridesComputer(dartUnit).compute();
243 var params = new protocol.AnalysisOverridesParams(file, overrides); 242 var params = new protocol.AnalysisOverridesParams(file, overrides);
244 server.sendNotification(params.toNotification()); 243 server.sendNotification(params.toNotification());
245 }); 244 });
246 } 245 }
247 246
248 /**
249 * Sets the cache size in the given [context] to the given value.
250 */
251 void setCacheSize(AnalysisContext context, int cacheSize) {
252 // TODO(scheglov) The cache size cannot be changed with task model.
253 // TODO(scheglov) Consider removing this function.
254 // AnalysisOptionsImpl options =
255 // new AnalysisOptionsImpl.from(context.analysisOptions);
256 // options.cacheSize = cacheSize;
257 // context.analysisOptions = options;
258 }
259
260 String _computeLibraryName(CompilationUnit unit) { 247 String _computeLibraryName(CompilationUnit unit) {
261 for (Directive directive in unit.directives) { 248 for (Directive directive in unit.directives) {
262 if (directive is LibraryDirective && directive.name != null) { 249 if (directive is LibraryDirective && directive.name != null) {
263 return directive.name.name; 250 return directive.name.name;
264 } 251 }
265 } 252 }
266 for (Directive directive in unit.directives) { 253 for (Directive directive in unit.directives) {
267 if (directive is PartOfDirective && directive.libraryName != null) { 254 if (directive is PartOfDirective && directive.libraryName != null) {
268 return directive.libraryName.name; 255 return directive.libraryName.name;
269 } 256 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 @override 305 @override
319 void perform(AnalysisServer server) { 306 void perform(AnalysisServer server) {
320 sendAnalysisNotificationOccurrences(server, context, source); 307 sendAnalysisNotificationOccurrences(server, context, source);
321 } 308 }
322 } 309 }
323 310
324 /** 311 /**
325 * Instances of [PerformAnalysisOperation] perform a single analysis task. 312 * Instances of [PerformAnalysisOperation] perform a single analysis task.
326 */ 313 */
327 class PerformAnalysisOperation extends ServerOperation { 314 class PerformAnalysisOperation extends ServerOperation {
328 static const int IDLE_CACHE_SIZE = AnalysisOptionsImpl.DEFAULT_CACHE_SIZE;
329 static const int WORKING_CACHE_SIZE = 512;
330
331 final bool isContinue; 315 final bool isContinue;
332 316
333 PerformAnalysisOperation(AnalysisContext context, this.isContinue) 317 PerformAnalysisOperation(AnalysisContext context, this.isContinue)
334 : super(context); 318 : super(context);
335 319
336 @override 320 @override
337 ServerOperationPriority get priority { 321 ServerOperationPriority get priority {
338 if (_isPriorityContext) { 322 if (_isPriorityContext) {
339 if (isContinue) { 323 if (isContinue) {
340 return ServerOperationPriority.PRIORITY_ANALYSIS_CONTINUE; 324 return ServerOperationPriority.PRIORITY_ANALYSIS_CONTINUE;
(...skipping 17 matching lines...) Expand all
358 void perform(AnalysisServer server) { 342 void perform(AnalysisServer server) {
359 // 343 //
360 // TODO(brianwilkerson) Add an optional function-valued parameter to 344 // TODO(brianwilkerson) Add an optional function-valued parameter to
361 // performAnalysisTask that will be called when the task has been computed 345 // performAnalysisTask that will be called when the task has been computed
362 // but before it is performed and send notification in the function: 346 // but before it is performed and send notification in the function:
363 // 347 //
364 // AnalysisResult result = context.performAnalysisTask((taskDescription) { 348 // AnalysisResult result = context.performAnalysisTask((taskDescription) {
365 // sendStatusNotification(context.toString(), taskDescription); 349 // sendStatusNotification(context.toString(), taskDescription);
366 // }); 350 // });
367 if (!isContinue) { 351 if (!isContinue) {
368 setCacheSize(context, WORKING_CACHE_SIZE); 352 _setContextActive(true);
369 } 353 }
370 // prepare results 354 // prepare results
371 AnalysisResult result = context.performAnalysisTask(); 355 AnalysisResult result = context.performAnalysisTask();
372 List<ChangeNotice> notices = result.changeNotices; 356 List<ChangeNotice> notices = result.changeNotices;
373 // nothing to analyze 357 // nothing to analyze
374 if (notices == null) { 358 if (notices == null) {
375 server.scheduleCacheConsistencyValidation(context); 359 server.scheduleCacheConsistencyValidation(context);
376 setCacheSize(context, IDLE_CACHE_SIZE); 360 _setContextActive(false);
377 server.sendContextAnalysisDoneNotifications( 361 server.sendContextAnalysisDoneNotifications(
378 context, AnalysisDoneReason.COMPLETE); 362 context, AnalysisDoneReason.COMPLETE);
379 return; 363 return;
380 } 364 }
381 // process results 365 // process results
382 ServerPerformanceStatistics.notices.makeCurrentWhile(() { 366 ServerPerformanceStatistics.notices.makeCurrentWhile(() {
383 _sendNotices(server, notices); 367 _sendNotices(server, notices);
384 _updateIndex(server, notices); 368 _updateIndex(server, notices);
385 }); 369 });
386 // continue analysis 370 // continue analysis
(...skipping 11 matching lines...) Expand all
398 // Dart 382 // Dart
399 CompilationUnit parsedDartUnit = notice.parsedDartUnit; 383 CompilationUnit parsedDartUnit = notice.parsedDartUnit;
400 CompilationUnit resolvedDartUnit = notice.resolvedDartUnit; 384 CompilationUnit resolvedDartUnit = notice.resolvedDartUnit;
401 scheduleNotificationOperations(server, source, file, notice.lineInfo, 385 scheduleNotificationOperations(server, source, file, notice.lineInfo,
402 context, parsedDartUnit, resolvedDartUnit, notice.errors); 386 context, parsedDartUnit, resolvedDartUnit, notice.errors);
403 // done 387 // done
404 server.fileAnalyzed(notice); 388 server.fileAnalyzed(notice);
405 } 389 }
406 } 390 }
407 391
392 /**
393 * Make the [context] active or idle.
394 */
395 void _setContextActive(bool active) {
396 AnalysisContext context = this.context;
397 if (context is InternalAnalysisContext) {
398 context.isActive = active;
399 }
400 }
401
408 void _updateIndex(AnalysisServer server, List<ChangeNotice> notices) { 402 void _updateIndex(AnalysisServer server, List<ChangeNotice> notices) {
409 if (server.index == null) { 403 if (server.index == null) {
410 return; 404 return;
411 } 405 }
412 for (ChangeNotice notice in notices) { 406 for (ChangeNotice notice in notices) {
413 String file = notice.source.fullName; 407 String file = notice.source.fullName;
414 // Dart 408 // Dart
415 try { 409 try {
416 CompilationUnit dartUnit = notice.resolvedDartUnit; 410 CompilationUnit dartUnit = notice.resolvedDartUnit;
417 if (dartUnit != null) { 411 if (dartUnit != null) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 abstract class _SingleFileOperation extends SourceSensitiveOperation { 529 abstract class _SingleFileOperation extends SourceSensitiveOperation {
536 final String file; 530 final String file;
537 531
538 _SingleFileOperation(AnalysisContext context, this.file) : super(context); 532 _SingleFileOperation(AnalysisContext context, this.file) : super(context);
539 533
540 @override 534 @override
541 bool shouldBeDiscardedOnSourceChange(Source source) { 535 bool shouldBeDiscardedOnSourceChange(Source source) {
542 return source.fullName == file; 536 return source.fullName == file;
543 } 537 }
544 } 538 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | pkg/analyzer/lib/src/context/cache.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698