| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 analyzer_impl; | 5 library analyzer_impl; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 final HashMap<Source, AnalysisErrorInfo> sourceErrorsMap = new HashMap<Source,
AnalysisErrorInfo>(); | 52 final HashMap<Source, AnalysisErrorInfo> sourceErrorsMap = new HashMap<Source,
AnalysisErrorInfo>(); |
| 53 | 53 |
| 54 AnalyzerImpl(this.sourcePath, this.options, this.startTime) { | 54 AnalyzerImpl(this.sourcePath, this.options, this.startTime) { |
| 55 if (sdk == null) { | 55 if (sdk == null) { |
| 56 sdk = new DirectoryBasedDartSdk(new JavaFile(options.dartSdkPath)); | 56 sdk = new DirectoryBasedDartSdk(new JavaFile(options.dartSdkPath)); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Treats the [sourcePath] as the top level library and analyzes it using a | 61 * Treats the [sourcePath] as the top level library and analyzes it using a |
| 62 * synchronous algorithm over the analysis engine. | 62 * synchronous algorithm over the analysis engine. If [printMode] is `0`, |
| 63 * then no error or performance information is printed. If [printMode] is `1`, |
| 64 * then both will be printed. If [printMode] is `2`, then only performance |
| 65 * information will be printed, and it will be marked as being for a cold VM. |
| 63 */ | 66 */ |
| 64 ErrorSeverity analyzeSync() { | 67 ErrorSeverity analyzeSync({int printMode : 1}) { |
| 65 setupForAnalysis(); | 68 setupForAnalysis(); |
| 66 return _analyzeSync(); | 69 return _analyzeSync(printMode); |
| 67 } | 70 } |
| 68 | 71 |
| 69 /** | 72 /** |
| 70 * Treats the [sourcePath] as the top level library and analyzes it using a | 73 * Treats the [sourcePath] as the top level library and analyzes it using a |
| 71 * asynchronous algorithm over the analysis engine. | 74 * asynchronous algorithm over the analysis engine. |
| 72 */ | 75 */ |
| 73 void analyzeAsync() { | 76 void analyzeAsync() { |
| 74 setupForAnalysis(); | 77 setupForAnalysis(); |
| 75 _analyzeAsync(); | 78 _analyzeAsync(); |
| 76 } | 79 } |
| 77 | 80 |
| 78 /** | 81 /** |
| 79 * Setup local fields such as the analysis context for analysis. | 82 * Setup local fields such as the analysis context for analysis. |
| 80 */ | 83 */ |
| 81 void setupForAnalysis() { | 84 void setupForAnalysis() { |
| 82 sources.clear(); | 85 sources.clear(); |
| 83 errorInfos.clear(); | 86 errorInfos.clear(); |
| 84 if (sourcePath == null) { | 87 if (sourcePath == null) { |
| 85 throw new ArgumentError("sourcePath cannot be null"); | 88 throw new ArgumentError("sourcePath cannot be null"); |
| 86 } | 89 } |
| 87 JavaFile sourceFile = new JavaFile(sourcePath); | 90 JavaFile sourceFile = new JavaFile(sourcePath); |
| 88 UriKind uriKind = getUriKind(sourceFile); | 91 UriKind uriKind = getUriKind(sourceFile); |
| 89 librarySource = new FileBasedSource.con2(sourceFile, uriKind); | 92 librarySource = new FileBasedSource.con2(sourceFile, uriKind); |
| 90 | 93 |
| 91 // prepare context | 94 // prepare context |
| 92 prepareAnalysisContext(sourceFile, librarySource); | 95 prepareAnalysisContext(sourceFile, librarySource); |
| 93 } | 96 } |
| 94 | 97 |
| 95 /// The sync version of analysis | 98 /// The sync version of analysis. |
| 96 ErrorSeverity _analyzeSync() { | 99 ErrorSeverity _analyzeSync(int printMode) { |
| 97 // don't try to analyze parts | 100 // don't try to analyze parts |
| 98 if (context.computeKindOf(librarySource) == SourceKind.PART) { | 101 if (context.computeKindOf(librarySource) == SourceKind.PART) { |
| 99 print("Only libraries can be analyzed."); | 102 print("Only libraries can be analyzed."); |
| 100 print("$sourcePath is a part and can not be analyzed."); | 103 print("$sourcePath is a part and can not be analyzed."); |
| 101 return ErrorSeverity.ERROR; | 104 return ErrorSeverity.ERROR; |
| 102 } | 105 } |
| 103 // resolve library | 106 // resolve library |
| 104 var libraryElement = context.computeLibraryElement(librarySource); | 107 var libraryElement = context.computeLibraryElement(librarySource); |
| 105 // prepare source and errors | 108 // prepare source and errors |
| 106 prepareSources(libraryElement); | 109 prepareSources(libraryElement); |
| 107 prepareErrors(); | 110 prepareErrors(); |
| 108 | 111 |
| 109 // print errors and performance numbers | 112 // print errors and performance numbers |
| 110 _printErrorsAndPerf(); | 113 if (printMode == 1) { |
| 114 _printErrorsAndPerf(); |
| 115 } else if (printMode == 2) { |
| 116 _printColdPerf(); |
| 117 } |
| 111 | 118 |
| 112 // compute max severity and set exitCode | 119 // compute max severity and set exitCode |
| 113 ErrorSeverity status = maxErrorSeverity; | 120 ErrorSeverity status = maxErrorSeverity; |
| 114 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { | 121 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { |
| 115 status = ErrorSeverity.ERROR; | 122 status = ErrorSeverity.ERROR; |
| 116 } | 123 } |
| 117 return status; | 124 return status; |
| 118 } | 125 } |
| 119 | 126 |
| 120 /// The async version of the analysis | 127 /// The async version of the analysis |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // is because when the argument flags are constructed in BatchRunner and | 169 // is because when the argument flags are constructed in BatchRunner and |
| 163 // passed in from batch mode which removes the batch flag to prevent the | 170 // passed in from batch mode which removes the batch flag to prevent the |
| 164 // "cannot have the batch flag and source file" error message. | 171 // "cannot have the batch flag and source file" error message. |
| 165 IOSink sink = options.machineFormat ? stderr : stdout; | 172 IOSink sink = options.machineFormat ? stderr : stdout; |
| 166 | 173 |
| 167 // print errors | 174 // print errors |
| 168 ErrorFormatter formatter = new ErrorFormatter(sink, options, _excludeTodo); | 175 ErrorFormatter formatter = new ErrorFormatter(sink, options, _excludeTodo); |
| 169 formatter.formatErrors(errorInfos); | 176 formatter.formatErrors(errorInfos); |
| 170 | 177 |
| 171 // print performance numbers | 178 // print performance numbers |
| 172 if (options.perf) { | 179 if (options.perf || options.warmPerf) { |
| 173 int totalTime = JavaSystem.currentTimeMillis() - startTime; | 180 int totalTime = JavaSystem.currentTimeMillis() - startTime; |
| 174 int ioTime = PerformanceStatistics.io.result; | 181 int ioTime = PerformanceStatistics.io.result; |
| 175 int scanTime = PerformanceStatistics.scan.result; | 182 int scanTime = PerformanceStatistics.scan.result; |
| 176 int parseTime = PerformanceStatistics.parse.result; | 183 int parseTime = PerformanceStatistics.parse.result; |
| 177 int resolveTime = PerformanceStatistics.resolve.result; | 184 int resolveTime = PerformanceStatistics.resolve.result; |
| 178 int errorsTime = PerformanceStatistics.errors.result; | 185 int errorsTime = PerformanceStatistics.errors.result; |
| 179 int hintsTime = PerformanceStatistics.hints.result; | 186 int hintsTime = PerformanceStatistics.hints.result; |
| 180 int angularTime = PerformanceStatistics.angular.result; | 187 int angularTime = PerformanceStatistics.angular.result; |
| 181 stdout.writeln("io:$ioTime"); | 188 stdout.writeln("io:$ioTime"); |
| 182 stdout.writeln("scan:$scanTime"); | 189 stdout.writeln("scan:$scanTime"); |
| 183 stdout.writeln("parse:$parseTime"); | 190 stdout.writeln("parse:$parseTime"); |
| 184 stdout.writeln("resolve:$resolveTime"); | 191 stdout.writeln("resolve:$resolveTime"); |
| 185 stdout.writeln("errors:$errorsTime"); | 192 stdout.writeln("errors:$errorsTime"); |
| 186 stdout.writeln("hints:$hintsTime"); | 193 stdout.writeln("hints:$hintsTime"); |
| 187 stdout.writeln("angular:$angularTime"); | 194 stdout.writeln("angular:$angularTime"); |
| 188 stdout.writeln("other:${totalTime | 195 stdout.writeln("other:${totalTime |
| 189 - (ioTime + scanTime + parseTime + resolveTime + errorsTime + hintsTim
e | 196 - (ioTime + scanTime + parseTime + resolveTime + errorsTime + hintsTim
e |
| 190 + angularTime)}"); | 197 + angularTime)}"); |
| 191 stdout.writeln("total:$totalTime"); | 198 stdout.writeln("total:$totalTime"); |
| 192 } | 199 } |
| 193 } | 200 } |
| 194 | 201 |
| 202 _printColdPerf() { |
| 203 // print cold VM performance numbers |
| 204 int totalTime = JavaSystem.currentTimeMillis() - startTime; |
| 205 int ioTime = PerformanceStatistics.io.result; |
| 206 int scanTime = PerformanceStatistics.scan.result; |
| 207 int parseTime = PerformanceStatistics.parse.result; |
| 208 int resolveTime = PerformanceStatistics.resolve.result; |
| 209 int errorsTime = PerformanceStatistics.errors.result; |
| 210 int hintsTime = PerformanceStatistics.hints.result; |
| 211 int angularTime = PerformanceStatistics.angular.result; |
| 212 stdout.writeln("io-cold:$ioTime"); |
| 213 stdout.writeln("scan-cold:$scanTime"); |
| 214 stdout.writeln("parse-cold:$parseTime"); |
| 215 stdout.writeln("resolve-cold:$resolveTime"); |
| 216 stdout.writeln("errors-cold:$errorsTime"); |
| 217 stdout.writeln("hints-cold:$hintsTime"); |
| 218 stdout.writeln("angular-cold:$angularTime"); |
| 219 stdout.writeln("other-cold:${totalTime |
| 220 - (ioTime + scanTime + parseTime + resolveTime + errorsTime + hintsTime |
| 221 + angularTime)}"); |
| 222 stdout.writeln("total-cold:$totalTime"); |
| 223 } |
| 224 |
| 195 /// Returns the maximal [ErrorSeverity] of the recorded errors. | 225 /// Returns the maximal [ErrorSeverity] of the recorded errors. |
| 196 ErrorSeverity get maxErrorSeverity { | 226 ErrorSeverity get maxErrorSeverity { |
| 197 var status = ErrorSeverity.NONE; | 227 var status = ErrorSeverity.NONE; |
| 198 for (AnalysisErrorInfo errorInfo in errorInfos) { | 228 for (AnalysisErrorInfo errorInfo in errorInfos) { |
| 199 for (AnalysisError error in errorInfo.errors) { | 229 for (AnalysisError error in errorInfo.errors) { |
| 200 var severity = error.errorCode.errorSeverity; | 230 var severity = error.errorCode.errorSeverity; |
| 201 status = status.max(severity); | 231 status = status.max(severity); |
| 202 } | 232 } |
| 203 } | 233 } |
| 204 return status; | 234 return status; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 388 } |
| 359 } | 389 } |
| 360 | 390 |
| 361 @override | 391 @override |
| 362 void logInformation2(String message, Exception exception) { | 392 void logInformation2(String message, Exception exception) { |
| 363 if (log) { | 393 if (log) { |
| 364 stdout.writeln(message); | 394 stdout.writeln(message); |
| 365 } | 395 } |
| 366 } | 396 } |
| 367 } | 397 } |
| OLD | NEW |