Index: pkg/analyzer_cli/lib/src/perf_report.dart |
diff --git a/pkg/analyzer_cli/lib/src/perf_report.dart b/pkg/analyzer_cli/lib/src/perf_report.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1b8164e740b962101f446f52f06e252b85791acd |
--- /dev/null |
+++ b/pkg/analyzer_cli/lib/src/perf_report.dart |
@@ -0,0 +1,81 @@ |
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+library analyzer_cli.src.perf_report; |
+ |
+import 'dart:convert' show JsonEncoder; |
+import 'dart:io' show File, Platform; |
+ |
+import 'package:analyzer/src/generated/utilities_general.dart' |
+ show PerformanceTag; |
+import 'package:analyzer_cli/src/options.dart' show CommandLineOptions; |
+ |
+const _JSON = const JsonEncoder.withIndent(" "); |
+ |
+String makePerfReport(int startTime, int endTime, CommandLineOptions options) { |
Brian Wilkerson
2015/12/17 15:05:41
We should add a version number to the output so th
|
+ int totalTime = endTime - startTime; |
+ int otherTime = totalTime; |
+ |
+ var platformJson = <String, dynamic>{ |
+ 'osType': _osType, |
+ 'dartSdkVersion': Platform.version, |
+ 'checkedMode': _isCheckedMode, |
+ }; |
+ |
+ var optionsJson = <String, dynamic>{ |
+ 'dartSdkPath': options.dartSdkPath, |
+ 'strongMode': options.strongMode, |
+ 'showPackageWarnings': options.showPackageWarnings, |
+ 'showSdkWarnings': options.showSdkWarnings, |
+ 'definedVariables': options.definedVariables, |
+ 'packageRootPath': options.packageRootPath, |
+ 'packageConfigPath': options.packageConfigPath, |
+ 'sourceFiles': options.sourceFiles, |
+ }; |
+ |
+ // Convert performance tags to JSON representation. |
+ var perfTagsJson = <String, dynamic>{}; |
+ for (PerformanceTag tag in PerformanceTag.all) { |
+ if (tag != PerformanceTag.UNKNOWN) { |
+ int tagTime = tag.elapsedMs; |
+ perfTagsJson[tag.label] = tagTime; |
+ otherTime -= tagTime; |
+ } |
+ } |
+ perfTagsJson['other'] = otherTime; |
+ |
+ var json = <String, dynamic>{ |
+ 'platform': platformJson, |
+ 'options': optionsJson, |
+ 'totalElapsedTime': totalTime, |
+ 'performanceTags': perfTagsJson |
+ }; |
+ |
+ return _JSON.convert(json); |
+} |
+ |
+bool _isCheckedMode = () { |
+ bool x = true; |
+ try { |
+ // Trigger an exception if we're in checked mode. |
+ x = "" as dynamic; |
+ return x != ""; // return false; suppress unused variable warning |
+ } catch (e) { |
+ return true; |
+ } |
+}(); |
+ |
+String _osType = () { |
+ if (Platform.isLinux) { |
+ return "linux"; |
+ } else if (Platform.isMacOS) { |
+ return "mac"; |
+ } else if (Platform.isWindows) { |
+ return "windows"; |
+ } else if (Platform.isAndroid) { |
+ return "android"; |
+ } else { |
+ return "unknown"; |
+ } |
+}(); |