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

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart

Issue 691853006: display completion performance in new server status page (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 1 month 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
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 test.services.completion.dart; 5 library test.services.completion.dart;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_server/src/services/completion/arglist_computer.dart';
10 import 'package:analysis_server/src/services/completion/combinator_computer.dart '; 11 import 'package:analysis_server/src/services/completion/combinator_computer.dart ';
11 import 'package:analysis_server/src/services/completion/completion_manager.dart' ; 12 import 'package:analysis_server/src/services/completion/completion_manager.dart' ;
12 import 'package:analysis_server/src/services/completion/imported_computer.dart'; 13 import 'package:analysis_server/src/services/completion/imported_computer.dart';
13 import 'package:analysis_server/src/services/completion/invocation_computer.dart '; 14 import 'package:analysis_server/src/services/completion/invocation_computer.dart ';
14 import 'package:analysis_server/src/services/completion/keyword_computer.dart'; 15 import 'package:analysis_server/src/services/completion/keyword_computer.dart';
15 import 'package:analysis_server/src/services/completion/local_computer.dart'; 16 import 'package:analysis_server/src/services/completion/local_computer.dart';
16 import 'package:analysis_server/src/services/search/search_engine.dart'; 17 import 'package:analysis_server/src/services/search/search_engine.dart';
17 import 'package:analyzer/src/generated/ast.dart'; 18 import 'package:analyzer/src/generated/ast.dart';
18 import 'package:analyzer/src/generated/element.dart'; 19 import 'package:analyzer/src/generated/element.dart';
19 import 'package:analyzer/src/generated/engine.dart'; 20 import 'package:analyzer/src/generated/engine.dart';
(...skipping 22 matching lines...) Expand all
42 Future<bool> computeFull(DartCompletionRequest request); 43 Future<bool> computeFull(DartCompletionRequest request);
43 } 44 }
44 45
45 /** 46 /**
46 * Manages code completion for a given Dart file completion request. 47 * Manages code completion for a given Dart file completion request.
47 */ 48 */
48 class DartCompletionManager extends CompletionManager { 49 class DartCompletionManager extends CompletionManager {
49 final AnalysisContext context; 50 final AnalysisContext context;
50 final Source source; 51 final Source source;
51 final int offset; 52 final int offset;
53 final CompletionPerformance performance;
52 DartCompletionRequest request; 54 DartCompletionRequest request;
53 List<DartCompletionComputer> computers; 55 List<DartCompletionComputer> computers;
54 56
55 DartCompletionManager(this.context, SearchEngine searchEngine, this.source, 57 DartCompletionManager(this.context, SearchEngine searchEngine, this.source,
56 this.offset) { 58 this.offset, this.performance) {
57 request = new DartCompletionRequest(context, searchEngine, source, offset); 59 request = new DartCompletionRequest(context, searchEngine, source, offset);
58 } 60 }
59 61
60 @override 62 @override
61 void compute() { 63 void compute() {
62 initComputers(); 64 performance.logElapseTime('compute', () {
63 computeFast(); 65 initComputers();
64 if (!computers.isEmpty) { 66 computeFast();
65 computeFull(); 67 if (!computers.isEmpty) {
66 } 68 computeFull();
69 }
70 });
67 } 71 }
68 72
69 /** 73 /**
70 * Compute suggestions based upon cached information only 74 * Compute suggestions based upon cached information only
71 * then send an initial response to the client. 75 * then send an initial response to the client.
72 */ 76 */
73 void computeFast() { 77 void computeFast() {
74 CompilationUnit unit = context.parseCompilationUnit(source); 78 performance.logElapseTime('computeFast', () {
75 request.unit = unit; 79 CompilationUnit unit = context.parseCompilationUnit(source);
76 request.node = new NodeLocator.con1(offset).searchWithin(unit); 80 request.unit = unit;
77 request.node.accept(new _ReplacementOffsetBuilder(request)); 81 request.node = new NodeLocator.con1(offset).searchWithin(unit);
78 computers.removeWhere((DartCompletionComputer c) => c.computeFast(request)); 82 request.node.accept(new _ReplacementOffsetBuilder(request));
79 sendResults(computers.isEmpty); 83 computers.removeWhere((DartCompletionComputer c) {
84 return performance.logElapseTime('computeFast ${c.runtimeType}', () {
85 return c.computeFast(request);
86 });
87 });
88 sendResults(computers.isEmpty);
89 });
80 } 90 }
81 91
82 /** 92 /**
83 * If there is remaining work to be done, then wait for the unit to be 93 * If there is remaining work to be done, then wait for the unit to be
84 * resolved and request that each remaining computer finish their work. 94 * resolved and request that each remaining computer finish their work.
85 */ 95 */
86 void computeFull() { 96 void computeFull() {
97 performance.logStartTime('waitForAnalysis');
87 waitForAnalysis().then((CompilationUnit unit) { 98 waitForAnalysis().then((CompilationUnit unit) {
99 performance.logElapseTime('waitForAnalysis');
88 if (unit == null) { 100 if (unit == null) {
89 sendResults(true); 101 sendResults(true);
90 return; 102 return;
91 } 103 }
92 request.unit = unit; 104 performance.logElapseTime('computeFull', () {
93 request.node = new NodeLocator.con1(offset).searchWithin(unit); 105 request.unit = unit;
94 int count = computers.length; 106 request.node = new NodeLocator.con1(offset).searchWithin(unit);
95 computers.forEach((c) { 107 int count = computers.length;
96 c.computeFull(request).then((bool changed) { 108 computers.forEach((DartCompletionComputer c) {
97 bool last = --count == 0; 109 String name = c.runtimeType.toString();
98 if (changed || last) { 110 String completeTag = 'computeFull $name complete';
99 sendResults(last); 111 performance.logStartTime(completeTag);
100 } 112 performance.logElapseTime('computeFull $name', () {
113 c.computeFull(request).then((bool changed) {
114 performance.logElapseTime(completeTag);
115 bool last = --count == 0;
116 if (changed || last) {
117 sendResults(last);
118 }
119 });
120 });
101 }); 121 });
102 }); 122 });
103 }); 123 });
104 } 124 }
105 125
106 /** 126 /**
107 * Build and initialize the list of completion computers 127 * Build and initialize the list of completion computers
108 */ 128 */
109 void initComputers() { 129 void initComputers() {
110 if (computers == null) { 130 if (computers == null) {
111 computers = [ 131 computers = [
112 new KeywordComputer(), 132 new KeywordComputer(),
113 new LocalComputer(), 133 new LocalComputer(),
134 new ArgListComputer(),
114 new CombinatorComputer(), 135 new CombinatorComputer(),
115 new ImportedComputer(), 136 new ImportedComputer(),
116 new InvocationComputer()]; 137 new InvocationComputer()];
117 } 138 }
118 } 139 }
119 140
120 /** 141 /**
121 * Send the current list of suggestions to the client. 142 * Send the current list of suggestions to the client.
122 */ 143 */
123 void sendResults(bool last) { 144 void sendResults(bool last) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 _ReplacementOffsetBuilder(this.request) { 244 _ReplacementOffsetBuilder(this.request) {
224 request.replacementOffset = request.offset; 245 request.replacementOffset = request.offset;
225 request.replacementLength = 0; 246 request.replacementLength = 0;
226 } 247 }
227 248
228 visitSimpleIdentifier(SimpleIdentifier node) { 249 visitSimpleIdentifier(SimpleIdentifier node) {
229 request.replacementOffset = node.offset; 250 request.replacementOffset = node.offset;
230 request.replacementLength = node.length; 251 request.replacementLength = node.length;
231 } 252 }
232 } 253 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698