| 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_cli/src/options.dart' show CommandLineOptions; | 13 import 'package:analyzer_cli/src/options.dart' show CommandLineOptions; |
| 13 | 14 |
| 14 const _JSON = const JsonEncoder.withIndent(" "); | 15 const _JSON = const JsonEncoder.withIndent(" "); |
| 15 | 16 |
| 16 bool _isCheckedMode = () { | 17 bool _isCheckedMode = () { |
| 17 bool x = true; | 18 bool x = true; |
| 18 try { | 19 try { |
| 19 // Trigger an exception if we're in checked mode. | 20 // Trigger an exception if we're in checked mode. |
| 20 x = "" as dynamic; | 21 x = "" as dynamic; |
| 21 return x != ""; // return false; suppress unused variable warning | 22 return x != ""; // return false; suppress unused variable warning |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 var perfTagsJson = <String, dynamic>{}; | 64 var perfTagsJson = <String, dynamic>{}; |
| 64 for (PerformanceTag tag in PerformanceTag.all) { | 65 for (PerformanceTag tag in PerformanceTag.all) { |
| 65 if (tag != PerformanceTag.UNKNOWN) { | 66 if (tag != PerformanceTag.UNKNOWN) { |
| 66 int tagTime = tag.elapsedMs; | 67 int tagTime = tag.elapsedMs; |
| 67 perfTagsJson[tag.label] = tagTime; | 68 perfTagsJson[tag.label] = tagTime; |
| 68 otherTime -= tagTime; | 69 otherTime -= tagTime; |
| 69 } | 70 } |
| 70 } | 71 } |
| 71 perfTagsJson['other'] = otherTime; | 72 perfTagsJson['other'] = otherTime; |
| 72 | 73 |
| 73 var json = <String, dynamic>{ | 74 // Generate task table. |
| 75 var taskRows = <_TaskRow>[]; |
| 76 int totalTaskTime = 0; |
| 77 for (var key in AnalysisTask.stopwatchMap.keys) { |
| 78 var time = AnalysisTask.stopwatchMap[key].elapsedMilliseconds; |
| 79 if (time == 0) continue; |
| 80 totalTaskTime += time; |
| 81 var count = AnalysisTask.countMap[key]; |
| 82 taskRows.add(new _TaskRow(key.toString(), time, count)); |
| 83 } |
| 84 taskRows.sort((a, b) => b.time.compareTo(a.time)); |
| 85 |
| 86 var reportJson = <String, dynamic>{ |
| 74 'perfReportVersion': 0, | 87 'perfReportVersion': 0, |
| 75 'platform': platformJson, | 88 'platform': platformJson, |
| 76 'options': optionsJson, | 89 'options': optionsJson, |
| 77 'totalElapsedTime': totalTime, | 90 'totalElapsedTime': totalTime, |
| 78 'performanceTags': perfTagsJson | 91 'totalTaskTime': totalTaskTime, |
| 92 'performanceTags': perfTagsJson, |
| 93 'tasks': taskRows.map((r) => r.toJson()).toList(), |
| 79 }; | 94 }; |
| 80 | 95 |
| 81 return _JSON.convert(json); | 96 return _JSON.convert(reportJson); |
| 82 } | 97 } |
| 98 |
| 99 class _TaskRow { |
| 100 final String name; |
| 101 final int time; |
| 102 final int count; |
| 103 _TaskRow(this.name, this.time, this.count); |
| 104 |
| 105 Map toJson() => <String, dynamic>{'name': name, 'time': time, 'count': count}; |
| 106 } |
| OLD | NEW |