OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 server.driver; | 5 library server.driver; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:math' show max; | 8 import 'dart:math' show max; |
9 | 9 |
10 import 'package:logging/logging.dart'; | 10 import 'package:logging/logging.dart'; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 _runCompleter.complete(results); | 141 _runCompleter.complete(results); |
142 } | 142 } |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 /** | 146 /** |
147 * [Measurement] tracks elapsed time for a given operation. | 147 * [Measurement] tracks elapsed time for a given operation. |
148 */ | 148 */ |
149 class Measurement { | 149 class Measurement { |
150 final String tag; | 150 final String tag; |
| 151 final bool notification; |
151 final List<Duration> elapsedTimes = new List<Duration>(); | 152 final List<Duration> elapsedTimes = new List<Duration>(); |
152 int errorCount = 0; | 153 int errorCount = 0; |
| 154 int unexpectedResultCount = 0; |
153 | 155 |
154 Measurement(this.tag); | 156 Measurement(this.tag, this.notification); |
| 157 |
| 158 int get count => elapsedTimes.length; |
155 | 159 |
156 void printSummary(int keyLen) { | 160 void printSummary(int keyLen) { |
157 int count = 0; | 161 int count = 0; |
| 162 Duration maxTime = elapsedTimes[0]; |
| 163 Duration minTime = elapsedTimes[0]; |
158 int totalTimeMicros = 0; | 164 int totalTimeMicros = 0; |
159 for (Duration elapsed in elapsedTimes) { | 165 for (Duration elapsed in elapsedTimes) { |
160 ++count; | 166 ++count; |
161 totalTimeMicros += elapsed.inMicroseconds; | 167 int timeMicros = elapsed.inMicroseconds; |
| 168 maxTime = maxTime.compareTo(elapsed) > 0 ? maxTime : elapsed; |
| 169 minTime = minTime.compareTo(elapsed) < 0 ? minTime : elapsed; |
| 170 totalTimeMicros += timeMicros; |
162 } | 171 } |
163 int averageTimeMicros = (totalTimeMicros / count).round(); | 172 int averageTimeMicros = (totalTimeMicros / count).round(); |
164 StringBuffer sb = new StringBuffer(); | 173 StringBuffer sb = new StringBuffer(); |
165 _printColumn(sb, tag, keyLen); | 174 _printColumn(sb, tag, keyLen); |
166 _printColumn(sb, count.toString(), 5, rightJustified: true); | 175 _printColumn(sb, count.toString(), 6, rightJustified: true); |
167 _printColumn(sb, errorCount.toString(), 5, rightJustified: true); | 176 _printColumn(sb, errorCount.toString(), 6, rightJustified: true); |
168 sb.write(' '); | 177 _printColumn(sb, unexpectedResultCount.toString(), 6, rightJustified: true); |
169 sb.write(new Duration(microseconds: averageTimeMicros)); | 178 _printDuration(sb, minTime); |
170 sb.write(', '); | 179 _printDuration(sb, new Duration(microseconds: averageTimeMicros)); |
171 sb.write(new Duration(microseconds: totalTimeMicros)); | 180 _printDuration(sb, maxTime); |
| 181 _printDuration(sb, new Duration(microseconds: totalTimeMicros)); |
172 print(sb.toString()); | 182 print(sb.toString()); |
173 } | 183 } |
174 | 184 |
175 void record(bool success, Duration elapsed) { | 185 void record(bool success, Duration elapsed) { |
176 if (!success) { | 186 if (!success) { |
177 ++errorCount; | 187 ++errorCount; |
178 } | 188 } |
179 elapsedTimes.add(elapsed); | 189 elapsedTimes.add(elapsed); |
180 } | 190 } |
| 191 |
| 192 void recordUnexpectedResults() { |
| 193 ++unexpectedResultCount; |
| 194 } |
| 195 |
| 196 void _printDuration(StringBuffer sb, Duration duration) { |
| 197 sb.write(' '); |
| 198 sb.write(duration); |
| 199 sb.write(','); |
| 200 } |
181 } | 201 } |
182 | 202 |
183 /** | 203 /** |
184 * [Results] contains information gathered by [Driver] | 204 * [Results] contains information gathered by [Driver] |
185 * while running the analysis server | 205 * while running the analysis server |
186 */ | 206 */ |
187 class Results { | 207 class Results { |
188 Map<String, Measurement> measurements = new Map<String, Measurement>(); | 208 Map<String, Measurement> measurements = new Map<String, Measurement>(); |
189 | 209 |
190 /** | 210 /** |
191 * Display results on stdout. | 211 * Display results on stdout. |
192 */ | 212 */ |
193 void printResults() { | 213 void printResults() { |
| 214 print(''); |
194 print('=================================================================='); | 215 print('=================================================================='); |
| 216 print(''); |
195 List<String> keys = measurements.keys.toList()..sort(); | 217 List<String> keys = measurements.keys.toList()..sort(); |
196 int keyLen = keys.fold(0, (int len, String key) => max(len, key.length)); | 218 int keyLen = keys.fold(0, (int len, String key) => max(len, key.length)); |
197 StringBuffer sb = new StringBuffer(); | 219 _printGroupHeader('Request/Response', keyLen); |
198 _printColumn(sb, 'Results', keyLen); | |
199 _printColumn(sb, 'count', 5); | |
200 _printColumn(sb, 'errors', 5); | |
201 sb.write(' average, total,'); | |
202 print(sb.toString()); | |
203 int totalCount = 0; | 220 int totalCount = 0; |
204 int totalErrorCount = 0; | 221 int totalErrorCount = 0; |
| 222 int totalUnexpectedResultCount = 0; |
205 for (String tag in keys) { | 223 for (String tag in keys) { |
206 Measurement m = measurements[tag]; | 224 Measurement m = measurements[tag]; |
207 m.printSummary(keyLen); | 225 if (!m.notification) { |
208 totalCount += m.elapsedTimes.length; | 226 m.printSummary(keyLen); |
209 totalErrorCount += m.errorCount; | 227 totalCount += m.count; |
| 228 totalErrorCount += m.errorCount; |
| 229 totalUnexpectedResultCount += m.unexpectedResultCount; |
| 230 } |
210 } | 231 } |
211 sb.clear(); | 232 _printTotals(keyLen, totalCount, totalErrorCount, totalUnexpectedResultCount
); |
212 _printColumn(sb, 'Totals', keyLen); | 233 print(''); |
213 _printColumn(sb, totalCount.toString(), 5); | 234 _printGroupHeader('Notifications', keyLen); |
214 _printColumn(sb, totalErrorCount.toString(), 5); | 235 for (String tag in keys) { |
215 print(sb.toString()); | 236 Measurement m = measurements[tag]; |
| 237 if (m.notification) { |
| 238 m.printSummary(keyLen); |
| 239 } |
| 240 } |
| 241 /// TODO(danrubel) *** print warnings if driver caches are not empty **** |
| 242 print(''); |
| 243 print( |
| 244 '(1) uxr = UneXpected Results, or responses received from the server'); |
| 245 print( |
| 246 ' that do not match the recorded response for that request.'); |
216 } | 247 } |
217 | 248 |
218 /** | 249 /** |
219 * Record the elapsed time for the given operation. | 250 * Record the elapsed time for the given operation. |
220 */ | 251 */ |
221 void record(String tag, Duration elapsed, {bool success: true}) { | 252 void record(String tag, Duration elapsed, |
| 253 {bool notification: false, bool success: true}) { |
222 Measurement measurement = measurements[tag]; | 254 Measurement measurement = measurements[tag]; |
223 if (measurement == null) { | 255 if (measurement == null) { |
224 measurement = new Measurement(tag); | 256 measurement = new Measurement(tag, notification); |
225 measurements[tag] = measurement; | 257 measurements[tag] = measurement; |
226 } | 258 } |
227 measurement.record(success, elapsed); | 259 measurement.record(success, elapsed); |
228 } | 260 } |
| 261 |
| 262 void recordUnexpectedResults(String tag) { |
| 263 measurements[tag].recordUnexpectedResults(); |
| 264 } |
| 265 |
| 266 void _printGroupHeader(String groupName, int keyLen) { |
| 267 StringBuffer sb = new StringBuffer(); |
| 268 _printColumn(sb, groupName, keyLen); |
| 269 _printColumn(sb, 'count', 6, rightJustified: true); |
| 270 _printColumn(sb, 'error', 6, rightJustified: true); |
| 271 _printColumn(sb, 'uxr(1)', 6, rightJustified: true); |
| 272 sb.write(' '); |
| 273 _printColumn(sb, 'minimum', 15); |
| 274 _printColumn(sb, 'average', 15); |
| 275 _printColumn(sb, 'maximum', 15); |
| 276 _printColumn(sb, 'total', 15); |
| 277 print(sb.toString()); |
| 278 } |
| 279 |
| 280 void _printTotals(int keyLen, int totalCount, int totalErrorCount, int totalUn
expectedResultCount) { |
| 281 StringBuffer sb = new StringBuffer(); |
| 282 _printColumn(sb, 'Totals', keyLen); |
| 283 _printColumn(sb, totalCount.toString(), 6, rightJustified: true); |
| 284 _printColumn(sb, totalErrorCount.toString(), 6, rightJustified: true); |
| 285 _printColumn(sb, totalUnexpectedResultCount.toString(), 6, |
| 286 rightJustified: true); |
| 287 print(sb.toString()); |
| 288 } |
229 } | 289 } |
OLD | NEW |