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

Side by Side Diff: pkg/analyzer/benchmark/errors_in_all_libraries.dart

Issue 1821313002: Add a simple benchmark for analysis and error reporting. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | 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
(Empty)
1 #!/usr/bin/env dart
2 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file.
5
6 /// Resolves this library and everything it transitively imports and generates
7 /// errors in all of those libraries. Does this in an infinite loop, starting
8 /// from scratch each time, to show how VM warm-up affects things and to make
9 /// it easier to connect to this with observatory.
10 import 'dart:io';
11
12 import 'package:path/path.dart' as p;
13
14 import 'package:analyzer/dart/element/element.dart';
15 import 'package:analyzer/src/generated/engine.dart';
16 import 'package:analyzer/src/generated/java_io.dart';
17 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
18 import 'package:analyzer/src/generated/source.dart';
19 import 'package:analyzer/src/generated/source_io.dart';
20
21 void main(List<String> args) {
22 JavaSystemIO.setProperty(
23 "com.google.dart.sdk",
24 p.normalize(
25 p.join(p.dirname(p.fromUri(Platform.script)), "../../../sdk")));
26
27 // Assumes you have run "pub get" in the analyzer directory itself and uses
28 // that "packages" directory as its package root.
29 var packageRoot =
30 p.normalize(p.join(p.dirname(p.fromUri(Platform.script)), "packages"));
31
32 var best = new Duration(days: 1);
33 while (true) {
34 var start = new DateTime.now();
35 AnalysisEngine.instance.clearCaches();
36
37 var context = AnalysisEngine.instance.createAnalysisContext();
38 context.sourceFactory = new SourceFactory([
39 new DartUriResolver(DirectoryBasedDartSdk.defaultSdk),
40 new FileUriResolver(),
41 new PackageUriResolver([new JavaFile(packageRoot)])
42 ]);
43
44 context.analysisOptions.strongMode = true;
45 context.analysisOptions.strongModeHints = true;
46
47 var mainSource =
48 new FileBasedSource(new JavaFile(p.fromUri(Platform.script)));
49 context.applyChanges(new ChangeSet()..addedSource(mainSource));
50
51 var initialLibrary =
52 context.resolveCompilationUnit2(mainSource, mainSource);
53
54 // Walk all of the transitively referenced libraries and compute errors.
55 var errorCount = 0;
56 var allLibraries = _reachableLibraries(initialLibrary.element.library);
57 for (var lib in allLibraries) {
58 for (var unit in lib.units) {
59 var source = unit.source;
60
61 // Skip core libraries.
62 if (source.uri.scheme == 'dart') continue;
63
64 var librarySource = context.getLibrariesContaining(source).single;
65 context.resolveCompilationUnit2(source, librarySource);
66 errorCount += context.computeErrors(source).length;
67 }
68 }
69
70 var elapsed = new DateTime.now().difference(start);
71 print("$elapsed : $errorCount errors ${elapsed < best ? "(best)" : ""}");
72 if (elapsed < best) best = elapsed;
73 }
74 }
75
76 /// Returns all libraries transitively imported or exported from [start].
77 List<LibraryElement> _reachableLibraries(LibraryElement start) {
78 var results = <LibraryElement>[];
79 var seen = new Set();
80 void find(LibraryElement lib) {
81 if (seen.contains(lib)) return;
82 seen.add(lib);
83 results.add(lib);
84 lib.importedLibraries.forEach(find);
85 lib.exportedLibraries.forEach(find);
86 }
87 find(start);
88 return results;
89 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698