| OLD | NEW |
| 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/completion/dart_completion_manager.
dart'; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 }); | 108 }); |
| 109 }); | 109 }); |
| 110 return controller.stream; | 110 return controller.stream; |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 /** | 114 /** |
| 115 * Overall performance of a code completion operation. | 115 * Overall performance of a code completion operation. |
| 116 */ | 116 */ |
| 117 class CompletionPerformance { | 117 class CompletionPerformance { |
| 118 final DateTime start = new DateTime.now(); |
| 118 final Map<String, Duration> _startTimes = new Map<String, Duration>(); | 119 final Map<String, Duration> _startTimes = new Map<String, Duration>(); |
| 119 final Stopwatch _stopwatch = new Stopwatch(); | 120 final Stopwatch _stopwatch = new Stopwatch(); |
| 120 final List<OperationPerformance> operations = <OperationPerformance>[]; | 121 final List<OperationPerformance> operations = <OperationPerformance>[]; |
| 121 | 122 |
| 122 Source source; | 123 Source source; |
| 123 int offset; | 124 int offset; |
| 124 String contents; | 125 String contents; |
| 125 int notificationCount = -1; | 126 int notificationCount = -1; |
| 126 int suggestionCount = -1; | 127 int suggestionCount = -1; |
| 128 Duration _firstNotification; |
| 127 | 129 |
| 128 CompletionPerformance() { | 130 CompletionPerformance() { |
| 129 _stopwatch.start(); | 131 _stopwatch.start(); |
| 130 } | 132 } |
| 131 | 133 |
| 132 int get elapsedInMilliseconds => | 134 int get elapsedInMilliseconds => |
| 133 operations.length > 0 ? operations.last.elapsed.inMilliseconds : 0; | 135 operations.length > 0 ? operations.last.elapsed.inMilliseconds : 0; |
| 134 | 136 |
| 137 int get firstNotificationInMilliseconds => |
| 138 _firstNotification != null ? _firstNotification.inMilliseconds : 0; |
| 139 |
| 135 String get snippet { | 140 String get snippet { |
| 136 if (contents == null || offset < 0 || contents.length < offset) { | 141 if (contents == null || offset < 0 || contents.length < offset) { |
| 137 return '???'; | 142 return '???'; |
| 138 } | 143 } |
| 139 int start = offset; | 144 int start = offset; |
| 140 while (start > 0) { | 145 while (start > 0) { |
| 141 String ch = contents[start - 1]; | 146 String ch = contents[start - 1]; |
| 142 if (ch == '\r' || ch == '\n') { | 147 if (ch == '\r' || ch == '\n') { |
| 143 break; | 148 break; |
| 144 } | 149 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 174 } | 179 } |
| 175 } else { | 180 } else { |
| 176 result = f(); | 181 result = f(); |
| 177 start = end; | 182 start = end; |
| 178 end = _stopwatch.elapsed; | 183 end = _stopwatch.elapsed; |
| 179 } | 184 } |
| 180 _logDuration(tag, end - start); | 185 _logDuration(tag, end - start); |
| 181 return result; | 186 return result; |
| 182 } | 187 } |
| 183 | 188 |
| 189 void logFirstNotificationComplete(String tag) { |
| 190 _firstNotification = _stopwatch.elapsed; |
| 191 _logDuration(tag, _firstNotification); |
| 192 } |
| 193 |
| 184 void logStartTime(String tag) { | 194 void logStartTime(String tag) { |
| 185 _startTimes[tag] = _stopwatch.elapsed; | 195 _startTimes[tag] = _stopwatch.elapsed; |
| 186 } | 196 } |
| 187 | 197 |
| 188 void _logDuration(String tag, Duration elapsed) { | 198 void _logDuration(String tag, Duration elapsed) { |
| 189 operations.add(new OperationPerformance(tag, elapsed)); | 199 operations.add(new OperationPerformance(tag, elapsed)); |
| 190 } | 200 } |
| 191 } | 201 } |
| 192 | 202 |
| 193 /** | 203 /** |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 */ | 272 */ |
| 263 final String name; | 273 final String name; |
| 264 | 274 |
| 265 /** | 275 /** |
| 266 * The elapse time or `null` if undefined. | 276 * The elapse time or `null` if undefined. |
| 267 */ | 277 */ |
| 268 final Duration elapsed; | 278 final Duration elapsed; |
| 269 | 279 |
| 270 OperationPerformance(this.name, this.elapsed); | 280 OperationPerformance(this.name, this.elapsed); |
| 271 } | 281 } |
| OLD | NEW |