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

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

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 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 | « packages/analyzer/README.md ('k') | packages/analyzer/doc/support/dart.js » ('j') | 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:analyzer/dart/element/element.dart';
13 import 'package:analyzer/file_system/file_system.dart';
14 import 'package:analyzer/file_system/physical_file_system.dart';
15 import 'package:analyzer/source/package_map_resolver.dart';
16 import 'package:analyzer/src/context/builder.dart';
17 import 'package:analyzer/src/dart/sdk/sdk.dart';
18 import 'package:analyzer/src/generated/engine.dart';
19 import 'package:analyzer/src/generated/source.dart';
20 import 'package:analyzer/src/generated/source_io.dart';
21 import 'package:analyzer/src/source/source_resource.dart';
22 import 'package:path/path.dart' as p;
23
24 void main(List<String> args) {
25 // Assumes you have run "pub get" in the analyzer directory itself and uses
26 // that "packages" directory as its package root.
27 var packageRoot =
28 p.normalize(p.join(p.dirname(p.fromUri(Platform.script)), "packages"));
29
30 var best = new Duration(days: 1);
31 while (true) {
32 var start = new DateTime.now();
33 AnalysisEngine.instance.clearCaches();
34
35 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
36 options.strongMode = true;
37 options.strongModeHints = true;
38
39 PhysicalResourceProvider resourceProvider =
40 PhysicalResourceProvider.INSTANCE;
41 FolderBasedDartSdk sdk = new FolderBasedDartSdk(
42 resourceProvider, resourceProvider.getFolder(args[0]));
43 sdk.analysisOptions = options;
44
45 ContextBuilder builder = new ContextBuilder(resourceProvider, null, null);
46 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
47 context.sourceFactory = new SourceFactory([
48 new DartUriResolver(sdk),
49 new ResourceUriResolver(resourceProvider),
50 new PackageMapUriResolver(resourceProvider,
51 builder.convertPackagesToMap(builder.createPackageMap(packageRoot)))
52 ]);
53 context.analysisOptions = options;
54
55 var mainSource =
56 new FileSource(resourceProvider.getFile(p.fromUri(Platform.script)));
57 context.applyChanges(new ChangeSet()..addedSource(mainSource));
58
59 var initialLibrary =
60 context.resolveCompilationUnit2(mainSource, mainSource);
61
62 // Walk all of the transitively referenced libraries and compute errors.
63 var errorCount = 0;
64 var allLibraries = _reachableLibraries(initialLibrary.element.library);
65 for (var lib in allLibraries) {
66 for (var unit in lib.units) {
67 var source = unit.source;
68
69 // Skip core libraries.
70 if (source.uri.scheme == 'dart') continue;
71
72 var librarySource = context.getLibrariesContaining(source).single;
73 context.resolveCompilationUnit2(source, librarySource);
74 errorCount += context.computeErrors(source).length;
75 }
76 }
77
78 var elapsed = new DateTime.now().difference(start);
79 print("$elapsed : $errorCount errors ${elapsed < best ? "(best)" : ""}");
80 if (elapsed < best) best = elapsed;
81 }
82 }
83
84 /// Returns all libraries transitively imported or exported from [start].
85 List<LibraryElement> _reachableLibraries(LibraryElement start) {
86 var results = <LibraryElement>[];
87 var seen = new Set();
88 void find(LibraryElement lib) {
89 if (seen.contains(lib)) return;
90 seen.add(lib);
91 results.add(lib);
92 lib.importedLibraries.forEach(find);
93 lib.exportedLibraries.forEach(find);
94 }
95
96 find(start);
97 return results;
98 }
OLDNEW
« no previous file with comments | « packages/analyzer/README.md ('k') | packages/analyzer/doc/support/dart.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698