Chromium Code Reviews| Index: pkg/analysis_server/lib/src/services/completion/completion_manager.dart |
| diff --git a/pkg/analysis_server/lib/src/services/completion/completion_manager.dart b/pkg/analysis_server/lib/src/services/completion/completion_manager.dart |
| index c58e308f7dd2c06069151078bc0b6c59c8814102..2253056e9b22d5382acaf88bf3c680ae19830645 100644 |
| --- a/pkg/analysis_server/lib/src/services/completion/completion_manager.dart |
| +++ b/pkg/analysis_server/lib/src/services/completion/completion_manager.dart |
| @@ -7,8 +7,8 @@ library services.completion.computer; |
| import 'dart:async'; |
| import 'package:analysis_server/src/protocol.dart'; |
| -import 'package:analysis_server/src/services/search/search_engine.dart'; |
| import 'package:analysis_server/src/services/completion/dart_completion_manager.dart'; |
| +import 'package:analysis_server/src/services/search/search_engine.dart'; |
| import 'package:analyzer/src/generated/engine.dart'; |
| import 'package:analyzer/src/generated/source.dart'; |
| @@ -42,10 +42,15 @@ abstract class CompletionManager { |
| * Create a manager for the given request. |
| */ |
| static CompletionManager create(AnalysisContext context, Source source, |
| - int offset, SearchEngine searchEngine) { |
| + int offset, SearchEngine searchEngine, CompletionPerformance performance) { |
| if (context != null) { |
| if (AnalysisEngine.isDartFileName(source.shortName)) { |
| - return new DartCompletionManager(context, searchEngine, source, offset); |
| + return new DartCompletionManager( |
| + context, |
| + searchEngine, |
| + source, |
| + offset, |
| + performance); |
| } |
| if (AnalysisEngine.isHtmlFileName(source.shortName)) { |
| //TODO (danrubel) implement |
| @@ -57,6 +62,51 @@ abstract class CompletionManager { |
| } |
| /** |
| + * Overall performance of a code completion operation. |
| + */ |
| +class CompletionPerformance { |
| + final Map<String, Duration> _startTimes = new Map<String, Duration>(); |
| + final Stopwatch _stopwatch = new Stopwatch(); |
| + final List<OperationPerformance> operations = []; |
| + |
| + CompletionPerformance() { |
| + _stopwatch.start(); |
| + } |
| + |
| + void complete() { |
| + _stopwatch.stop(); |
| + _logDuration('total time', _stopwatch.elapsed); |
| + } |
| + |
| + logElapseTime(String tag, [f() = null]) { |
| + Duration start; |
| + Duration end = _stopwatch.elapsed; |
| + var result; |
| + if (f == null) { |
| + start = _startTimes[tag]; |
| + if (start == null) { |
| + _logDuration(tag, null); |
| + return null; |
| + } |
| + } else { |
| + result = f(); |
| + start = end; |
| + end = _stopwatch.elapsed; |
| + } |
| + _logDuration(tag, end - start); |
| + return result; |
|
scheglov
2014/11/07 17:29:37
Do we use these values somewhere?
danrubel
2014/11/07 18:09:46
Yes. In several places, logElapseTime is called wi
|
| + } |
| + |
| + void logStartTime(String tag) { |
| + _startTimes[tag] = _stopwatch.elapsed; |
| + } |
| + |
| + void _logDuration(String tag, Duration elapsed) { |
| + operations.add(new OperationPerformance(tag, elapsed)); |
| + } |
| +} |
| + |
| +/** |
| * Code completion result generated by an [CompletionManager]. |
| */ |
| class CompletionResult { |
| @@ -102,3 +152,21 @@ class NoOpCompletionManager extends CompletionManager { |
| controller.add(new CompletionResult(offset, 0, [], true)); |
| } |
| } |
| + |
| +/** |
| + * The performance of an operation when computing code completion. |
| + */ |
| +class OperationPerformance { |
| + |
| + /** |
| + * The name of the operation |
| + */ |
| + final String name; |
| + |
| + /** |
| + * The elapse time or `null` if undefined. |
| + */ |
| + final Duration elapsed; |
| + |
| + OperationPerformance(this.name, this.elapsed); |
| +} |