| 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 /** | 5 /** |
| 6 * A stress test for the analysis server. | 6 * A stress test for the analysis server. |
| 7 */ | 7 */ |
| 8 library analysis_server.test.stress.replay.replay; | 8 library analysis_server.test.stress.replay.replay; |
| 9 | 9 |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| 11 import 'dart:io'; | 11 import 'dart:io'; |
| 12 import 'dart:math' as math; |
| 12 | 13 |
| 13 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 14 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 14 import 'package:analyzer/dart/ast/token.dart'; | 15 import 'package:analyzer/dart/ast/token.dart'; |
| 15 import 'package:analyzer/src/dart/scanner/reader.dart'; | 16 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| 16 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 17 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
| 17 import 'package:analyzer/src/generated/error.dart' as error; | 18 import 'package:analyzer/src/generated/error.dart' as error; |
| 18 import 'package:analyzer/src/generated/java_engine.dart'; | 19 import 'package:analyzer/src/generated/java_engine.dart'; |
| 19 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 20 import 'package:analyzer/src/util/glob.dart'; | 21 import 'package:analyzer/src/util/glob.dart'; |
| 21 import 'package:args/args.dart'; | 22 import 'package:args/args.dart'; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 return parser; | 162 return parser; |
| 162 } | 163 } |
| 163 | 164 |
| 164 /** | 165 /** |
| 165 * Add source edits to the given [fileEdit] based on the given [blobDiff]. | 166 * Add source edits to the given [fileEdit] based on the given [blobDiff]. |
| 166 */ | 167 */ |
| 167 void _createSourceEdits(FileEdit fileEdit, BlobDiff blobDiff) { | 168 void _createSourceEdits(FileEdit fileEdit, BlobDiff blobDiff) { |
| 168 LineInfo info = fileEdit.lineInfo; | 169 LineInfo info = fileEdit.lineInfo; |
| 169 for (DiffHunk hunk in blobDiff.hunks) { | 170 for (DiffHunk hunk in blobDiff.hunks) { |
| 170 int srcStart = info.getOffsetOfLine(hunk.srcLine); | 171 int srcStart = info.getOffsetOfLine(hunk.srcLine); |
| 171 int srcEnd = info.getOffsetOfLine(hunk.srcLine + hunk.removeLines.length); | 172 int srcEnd = info.getOffsetOfLine( |
| 173 math.min(hunk.srcLine + hunk.removeLines.length, info.lineCount - 1)); |
| 172 String addedText = _join(hunk.addLines); | 174 String addedText = _join(hunk.addLines); |
| 173 // | 175 // |
| 174 // Create the source edits. | 176 // Create the source edits. |
| 175 // | 177 // |
| 176 List<int> breakOffsets = _getBreakOffsets(addedText); | 178 List<int> breakOffsets = _getBreakOffsets(addedText); |
| 177 int breakCount = breakOffsets.length; | 179 int breakCount = breakOffsets.length; |
| 178 List<SourceEdit> sourceEdits = <SourceEdit>[]; | 180 List<SourceEdit> sourceEdits = <SourceEdit>[]; |
| 179 if (breakCount == 0) { | 181 if (breakCount == 0) { |
| 180 sourceEdits | 182 sourceEdits |
| 181 .add(new SourceEdit(srcStart, srcEnd - srcStart + 1, addedText)); | 183 .add(new SourceEdit(srcStart, srcEnd - srcStart + 1, addedText)); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 Future _replayChanges() async { | 315 Future _replayChanges() async { |
| 314 // | 316 // |
| 315 // Get the revision history of the repo. | 317 // Get the revision history of the repo. |
| 316 // | 318 // |
| 317 LinearCommitHistory history = repository.getCommitHistory(); | 319 LinearCommitHistory history = repository.getCommitHistory(); |
| 318 statistics.commitCount = history.commitIds.length; | 320 statistics.commitCount = history.commitIds.length; |
| 319 LinearCommitHistoryIterator iterator = history.iterator(); | 321 LinearCommitHistoryIterator iterator = history.iterator(); |
| 320 // | 322 // |
| 321 // Iterate over the history, applying changes. | 323 // Iterate over the history, applying changes. |
| 322 // | 324 // |
| 325 int dotCount = 0; |
| 323 bool firstCheckout = true; | 326 bool firstCheckout = true; |
| 324 ErrorMap expectedErrors = null; | 327 ErrorMap expectedErrors = null; |
| 325 Iterable<String> changedPubspecs; | 328 Iterable<String> changedPubspecs; |
| 326 while (iterator.moveNext()) { | 329 while (iterator.moveNext()) { |
| 327 // | 330 // |
| 328 // Checkout the commit on which the changes are based. | 331 // Checkout the commit on which the changes are based. |
| 329 // | 332 // |
| 330 String commit = iterator.srcCommit; | 333 String commit = iterator.srcCommit; |
| 331 repository.checkout(commit); | 334 repository.checkout(commit); |
| 332 if (expectedErrors != null) { | 335 if (expectedErrors != null) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 356 // Apply the changes. | 359 // Apply the changes. |
| 357 // | 360 // |
| 358 CommitDelta commitDelta = iterator.next(); | 361 CommitDelta commitDelta = iterator.next(); |
| 359 commitDelta.filterDiffs(analysisRoots, fileGlobs); | 362 commitDelta.filterDiffs(analysisRoots, fileGlobs); |
| 360 if (commitDelta.hasDiffs) { | 363 if (commitDelta.hasDiffs) { |
| 361 statistics.commitsWithChangeInRootCount++; | 364 statistics.commitsWithChangeInRootCount++; |
| 362 _replayDiff(commitDelta); | 365 _replayDiff(commitDelta); |
| 363 } | 366 } |
| 364 changedPubspecs = commitDelta.filesMatching(PUBSPEC_FILE_NAME); | 367 changedPubspecs = commitDelta.filesMatching(PUBSPEC_FILE_NAME); |
| 365 stdout.write('.'); | 368 stdout.write('.'); |
| 369 if (dotCount++ > 100) { |
| 370 stdout.writeln(); |
| 371 dotCount = 0; |
| 372 } |
| 366 } | 373 } |
| 367 server.removeAllOverlays(); | 374 server.removeAllOverlays(); |
| 368 stdout.writeln(); | 375 stdout.writeln(); |
| 369 } | 376 } |
| 370 | 377 |
| 371 /** | 378 /** |
| 372 * Replay the changes between two commits, as represented by the given | 379 * Replay the changes between two commits, as represented by the given |
| 373 * [commitDelta]. | 380 * [commitDelta]. |
| 374 */ | 381 */ |
| 375 void _replayDiff(CommitDelta commitDelta) { | 382 void _replayDiff(CommitDelta commitDelta) { |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 int seconds = milliseconds ~/ 1000; | 632 int seconds = milliseconds ~/ 1000; |
| 626 milliseconds -= seconds * 1000; | 633 milliseconds -= seconds * 1000; |
| 627 int minutes = seconds ~/ 60; | 634 int minutes = seconds ~/ 60; |
| 628 seconds -= minutes * 60; | 635 seconds -= minutes * 60; |
| 629 int hours = minutes ~/ 60; | 636 int hours = minutes ~/ 60; |
| 630 minutes -= hours * 60; | 637 minutes -= hours * 60; |
| 631 | 638 |
| 632 if (hours > 0) { | 639 if (hours > 0) { |
| 633 return '$hours:$minutes:$seconds.$milliseconds'; | 640 return '$hours:$minutes:$seconds.$milliseconds'; |
| 634 } else if (minutes > 0) { | 641 } else if (minutes > 0) { |
| 635 return '$minutes:$seconds.$milliseconds m'; | 642 return '$minutes:$seconds.$milliseconds'; |
| 636 } else if (seconds > 0) { | |
| 637 return '$seconds.$milliseconds s'; | |
| 638 } | 643 } |
| 639 return '$milliseconds ms'; | 644 return '$seconds.$milliseconds'; |
| 640 } | 645 } |
| 641 } | 646 } |
| OLD | NEW |