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

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/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 services.completion.computer; 5 library services.completion.computer;
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/dart_completion_manager. dart';
10 import 'package:analysis_server/src/services/search/search_engine.dart'; 11 import 'package:analysis_server/src/services/search/search_engine.dart';
11 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
12 import 'package:analyzer/src/generated/engine.dart'; 12 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/source.dart'; 13 import 'package:analyzer/src/generated/source.dart';
14 14
15 /** 15 /**
16 * Manages `CompletionComputer`s for a given completion request. 16 * Manages `CompletionComputer`s for a given completion request.
17 */ 17 */
18 abstract class CompletionManager { 18 abstract class CompletionManager {
19 19
20 StreamController<CompletionResult> controller; 20 StreamController<CompletionResult> controller;
21 21
(...skipping 13 matching lines...) Expand all
35 controller = new StreamController<CompletionResult>(onListen: () { 35 controller = new StreamController<CompletionResult>(onListen: () {
36 scheduleMicrotask(compute); 36 scheduleMicrotask(compute);
37 }); 37 });
38 return controller.stream; 38 return controller.stream;
39 } 39 }
40 40
41 /** 41 /**
42 * Create a manager for the given request. 42 * Create a manager for the given request.
43 */ 43 */
44 static CompletionManager create(AnalysisContext context, Source source, 44 static CompletionManager create(AnalysisContext context, Source source,
45 int offset, SearchEngine searchEngine) { 45 int offset, SearchEngine searchEngine, CompletionPerformance performance) {
46 if (context != null) { 46 if (context != null) {
47 if (AnalysisEngine.isDartFileName(source.shortName)) { 47 if (AnalysisEngine.isDartFileName(source.shortName)) {
48 return new DartCompletionManager(context, searchEngine, source, offset); 48 return new DartCompletionManager(
49 context,
50 searchEngine,
51 source,
52 offset,
53 performance);
49 } 54 }
50 if (AnalysisEngine.isHtmlFileName(source.shortName)) { 55 if (AnalysisEngine.isHtmlFileName(source.shortName)) {
51 //TODO (danrubel) implement 56 //TODO (danrubel) implement
52 // return new HtmlCompletionManager(context, searchEngine, source, offset ); 57 // return new HtmlCompletionManager(context, searchEngine, source, offset );
53 } 58 }
54 } 59 }
55 return new NoOpCompletionManager(source, offset); 60 return new NoOpCompletionManager(source, offset);
56 } 61 }
57 } 62 }
58 63
59 /** 64 /**
65 * Overall performance of a code completion operation.
66 */
67 class CompletionPerformance {
68 final Map<String, Duration> _startTimes = new Map<String, Duration>();
69 final Stopwatch _stopwatch = new Stopwatch();
70 final List<OperationPerformance> operations = [];
71
72 CompletionPerformance() {
73 _stopwatch.start();
74 }
75
76 void complete() {
77 _stopwatch.stop();
78 _logDuration('total time', _stopwatch.elapsed);
79 }
80
81 logElapseTime(String tag, [f() = null]) {
82 Duration start;
83 Duration end = _stopwatch.elapsed;
84 var result;
85 if (f == null) {
86 start = _startTimes[tag];
87 if (start == null) {
88 _logDuration(tag, null);
89 return null;
90 }
91 } else {
92 result = f();
93 start = end;
94 end = _stopwatch.elapsed;
95 }
96 _logDuration(tag, end - start);
97 return result;
98 }
99
100 void logStartTime(String tag) {
101 _startTimes[tag] = _stopwatch.elapsed;
102 }
103
104 void _logDuration(String tag, Duration elapsed) {
105 operations.add(new OperationPerformance(tag, elapsed));
106 }
107 }
108
109 /**
60 * Code completion result generated by an [CompletionManager]. 110 * Code completion result generated by an [CompletionManager].
61 */ 111 */
62 class CompletionResult { 112 class CompletionResult {
63 113
64 /** 114 /**
65 * The length of the text to be replaced if the remainder of the identifier 115 * The length of the text to be replaced if the remainder of the identifier
66 * containing the cursor is to be replaced when the suggestion is applied 116 * containing the cursor is to be replaced when the suggestion is applied
67 * (that is, the number of characters in the existing identifier). 117 * (that is, the number of characters in the existing identifier).
68 */ 118 */
69 final int replacementLength; 119 final int replacementLength;
(...skipping 25 matching lines...) Expand all
95 final Source source; 145 final Source source;
96 final int offset; 146 final int offset;
97 147
98 NoOpCompletionManager(this.source, this.offset); 148 NoOpCompletionManager(this.source, this.offset);
99 149
100 @override 150 @override
101 void compute() { 151 void compute() {
102 controller.add(new CompletionResult(offset, 0, [], true)); 152 controller.add(new CompletionResult(offset, 0, [], true));
103 } 153 }
104 } 154 }
155
156 /**
157 * The performance of an operation when computing code completion.
158 */
159 class OperationPerformance {
160
161 /**
162 * The name of the operation
163 */
164 final String name;
165
166 /**
167 * The elapse time or `null` if undefined.
168 */
169 final Duration elapsed;
170
171 OperationPerformance(this.name, this.elapsed);
172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698