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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer_cli/lib/src/driver.dart
diff --git a/pkg/analyzer_cli/lib/src/driver.dart b/pkg/analyzer_cli/lib/src/driver.dart
index f69e935f5dd49b5fa33944eed2c51ab043a17303..f190b78e43a9220af3f6ca95664327a546a1f3bf 100644
--- a/pkg/analyzer_cli/lib/src/driver.dart
+++ b/pkg/analyzer_cli/lib/src/driver.dart
@@ -25,6 +25,8 @@ import 'package:analyzer/src/generated/java_io.dart';
import 'package:analyzer/src/generated/sdk_io.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/source_io.dart';
+import 'package:analyzer/src/generated/utilities_general.dart'
+ show PerformanceTag;
import 'package:analyzer/src/services/lint.dart';
import 'package:analyzer/src/task/options.dart';
import 'package:analyzer_cli/src/analyzer_impl.dart';
@@ -88,6 +90,8 @@ class Driver {
/// Use the given command-line [args] to start this analysis driver.
void start(List<String> args) {
+ int startTime = new DateTime.now().millisecondsSinceEpoch;
+
StringUtilities.INTERNER = new MappedInterner();
_processPlugins();
@@ -111,10 +115,23 @@ class Driver {
exitCode = severity.ordinal;
}
}
+
+ if (options.perfLog != null) {
+ _writePerfLog(options.perfLog, startTime);
+ }
}
- /// Perform analysis according to the given [options].
ErrorSeverity _analyzeAll(CommandLineOptions options) {
+ return _analyzeAllTag.makeCurrentWhile(() {
+ return _analyzeAllImpl(options);
+ });
+ }
+
+ static final PerformanceTag _analyzeAllTag =
+ new PerformanceTag("Driver._analyzeAll");
+
+ /// Perform analysis according to the given [options].
+ ErrorSeverity _analyzeAllImpl(CommandLineOptions options) {
if (!options.machineFormat) {
outSink.writeln("Analyzing ${options.sourceFiles}...");
}
@@ -190,6 +207,38 @@ class Driver {
return allResult;
}
+ static _writePerfLog(String filename, int startTime) {
+ int totalTime = currentTimeMillis() - startTime;
+ int otherTime = totalTime;
+
+ // Convert performance tags to JSON representation.
+ var json = <String, dynamic>{};
+ for (PerformanceTag tag in PerformanceTag.all) {
+ if (tag != PerformanceTag.UNKNOWN) {
+ int tagTime = tag.elapsedMs;
+ json[tag.label] = tagTime;
+ otherTime -= tagTime;
+ }
+ }
+ json['other'] = otherTime;
+ json['total'] = totalTime;
+
+ // Pretty-print the JSON, one line per value for readability.
+ var buf = new StringBuffer();
Paul Berry 2015/12/16 15:11:26 There's already library code available to pretty-p
skybrian 2015/12/16 18:48:10 Thanks!
+ buf.writeln("{");
+ var firstLine = true;
+ for (var key in json.keys) {
+ if (!firstLine) buf.writeln(",");
Brian Wilkerson 2015/12/16 15:08:43 style nit: we always use blocks for 'if's.
+ var val = json[key];
+ buf.write(' "$key": ${JSON.encode(val)}');
+ firstLine = false;
+ }
+ buf.writeln("\n}");
Brian Wilkerson 2015/12/16 15:08:43 nit: seems strange to have a newline explicitly in
+
+ // Save to disk.
+ new File(filename).writeAsStringSync(buf.toString());
+ }
+
/// Determine whether the context created during a previous call to
/// [_analyzeAll] can be re-used in order to analyze using [options].
bool _canContextBeReused(CommandLineOptions options) {

Powered by Google App Engine
This is Rietveld 408576698