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

Side by Side Diff: pkg/analyzer_cli/lib/src/driver.dart

Issue 1524413002: Add --x-perf-report flag to the dartanalyzer command (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: add a test Created 5 years 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library analyzer_cli.src.driver; 5 library analyzer_cli.src.driver;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import 'package:analyzer/file_system/file_system.dart' as fileSystem; 11 import 'package:analyzer/file_system/file_system.dart' as fileSystem;
12 import 'package:analyzer/file_system/physical_file_system.dart'; 12 import 'package:analyzer/file_system/physical_file_system.dart';
13 import 'package:analyzer/plugin/options.dart'; 13 import 'package:analyzer/plugin/options.dart';
14 import 'package:analyzer/source/analysis_options_provider.dart'; 14 import 'package:analyzer/source/analysis_options_provider.dart';
15 import 'package:analyzer/source/package_map_provider.dart'; 15 import 'package:analyzer/source/package_map_provider.dart';
16 import 'package:analyzer/source/package_map_resolver.dart'; 16 import 'package:analyzer/source/package_map_resolver.dart';
17 import 'package:analyzer/source/pub_package_map_provider.dart'; 17 import 'package:analyzer/source/pub_package_map_provider.dart';
18 import 'package:analyzer/source/sdk_ext.dart'; 18 import 'package:analyzer/source/sdk_ext.dart';
19 import 'package:analyzer/src/generated/constant.dart'; 19 import 'package:analyzer/src/generated/constant.dart';
20 import 'package:analyzer/src/generated/engine.dart'; 20 import 'package:analyzer/src/generated/engine.dart';
21 import 'package:analyzer/src/generated/error.dart'; 21 import 'package:analyzer/src/generated/error.dart';
22 import 'package:analyzer/src/generated/interner.dart'; 22 import 'package:analyzer/src/generated/interner.dart';
23 import 'package:analyzer/src/generated/java_engine.dart'; 23 import 'package:analyzer/src/generated/java_engine.dart';
24 import 'package:analyzer/src/generated/java_io.dart'; 24 import 'package:analyzer/src/generated/java_io.dart';
25 import 'package:analyzer/src/generated/sdk_io.dart'; 25 import 'package:analyzer/src/generated/sdk_io.dart';
26 import 'package:analyzer/src/generated/source.dart'; 26 import 'package:analyzer/src/generated/source.dart';
27 import 'package:analyzer/src/generated/source_io.dart'; 27 import 'package:analyzer/src/generated/source_io.dart';
28 import 'package:analyzer/src/generated/utilities_general.dart'
29 show PerformanceTag;
28 import 'package:analyzer/src/services/lint.dart'; 30 import 'package:analyzer/src/services/lint.dart';
29 import 'package:analyzer/src/task/options.dart'; 31 import 'package:analyzer/src/task/options.dart';
30 import 'package:analyzer_cli/src/analyzer_impl.dart'; 32 import 'package:analyzer_cli/src/analyzer_impl.dart';
31 import 'package:analyzer_cli/src/options.dart'; 33 import 'package:analyzer_cli/src/options.dart';
34 import 'package:analyzer_cli/src/perf_report.dart';
32 import 'package:linter/src/plugin/linter_plugin.dart'; 35 import 'package:linter/src/plugin/linter_plugin.dart';
33 import 'package:package_config/discovery.dart' as pkgDiscovery; 36 import 'package:package_config/discovery.dart' as pkgDiscovery;
34 import 'package:package_config/packages.dart' show Packages; 37 import 'package:package_config/packages.dart' show Packages;
35 import 'package:package_config/packages_file.dart' as pkgfile show parse; 38 import 'package:package_config/packages_file.dart' as pkgfile show parse;
36 import 'package:package_config/src/packages_impl.dart' show MapPackages; 39 import 'package:package_config/src/packages_impl.dart' show MapPackages;
37 import 'package:path/path.dart' as path; 40 import 'package:path/path.dart' as path;
38 import 'package:plugin/manager.dart'; 41 import 'package:plugin/manager.dart';
39 import 'package:plugin/plugin.dart'; 42 import 'package:plugin/plugin.dart';
40 import 'package:yaml/yaml.dart'; 43 import 'package:yaml/yaml.dart';
41 44
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 /// *Visible for testing.* 80 /// *Visible for testing.*
78 AnalysisContext get context => _context; 81 AnalysisContext get context => _context;
79 82
80 /// Set the [plugins] that are defined outside the `analyzer_cli` package. 83 /// Set the [plugins] that are defined outside the `analyzer_cli` package.
81 void set userDefinedPlugins(List<Plugin> plugins) { 84 void set userDefinedPlugins(List<Plugin> plugins) {
82 _userDefinedPlugins = plugins == null ? <Plugin>[] : plugins; 85 _userDefinedPlugins = plugins == null ? <Plugin>[] : plugins;
83 } 86 }
84 87
85 /// Use the given command-line [args] to start this analysis driver. 88 /// Use the given command-line [args] to start this analysis driver.
86 void start(List<String> args) { 89 void start(List<String> args) {
90 int startTime = new DateTime.now().millisecondsSinceEpoch;
91
87 StringUtilities.INTERNER = new MappedInterner(); 92 StringUtilities.INTERNER = new MappedInterner();
88 93
89 _processPlugins(); 94 _processPlugins();
90 95
91 // Parse commandline options. 96 // Parse commandline options.
92 CommandLineOptions options = CommandLineOptions.parse(args); 97 CommandLineOptions options = CommandLineOptions.parse(args);
93 98
94 // Cache options of interest to inform analysis. 99 // Cache options of interest to inform analysis.
95 _setupEnv(options); 100 _setupEnv(options);
96 101
97 // Do analysis. 102 // Do analysis.
98 if (_isBatch) { 103 if (_isBatch) {
99 _BatchRunner.runAsBatch(args, (List<String> args) { 104 _BatchRunner.runAsBatch(args, (List<String> args) {
100 CommandLineOptions options = CommandLineOptions.parse(args); 105 CommandLineOptions options = CommandLineOptions.parse(args);
101 return _analyzeAll(options); 106 return _analyzeAll(options);
102 }); 107 });
103 } else { 108 } else {
104 ErrorSeverity severity = _analyzeAll(options); 109 ErrorSeverity severity = _analyzeAll(options);
105 // In case of error propagate exit code. 110 // In case of error propagate exit code.
106 if (severity == ErrorSeverity.ERROR) { 111 if (severity == ErrorSeverity.ERROR) {
107 exitCode = severity.ordinal; 112 exitCode = severity.ordinal;
108 } 113 }
109 } 114 }
115
116 if (options.perfReport != null) {
117 String json = makePerfReport(startTime, currentTimeMillis(), options);
118 new File(options.perfReport).writeAsStringSync(json);
119 }
110 } 120 }
111 121
122 ErrorSeverity _analyzeAll(CommandLineOptions options) {
123 return _analyzeAllTag.makeCurrentWhile(() {
124 return _analyzeAllImpl(options);
125 });
126 }
127
128 static final PerformanceTag _analyzeAllTag =
129 new PerformanceTag("Driver._analyzeAll");
130
112 /// Perform analysis according to the given [options]. 131 /// Perform analysis according to the given [options].
113 ErrorSeverity _analyzeAll(CommandLineOptions options) { 132 ErrorSeverity _analyzeAllImpl(CommandLineOptions options) {
114 if (!options.machineFormat) { 133 if (!options.machineFormat) {
115 outSink.writeln("Analyzing ${options.sourceFiles}..."); 134 outSink.writeln("Analyzing ${options.sourceFiles}...");
116 } 135 }
117 136
118 // Create a context, or re-use the previous one. 137 // Create a context, or re-use the previous one.
119 try { 138 try {
120 _createAnalysisContext(options); 139 _createAnalysisContext(options);
121 } on _DriverError catch (error) { 140 } on _DriverError catch (error) {
122 outSink.writeln(error.msg); 141 outSink.writeln(error.msg);
123 return ErrorSeverity.ERROR; 142 return ErrorSeverity.ERROR;
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 for (var package in packages) { 649 for (var package in packages) {
631 var packageName = path.basename(package.path); 650 var packageName = path.basename(package.path);
632 var realPath = package.resolveSymbolicLinksSync(); 651 var realPath = package.resolveSymbolicLinksSync();
633 result[packageName] = [ 652 result[packageName] = [
634 PhysicalResourceProvider.INSTANCE.getFolder(realPath) 653 PhysicalResourceProvider.INSTANCE.getFolder(realPath)
635 ]; 654 ];
636 } 655 }
637 return result; 656 return result;
638 } 657 }
639 } 658 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698