OLD | NEW |
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.perf_report; | 5 library analyzer_cli.src.perf_report; |
6 | 6 |
7 import 'dart:convert' show JsonEncoder; | 7 import 'dart:convert' show JsonEncoder; |
8 import 'dart:io' show File, Platform; | 8 import 'dart:io' show File, Platform; |
9 | 9 |
10 import 'package:analyzer/src/generated/utilities_general.dart' | 10 import 'package:analyzer/src/generated/utilities_general.dart' |
11 show PerformanceTag; | 11 show PerformanceTag; |
12 import 'package:analyzer/task/model.dart' show AnalysisTask; | 12 import 'package:analyzer/task/model.dart' show AnalysisTask; |
| 13 import 'package:analyzer_cli/src/error_formatter.dart'; |
13 import 'package:analyzer_cli/src/options.dart' show CommandLineOptions; | 14 import 'package:analyzer_cli/src/options.dart' show CommandLineOptions; |
| 15 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; |
14 | 16 |
15 const _JSON = const JsonEncoder.withIndent(" "); | 17 const _JSON = const JsonEncoder.withIndent(" "); |
16 | 18 |
17 bool _isCheckedMode = () { | 19 bool _isCheckedMode = () { |
18 bool x = true; | 20 bool x = true; |
19 try { | 21 try { |
20 // Trigger an exception if we're in checked mode. | 22 // Trigger an exception if we're in checked mode. |
21 x = "" as dynamic; | 23 x = "" as dynamic; |
22 return x != ""; // return false; suppress unused variable warning | 24 return x != ""; // return false; suppress unused variable warning |
23 } catch (e) { | 25 } catch (e) { |
24 return true; | 26 return true; |
25 } | 27 } |
26 }(); | 28 }(); |
27 | 29 |
28 String _osType = () { | 30 String _osType = () { |
29 if (Platform.isLinux) { | 31 if (Platform.isLinux) { |
30 return "linux"; | 32 return "linux"; |
31 } else if (Platform.isMacOS) { | 33 } else if (Platform.isMacOS) { |
32 return "mac"; | 34 return "mac"; |
33 } else if (Platform.isWindows) { | 35 } else if (Platform.isWindows) { |
34 return "windows"; | 36 return "windows"; |
35 } else if (Platform.isAndroid) { | 37 } else if (Platform.isAndroid) { |
36 return "android"; | 38 return "android"; |
37 } else { | 39 } else { |
38 return "unknown"; | 40 return "unknown"; |
39 } | 41 } |
40 }(); | 42 }(); |
41 | 43 |
42 String makePerfReport(int startTime, int endTime, CommandLineOptions options) { | 44 String makePerfReport(int startTime, int endTime, CommandLineOptions options, |
| 45 AnalysisContext context) { |
43 int totalTime = endTime - startTime; | 46 int totalTime = endTime - startTime; |
44 int otherTime = totalTime; | 47 int otherTime = totalTime; |
45 | 48 |
46 var platformJson = <String, dynamic>{ | 49 var platformJson = <String, dynamic>{ |
47 'osType': _osType, | 50 'osType': _osType, |
48 'dartSdkVersion': Platform.version, | 51 'dartSdkVersion': Platform.version, |
49 'checkedMode': _isCheckedMode, | 52 'checkedMode': _isCheckedMode, |
50 }; | 53 }; |
51 | 54 |
52 var optionsJson = <String, dynamic>{ | 55 var optionsJson = <String, dynamic>{ |
53 'dartSdkPath': options.dartSdkPath, | 56 'dartSdkPath': options.dartSdkPath, |
54 'strongMode': options.strongMode, | 57 'strongMode': options.strongMode, |
55 'showPackageWarnings': options.showPackageWarnings, | 58 'showPackageWarnings': options.showPackageWarnings, |
| 59 'showPackageWarningsPrefix': options.showPackageWarningsPrefix, |
56 'showSdkWarnings': options.showSdkWarnings, | 60 'showSdkWarnings': options.showSdkWarnings, |
57 'definedVariables': options.definedVariables, | 61 'definedVariables': options.definedVariables, |
58 'packageRootPath': options.packageRootPath, | 62 'packageRootPath': options.packageRootPath, |
59 'packageConfigPath': options.packageConfigPath, | 63 'packageConfigPath': options.packageConfigPath, |
60 'sourceFiles': options.sourceFiles, | 64 'sourceFiles': options.sourceFiles, |
61 }; | 65 }; |
62 | 66 |
63 // Convert performance tags to JSON representation. | 67 // Convert performance tags to JSON representation. |
64 var perfTagsJson = <String, dynamic>{}; | 68 var perfTagsJson = <String, dynamic>{}; |
65 for (PerformanceTag tag in PerformanceTag.all) { | 69 for (PerformanceTag tag in PerformanceTag.all) { |
(...skipping 16 matching lines...) Expand all Loading... |
82 taskRows.add(new _TaskRow(key.toString(), time, count)); | 86 taskRows.add(new _TaskRow(key.toString(), time, count)); |
83 } | 87 } |
84 taskRows.sort((a, b) => b.time.compareTo(a.time)); | 88 taskRows.sort((a, b) => b.time.compareTo(a.time)); |
85 | 89 |
86 var reportJson = <String, dynamic>{ | 90 var reportJson = <String, dynamic>{ |
87 'perfReportVersion': 0, | 91 'perfReportVersion': 0, |
88 'platform': platformJson, | 92 'platform': platformJson, |
89 'options': optionsJson, | 93 'options': optionsJson, |
90 'totalElapsedTime': totalTime, | 94 'totalElapsedTime': totalTime, |
91 'totalTaskTime': totalTaskTime, | 95 'totalTaskTime': totalTaskTime, |
| 96 'analyzedFiles': context.sources.length, |
| 97 'generatedDiagnostics': ErrorFormatter.inputErrorCount, |
92 'performanceTags': perfTagsJson, | 98 'performanceTags': perfTagsJson, |
93 'tasks': taskRows.map((r) => r.toJson()).toList(), | 99 'tasks': taskRows.map((r) => r.toJson()).toList(), |
94 }; | 100 }; |
95 | 101 |
96 return _JSON.convert(reportJson); | 102 return _JSON.convert(reportJson); |
97 } | 103 } |
98 | 104 |
99 class _TaskRow { | 105 class _TaskRow { |
100 final String name; | 106 final String name; |
101 final int time; | 107 final int time; |
102 final int count; | 108 final int count; |
103 _TaskRow(this.name, this.time, this.count); | 109 _TaskRow(this.name, this.time, this.count); |
104 | 110 |
105 Map toJson() => <String, dynamic>{'name': name, 'time': time, 'count': count}; | 111 Map toJson() => <String, dynamic>{'name': name, 'time': time, 'count': count}; |
106 } | 112 } |
OLD | NEW |