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

Unified Diff: pkg/analyzer_cli/tool/perf.dart

Issue 2933753002: Run the sorter to reduce code churn (Closed)
Patch Set: Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer_cli/test/utils.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer_cli/tool/perf.dart
diff --git a/pkg/analyzer_cli/tool/perf.dart b/pkg/analyzer_cli/tool/perf.dart
index 5c5a24302cc08e10db2043a19219421f6b6ab504..b5e3729722b1210f52c52944e7df260d8c2fc915 100644
--- a/pkg/analyzer_cli/tool/perf.dart
+++ b/pkg/analyzer_cli/tool/perf.dart
@@ -24,15 +24,6 @@ import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/source_io.dart';
import 'package:package_config/discovery.dart';
-/// Cumulative total number of chars scanned.
-int scanTotalChars = 0;
-
-/// Cumulative time spent scanning.
-Stopwatch scanTimer = new Stopwatch();
-
-/// Factory to load and resolve app, packages, and sdk sources.
-SourceFactory sources;
-
main(List<String> args) async {
// TODO(sigmund): provide sdk folder as well.
if (args.length < 2) {
@@ -64,56 +55,36 @@ main(List<String> args) async {
report("total", totalTimer.elapsedMicroseconds);
}
-/// Sets up analyzer to be able to load and resolve app, packages, and sdk
-/// sources.
-Future setup(Uri entryUri) async {
- var provider = PhysicalResourceProvider.INSTANCE;
- var packageMap = new ContextBuilder(provider, null, null)
- .convertPackagesToMap(await findPackages(entryUri));
- sources = new SourceFactory([
- new ResourceUriResolver(provider),
- new PackageMapUriResolver(provider, packageMap),
- new DartUriResolver(
- new FolderBasedDartSdk(provider, provider.getFolder("sdk"))),
- ]);
-}
+/// Cumulative time spent scanning.
+Stopwatch scanTimer = new Stopwatch();
-/// Load and scans all files we need to process: files reachable from the
-/// entrypoint and all core libraries automatically included by the VM.
-Set<Source> scanReachableFiles(Uri entryUri) {
- var files = new Set<Source>();
- var loadTimer = new Stopwatch()..start();
- collectSources(sources.forUri2(entryUri), files);
+/// Cumulative total number of chars scanned.
+int scanTotalChars = 0;
- var libs = [
- "dart:async",
- "dart:collection",
- "dart:convert",
- "dart:core",
- "dart:developer",
- "dart:_internal",
- "dart:isolate",
- "dart:math",
- "dart:mirrors",
- "dart:typed_data",
- "dart:io"
- ];
+/// Factory to load and resolve app, packages, and sdk sources.
+SourceFactory sources;
- for (var lib in libs) {
- collectSources(sources.forUri(lib), files);
+/// Add to [files] all sources reachable from [start].
+void collectSources(Source start, Set<Source> files) {
+ if (!files.add(start)) return;
+ var unit = parseDirectives(start);
+ for (var directive in unit.directives) {
+ if (directive is UriBasedDirective) {
+ var next = sources.resolveUri(start, directive.uri.stringValue);
+ collectSources(next, files);
+ }
}
+}
- loadTimer.stop();
-
- print('input size: ${scanTotalChars} chars');
- var loadTime = loadTimer.elapsedMicroseconds - scanTimer.elapsedMicroseconds;
- report("load", loadTime);
- report("scan", scanTimer.elapsedMicroseconds);
- return files;
+/// Uses the diet-parser to parse only directives in [source].
+CompilationUnit parseDirectives(Source source) {
+ var token = tokenize(source);
+ var parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER);
+ return parser.parseDirectives(token);
}
-/// Scans every file in [files] and reports the time spent doing so.
-void scanFiles(Set<Source> files) {
+/// Parses every file in [files] and reports the time spent doing so.
+void parseFiles(Set<Source> files) {
// The code below will record again how many chars are scanned and how long it
// takes to scan them, even though we already did so in [scanReachableFiles].
// Recording and reporting this twice is unnecessary, but we do so for now to
@@ -121,17 +92,38 @@ void scanFiles(Set<Source> files) {
scanTimer = new Stopwatch();
var old = scanTotalChars;
scanTotalChars = 0;
+ var parseTimer = new Stopwatch()..start();
for (var source in files) {
- tokenize(source);
+ parseFull(source);
}
+ parseTimer.stop();
// Report size and scanning time again. See discussion above.
if (old != scanTotalChars) print('input size changed? ${old} chars');
report("scan", scanTimer.elapsedMicroseconds);
+
+ var pTime = parseTimer.elapsedMicroseconds - scanTimer.elapsedMicroseconds;
+ report("parse", pTime);
}
-/// Parses every file in [files] and reports the time spent doing so.
-void parseFiles(Set<Source> files) {
+/// Parse the full body of [source] and return it's compilation unit.
+CompilationUnit parseFull(Source source) {
+ var token = tokenize(source);
+ var parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER);
+ return parser.parseCompilationUnit(token);
+}
+
+/// Report that metric [name] took [time] micro-seconds to process
+/// [scanTotalChars] characters.
+void report(String name, int time) {
+ var sb = new StringBuffer();
+ sb.write('$name: $time us, ${time ~/ 1000} ms');
+ sb.write(', ${scanTotalChars * 1000 ~/ time} chars/ms');
+ print('$sb');
+}
+
+/// Scans every file in [files] and reports the time spent doing so.
+void scanFiles(Set<Source> files) {
// The code below will record again how many chars are scanned and how long it
// takes to scan them, even though we already did so in [scanReachableFiles].
// Recording and reporting this twice is unnecessary, but we do so for now to
@@ -139,44 +131,61 @@ void parseFiles(Set<Source> files) {
scanTimer = new Stopwatch();
var old = scanTotalChars;
scanTotalChars = 0;
- var parseTimer = new Stopwatch()..start();
for (var source in files) {
- parseFull(source);
+ tokenize(source);
}
- parseTimer.stop();
// Report size and scanning time again. See discussion above.
if (old != scanTotalChars) print('input size changed? ${old} chars');
report("scan", scanTimer.elapsedMicroseconds);
-
- var pTime = parseTimer.elapsedMicroseconds - scanTimer.elapsedMicroseconds;
- report("parse", pTime);
}
-/// Add to [files] all sources reachable from [start].
-void collectSources(Source start, Set<Source> files) {
- if (!files.add(start)) return;
- var unit = parseDirectives(start);
- for (var directive in unit.directives) {
- if (directive is UriBasedDirective) {
- var next = sources.resolveUri(start, directive.uri.stringValue);
- collectSources(next, files);
- }
+/// Load and scans all files we need to process: files reachable from the
+/// entrypoint and all core libraries automatically included by the VM.
+Set<Source> scanReachableFiles(Uri entryUri) {
+ var files = new Set<Source>();
+ var loadTimer = new Stopwatch()..start();
+ collectSources(sources.forUri2(entryUri), files);
+
+ var libs = [
+ "dart:async",
+ "dart:collection",
+ "dart:convert",
+ "dart:core",
+ "dart:developer",
+ "dart:_internal",
+ "dart:isolate",
+ "dart:math",
+ "dart:mirrors",
+ "dart:typed_data",
+ "dart:io"
+ ];
+
+ for (var lib in libs) {
+ collectSources(sources.forUri(lib), files);
}
-}
-/// Uses the diet-parser to parse only directives in [source].
-CompilationUnit parseDirectives(Source source) {
- var token = tokenize(source);
- var parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER);
- return parser.parseDirectives(token);
+ loadTimer.stop();
+
+ print('input size: ${scanTotalChars} chars');
+ var loadTime = loadTimer.elapsedMicroseconds - scanTimer.elapsedMicroseconds;
+ report("load", loadTime);
+ report("scan", scanTimer.elapsedMicroseconds);
+ return files;
}
-/// Parse the full body of [source] and return it's compilation unit.
-CompilationUnit parseFull(Source source) {
- var token = tokenize(source);
- var parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER);
- return parser.parseCompilationUnit(token);
+/// Sets up analyzer to be able to load and resolve app, packages, and sdk
+/// sources.
+Future setup(Uri entryUri) async {
+ var provider = PhysicalResourceProvider.INSTANCE;
+ var packageMap = new ContextBuilder(provider, null, null)
+ .convertPackagesToMap(await findPackages(entryUri));
+ sources = new SourceFactory([
+ new ResourceUriResolver(provider),
+ new PackageMapUriResolver(provider, packageMap),
+ new DartUriResolver(
+ new FolderBasedDartSdk(provider, provider.getFolder("sdk"))),
+ ]);
}
/// Scan [source] and return the first token produced by the scanner.
@@ -193,12 +202,3 @@ Token tokenize(Source source) {
scanTimer.stop();
return token;
}
-
-/// Report that metric [name] took [time] micro-seconds to process
-/// [scanTotalChars] characters.
-void report(String name, int time) {
- var sb = new StringBuffer();
- sb.write('$name: $time us, ${time ~/ 1000} ms');
- sb.write(', ${scanTotalChars * 1000 ~/ time} chars/ms');
- print('$sb');
-}
« no previous file with comments | « pkg/analyzer_cli/test/utils.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698