Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: pkg/front_end/tool/fasta_perf.dart

Issue 2834543002: Remove use of package:analyzer in dependency_grapher (Closed)
Patch Set: cl comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/front_end/test/subpackage_relationships_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 fasta and measure its performance. 5 /// An entrypoint used to run portions of fasta and measure its performance.
6 library front_end.tool.fasta_perf; 6 library front_end.tool.fasta_perf;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import 'package:analyzer/src/fasta/ast_builder.dart'; 11 import 'package:analyzer/src/fasta/ast_builder.dart';
12 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; 12 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget;
13 import 'package:front_end/src/fasta/kernel/kernel_target.dart' 13 import 'package:front_end/src/fasta/kernel/kernel_target.dart'
14 show KernelTarget; 14 show KernelTarget;
15 import 'package:front_end/src/fasta/parser.dart'; 15 import 'package:front_end/src/fasta/parser.dart';
16 import 'package:front_end/src/fasta/source/directive_listener.dart';
16 import 'package:front_end/src/fasta/scanner.dart'; 17 import 'package:front_end/src/fasta/scanner.dart';
17 import 'package:front_end/src/fasta/scanner/io.dart' show readBytesFromFileSync; 18 import 'package:front_end/src/fasta/scanner/io.dart' show readBytesFromFileSync;
18 import 'package:front_end/src/fasta/ticker.dart' show Ticker; 19 import 'package:front_end/src/fasta/ticker.dart' show Ticker;
19 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; 20 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri;
20 import 'package:front_end/src/fasta/translate_uri.dart'; 21 import 'package:front_end/src/fasta/translate_uri.dart';
21 22
22 /// Cumulative total number of chars scanned. 23 /// Cumulative total number of chars scanned.
23 int inputSize = 0; 24 int inputSize = 0;
24 25
25 /// Cumulative time spent scanning. 26 /// Cumulative time spent scanning.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 helper(uri.resolve(directiveUri)); 150 helper(uri.resolve(directiveUri));
150 } 151 }
151 } 152 }
152 153
153 helper(start); 154 helper(start);
154 } 155 }
155 156
156 /// Parse [contents] as a Dart program and return the URIs that appear in its 157 /// Parse [contents] as a Dart program and return the URIs that appear in its
157 /// import, export, and part directives. 158 /// import, export, and part directives.
158 Set<String> extractDirectiveUris(List<int> contents) { 159 Set<String> extractDirectiveUris(List<int> contents) {
159 var listener = new DirectiveListener(); 160 var listener = new DirectiveListener(acceptsNativeClause: true);
160 new DirectiveParser(listener).parseUnit(tokenize(contents)); 161 new TopLevelParser(listener).parseUnit(tokenize(contents));
161 return listener.uris; 162 return new Set<String>()
162 } 163 ..addAll(listener.imports)
163 164 ..addAll(listener.exports)
164 /// Diet parser that stops eagerly at the first sign that we have seen all the 165 ..addAll(listener.parts);
165 /// import, export, and part directives.
166 class DirectiveParser extends ClassMemberParser {
167 DirectiveParser(listener) : super(listener);
168
169 static final _endToken = new SymbolToken.eof(-1);
170
171 Token parseClassOrNamedMixinApplication(Token token) => _endToken;
172 Token parseEnum(Token token) => _endToken;
173 parseTypedef(token) => _endToken;
174 parseTopLevelMember(Token token) => _endToken;
175 }
176
177 /// Listener that records the URIs from imports, exports, and part directives.
178 class DirectiveListener extends Listener {
179 bool _inDirective = false;
180 Set<String> uris = new Set<String>();
181
182 void _enterDirective() {
183 _inDirective = true;
184 }
185
186 void _exitDirective() {
187 _inDirective = false;
188 }
189
190 beginImport(_) => _enterDirective();
191 beginExport(_) => _enterDirective();
192 beginPart(_) => _enterDirective();
193
194 endExport(export, semicolon) => _exitDirective();
195 endImport(import, deferred, asKeyword, semicolon) => _exitDirective();
196 endPart(part, semicolon) => _exitDirective();
197
198 void beginLiteralString(Token token) {
199 if (_inDirective) {
200 var quotedString = token.lexeme;
201 uris.add(quotedString.substring(1, quotedString.length - 1));
202 }
203 }
204 } 166 }
205 167
206 /// Parses every file in [files] and reports the time spent doing so. 168 /// Parses every file in [files] and reports the time spent doing so.
207 void parseFiles(Map<Uri, List<int>> files) { 169 void parseFiles(Map<Uri, List<int>> files) {
208 scanTimer = new Stopwatch(); 170 scanTimer = new Stopwatch();
209 var parseTimer = new Stopwatch()..start(); 171 var parseTimer = new Stopwatch()..start();
210 files.forEach((uri, source) { 172 files.forEach((uri, source) {
211 parseFull(uri, source); 173 parseFull(uri, source);
212 }); 174 });
213 parseTimer.stop(); 175 parseTimer.stop();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 /// Report that metric [name] took [time] micro-seconds to process 245 /// Report that metric [name] took [time] micro-seconds to process
284 /// [inputSize] characters. 246 /// [inputSize] characters.
285 void report(String name, int time) { 247 void report(String name, int time) {
286 var sb = new StringBuffer(); 248 var sb = new StringBuffer();
287 var padding = ' ' * (20 - name.length); 249 var padding = ' ' * (20 - name.length);
288 sb.write('$name:$padding $time us, ${time ~/ 1000} ms'); 250 sb.write('$name:$padding $time us, ${time ~/ 1000} ms');
289 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2); 251 var invSpeed = (time * 1000 / inputSize).toStringAsFixed(2);
290 sb.write(', $invSpeed ns/char'); 252 sb.write(', $invSpeed ns/char');
291 print('$sb'); 253 print('$sb');
292 } 254 }
OLDNEW
« no previous file with comments | « pkg/front_end/test/subpackage_relationships_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698