OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /// An entrypoint used to run portions of analyzer and measure its performance. | 5 /// An entrypoint used to run portions of analyzer and measure its performance. |
6 library analyzer_cli.tool.perf; | 6 library analyzer_cli.tool.perf; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:io' show exit; | 9 import 'dart:io' show exit; |
10 | 10 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 scanTimer = new Stopwatch(); | 92 scanTimer = new Stopwatch(); |
93 var old = scanTotalChars; | 93 var old = scanTotalChars; |
94 scanTotalChars = 0; | 94 scanTotalChars = 0; |
95 var parseTimer = new Stopwatch()..start(); | 95 var parseTimer = new Stopwatch()..start(); |
96 for (var source in files) { | 96 for (var source in files) { |
97 parseFull(source); | 97 parseFull(source); |
98 } | 98 } |
99 parseTimer.stop(); | 99 parseTimer.stop(); |
100 | 100 |
101 // Report size and scanning time again. See discussion above. | 101 // Report size and scanning time again. See discussion above. |
102 if (old != scanTotalChars) print('input size changed? ${old} chars'); | 102 if (old != scanTotalChars) print('input size changed? $old chars'); |
103 report("scan", scanTimer.elapsedMicroseconds); | 103 report("scan", scanTimer.elapsedMicroseconds); |
104 | 104 |
105 var pTime = parseTimer.elapsedMicroseconds - scanTimer.elapsedMicroseconds; | 105 var pTime = parseTimer.elapsedMicroseconds - scanTimer.elapsedMicroseconds; |
106 report("parse", pTime); | 106 report("parse", pTime); |
107 } | 107 } |
108 | 108 |
109 /// Parse the full body of [source] and return it's compilation unit. | 109 /// Parse the full body of [source] and return it's compilation unit. |
110 CompilationUnit parseFull(Source source) { | 110 CompilationUnit parseFull(Source source) { |
111 var token = tokenize(source); | 111 var token = tokenize(source); |
112 var parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER); | 112 var parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER); |
(...skipping 16 matching lines...) Expand all Loading... |
129 // Recording and reporting this twice is unnecessary, but we do so for now to | 129 // Recording and reporting this twice is unnecessary, but we do so for now to |
130 // validate that the results are consistent. | 130 // validate that the results are consistent. |
131 scanTimer = new Stopwatch(); | 131 scanTimer = new Stopwatch(); |
132 var old = scanTotalChars; | 132 var old = scanTotalChars; |
133 scanTotalChars = 0; | 133 scanTotalChars = 0; |
134 for (var source in files) { | 134 for (var source in files) { |
135 tokenize(source); | 135 tokenize(source); |
136 } | 136 } |
137 | 137 |
138 // Report size and scanning time again. See discussion above. | 138 // Report size and scanning time again. See discussion above. |
139 if (old != scanTotalChars) print('input size changed? ${old} chars'); | 139 if (old != scanTotalChars) print('input size changed? $old chars'); |
140 report("scan", scanTimer.elapsedMicroseconds); | 140 report("scan", scanTimer.elapsedMicroseconds); |
141 } | 141 } |
142 | 142 |
143 /// Load and scans all files we need to process: files reachable from the | 143 /// Load and scans all files we need to process: files reachable from the |
144 /// entrypoint and all core libraries automatically included by the VM. | 144 /// entrypoint and all core libraries automatically included by the VM. |
145 Set<Source> scanReachableFiles(Uri entryUri) { | 145 Set<Source> scanReachableFiles(Uri entryUri) { |
146 var files = new Set<Source>(); | 146 var files = new Set<Source>(); |
147 var loadTimer = new Stopwatch()..start(); | 147 var loadTimer = new Stopwatch()..start(); |
148 collectSources(sources.forUri2(entryUri), files); | 148 collectSources(sources.forUri2(entryUri), files); |
149 | 149 |
(...skipping 10 matching lines...) Expand all Loading... |
160 "dart:typed_data", | 160 "dart:typed_data", |
161 "dart:io" | 161 "dart:io" |
162 ]; | 162 ]; |
163 | 163 |
164 for (var lib in libs) { | 164 for (var lib in libs) { |
165 collectSources(sources.forUri(lib), files); | 165 collectSources(sources.forUri(lib), files); |
166 } | 166 } |
167 | 167 |
168 loadTimer.stop(); | 168 loadTimer.stop(); |
169 | 169 |
170 print('input size: ${scanTotalChars} chars'); | 170 print('input size: $scanTotalChars chars'); |
171 var loadTime = loadTimer.elapsedMicroseconds - scanTimer.elapsedMicroseconds; | 171 var loadTime = loadTimer.elapsedMicroseconds - scanTimer.elapsedMicroseconds; |
172 report("load", loadTime); | 172 report("load", loadTime); |
173 report("scan", scanTimer.elapsedMicroseconds); | 173 report("scan", scanTimer.elapsedMicroseconds); |
174 return files; | 174 return files; |
175 } | 175 } |
176 | 176 |
177 /// Sets up analyzer to be able to load and resolve app, packages, and sdk | 177 /// Sets up analyzer to be able to load and resolve app, packages, and sdk |
178 /// sources. | 178 /// sources. |
179 Future setup(Uri entryUri) async { | 179 Future setup(Uri entryUri) async { |
180 var provider = PhysicalResourceProvider.INSTANCE; | 180 var provider = PhysicalResourceProvider.INSTANCE; |
(...skipping 14 matching lines...) Expand all Loading... |
195 scanTotalChars += contents.length; | 195 scanTotalChars += contents.length; |
196 // TODO(sigmund): is there a way to scan from a random-access-file without | 196 // TODO(sigmund): is there a way to scan from a random-access-file without |
197 // first converting to String? | 197 // first converting to String? |
198 var scanner = new Scanner(source, new CharSequenceReader(contents), | 198 var scanner = new Scanner(source, new CharSequenceReader(contents), |
199 AnalysisErrorListener.NULL_LISTENER) | 199 AnalysisErrorListener.NULL_LISTENER) |
200 ..preserveComments = false; | 200 ..preserveComments = false; |
201 var token = scanner.tokenize(); | 201 var token = scanner.tokenize(); |
202 scanTimer.stop(); | 202 scanTimer.stop(); |
203 return token; | 203 return token; |
204 } | 204 } |
OLD | NEW |