OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library analyzer_cli.src.perf_report; | |
6 | |
7 import 'dart:convert' show JsonEncoder; | |
8 import 'dart:io' show File, Platform; | |
9 | |
10 import 'package:analyzer/src/generated/utilities_general.dart' | |
11 show PerformanceTag; | |
12 import 'package:analyzer_cli/src/options.dart' show CommandLineOptions; | |
13 | |
14 const _JSON = const JsonEncoder.withIndent(" "); | |
15 | |
16 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
| |
17 int totalTime = endTime - startTime; | |
18 int otherTime = totalTime; | |
19 | |
20 var platformJson = <String, dynamic>{ | |
21 'osType': _osType, | |
22 'dartSdkVersion': Platform.version, | |
23 'checkedMode': _isCheckedMode, | |
24 }; | |
25 | |
26 var optionsJson = <String, dynamic>{ | |
27 'dartSdkPath': options.dartSdkPath, | |
28 'strongMode': options.strongMode, | |
29 'showPackageWarnings': options.showPackageWarnings, | |
30 'showSdkWarnings': options.showSdkWarnings, | |
31 'definedVariables': options.definedVariables, | |
32 'packageRootPath': options.packageRootPath, | |
33 'packageConfigPath': options.packageConfigPath, | |
34 'sourceFiles': options.sourceFiles, | |
35 }; | |
36 | |
37 // Convert performance tags to JSON representation. | |
38 var perfTagsJson = <String, dynamic>{}; | |
39 for (PerformanceTag tag in PerformanceTag.all) { | |
40 if (tag != PerformanceTag.UNKNOWN) { | |
41 int tagTime = tag.elapsedMs; | |
42 perfTagsJson[tag.label] = tagTime; | |
43 otherTime -= tagTime; | |
44 } | |
45 } | |
46 perfTagsJson['other'] = otherTime; | |
47 | |
48 var json = <String, dynamic>{ | |
49 'platform': platformJson, | |
50 'options': optionsJson, | |
51 'totalElapsedTime': totalTime, | |
52 'performanceTags': perfTagsJson | |
53 }; | |
54 | |
55 return _JSON.convert(json); | |
56 } | |
57 | |
58 bool _isCheckedMode = () { | |
59 bool x = true; | |
60 try { | |
61 // Trigger an exception if we're in checked mode. | |
62 x = "" as dynamic; | |
63 return x != ""; // return false; suppress unused variable warning | |
64 } catch (e) { | |
65 return true; | |
66 } | |
67 }(); | |
68 | |
69 String _osType = () { | |
70 if (Platform.isLinux) { | |
71 return "linux"; | |
72 } else if (Platform.isMacOS) { | |
73 return "mac"; | |
74 } else if (Platform.isWindows) { | |
75 return "windows"; | |
76 } else if (Platform.isAndroid) { | |
77 return "android"; | |
78 } else { | |
79 return "unknown"; | |
80 } | |
81 }(); | |
OLD | NEW |