| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 DateTime start = new DateTime.now(); |
| 119 final Map<String, Duration> _startTimes = new Map<String, Duration>(); | 119 final Map<String, Duration> _startTimes = new Map<String, Duration>(); |
| 120 final Stopwatch _stopwatch = new Stopwatch(); | 120 final Stopwatch _stopwatch = new Stopwatch(); |
| 121 final List<OperationPerformance> operations = <OperationPerformance>[]; | 121 final List<OperationPerformance> operations = <OperationPerformance>[]; |
| 122 | 122 |
| 123 Source source; | 123 Source source; |
| 124 int offset; | 124 String snippet = ''; |
| 125 String contents; | |
| 126 int notificationCount = -1; | 125 int notificationCount = -1; |
| 127 int suggestionCountFirst = -1; | 126 int suggestionCountFirst = -1; |
| 128 int suggestionCountLast = -1; | 127 int suggestionCountLast = -1; |
| 129 Duration _firstNotification; | 128 Duration _firstNotification; |
| 130 | 129 |
| 131 CompletionPerformance() { | 130 CompletionPerformance() { |
| 132 _stopwatch.start(); | 131 _stopwatch.start(); |
| 133 } | 132 } |
| 134 | 133 |
| 134 void setContentsAndOffset(String contents, int offset) { |
| 135 snippet = _computeSnippet(contents, offset); |
| 136 } |
| 137 |
| 135 int get elapsedInMilliseconds => | 138 int get elapsedInMilliseconds => |
| 136 operations.length > 0 ? operations.last.elapsed.inMilliseconds : 0; | 139 operations.length > 0 ? operations.last.elapsed.inMilliseconds : 0; |
| 137 | 140 |
| 138 int get firstNotificationInMilliseconds => | 141 int get firstNotificationInMilliseconds => |
| 139 _firstNotification != null ? _firstNotification.inMilliseconds : 0; | 142 _firstNotification != null ? _firstNotification.inMilliseconds : 0; |
| 140 | 143 |
| 141 String get snippet { | |
| 142 if (contents == null || offset < 0 || contents.length < offset) { | |
| 143 return '???'; | |
| 144 } | |
| 145 int start = offset; | |
| 146 while (start > 0) { | |
| 147 String ch = contents[start - 1]; | |
| 148 if (ch == '\r' || ch == '\n') { | |
| 149 break; | |
| 150 } | |
| 151 --start; | |
| 152 } | |
| 153 int end = offset; | |
| 154 while (end < contents.length) { | |
| 155 String ch = contents[end]; | |
| 156 if (ch == '\r' || ch == '\n') { | |
| 157 break; | |
| 158 } | |
| 159 ++end; | |
| 160 } | |
| 161 String prefix = contents.substring(start, offset); | |
| 162 String suffix = contents.substring(offset, end); | |
| 163 return '$prefix^$suffix'; | |
| 164 } | |
| 165 | |
| 166 String get startTimeAndMs => '${start.millisecondsSinceEpoch} - $start'; | 144 String get startTimeAndMs => '${start.millisecondsSinceEpoch} - $start'; |
| 167 | 145 |
| 168 String get suggestionCount { | 146 String get suggestionCount { |
| 169 if (notificationCount < 1) return ''; | 147 if (notificationCount < 1) return ''; |
| 170 if (notificationCount == 1) return '$suggestionCountFirst'; | 148 if (notificationCount == 1) return '$suggestionCountFirst'; |
| 171 return '$suggestionCountFirst, $suggestionCountLast'; | 149 return '$suggestionCountFirst, $suggestionCountLast'; |
| 172 } | 150 } |
| 173 | 151 |
| 174 void complete([String tag = null]) { | 152 void complete([String tag = null]) { |
| 175 _stopwatch.stop(); | 153 _stopwatch.stop(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 200 _logDuration(tag, _firstNotification); | 178 _logDuration(tag, _firstNotification); |
| 201 } | 179 } |
| 202 | 180 |
| 203 void logStartTime(String tag) { | 181 void logStartTime(String tag) { |
| 204 _startTimes[tag] = _stopwatch.elapsed; | 182 _startTimes[tag] = _stopwatch.elapsed; |
| 205 } | 183 } |
| 206 | 184 |
| 207 void _logDuration(String tag, Duration elapsed) { | 185 void _logDuration(String tag, Duration elapsed) { |
| 208 operations.add(new OperationPerformance(tag, elapsed)); | 186 operations.add(new OperationPerformance(tag, elapsed)); |
| 209 } | 187 } |
| 188 |
| 189 static String _computeSnippet(String contents, int offset) { |
| 190 if (contents == null || offset == null || offset < 0 || contents.length < of
fset) { |
| 191 return '???'; |
| 192 } |
| 193 int start = offset; |
| 194 while (start > 0) { |
| 195 String ch = contents[start - 1]; |
| 196 if (ch == '\r' || ch == '\n') { |
| 197 break; |
| 198 } |
| 199 --start; |
| 200 } |
| 201 int end = offset; |
| 202 while (end < contents.length) { |
| 203 String ch = contents[end]; |
| 204 if (ch == '\r' || ch == '\n') { |
| 205 break; |
| 206 } |
| 207 ++end; |
| 208 } |
| 209 String prefix = contents.substring(start, offset); |
| 210 String suffix = contents.substring(offset, end); |
| 211 return '$prefix^$suffix'; |
| 212 } |
| 210 } | 213 } |
| 211 | 214 |
| 212 /** | 215 /** |
| 213 * Encapsulates information specific to a particular completion request. | 216 * Encapsulates information specific to a particular completion request. |
| 214 */ | 217 */ |
| 215 class CompletionRequest { | 218 class CompletionRequest { |
| 216 /** | 219 /** |
| 217 * The offset within the source at which the completion is requested. | 220 * The offset within the source at which the completion is requested. |
| 218 */ | 221 */ |
| 219 final int offset; | 222 final int offset; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 */ | 284 */ |
| 282 final String name; | 285 final String name; |
| 283 | 286 |
| 284 /** | 287 /** |
| 285 * The elapse time or `null` if undefined. | 288 * The elapse time or `null` if undefined. |
| 286 */ | 289 */ |
| 287 final Duration elapsed; | 290 final Duration elapsed; |
| 288 | 291 |
| 289 OperationPerformance(this.name, this.elapsed); | 292 OperationPerformance(this.name, this.elapsed); |
| 290 } | 293 } |
| OLD | NEW |