| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of dart2js.helpers; | 5 part of dart2js.helpers; |
| 6 | 6 |
| 7 // Helper methods for statistics. | 7 // Helper methods for statistics. |
| 8 | 8 |
| 9 /// Current stats collector. Use [enableStatsOutput] to enable recording of | 9 /// Current stats collector. Use [enableStatsOutput] to enable recording of |
| 10 /// stats. | 10 /// stats. |
| 11 Stats get stats { | 11 Stats get stats { |
| 12 enableDebugMode(); |
| 12 if (_stats == null) { | 13 if (_stats == null) { |
| 13 _stats = const Stats(); | 14 _stats = const Stats(); |
| 14 } | 15 } |
| 15 return _stats; | 16 return _stats; |
| 16 } | 17 } |
| 17 | 18 |
| 18 Stats _stats; | 19 Stats _stats; |
| 19 | 20 |
| 20 /// Enable recording of stats. Use [Stats.dumpStats] to output the record stats. | 21 /// Enable recording of stats. Use [Stats.dumpStats] to output the record stats. |
| 21 /// | 22 /// |
| 22 /// Pass the [outputProvider] of [Compiler] to generate stats into a separate | 23 /// Pass the [outputProvider] of [Compiler] to generate stats into a separate |
| 23 /// file using [name] and [extension] for the filename. If omitted, stats are | 24 /// file using [name] and [extension] for the filename. If omitted, stats are |
| 24 /// printed on standard out. | 25 /// printed on standard out. |
| 25 /// | 26 /// |
| 26 /// If [xml] is `true`, stats output is formatted as XML with a default | 27 /// If [xml] is `true`, stats output is formatted as XML with a default |
| 27 /// extension of 'xml', otherwise the output is indented text with a default | 28 /// extension of 'xml', otherwise the output is indented text with a default |
| 28 /// extension of 'log'. | 29 /// extension of 'log'. |
| 29 void enableStatsOutput({CompilerOutputProvider outputProvider, | 30 void enableStatsOutput({CompilerOutputProvider outputProvider, |
| 30 bool xml: true, | 31 bool xml: true, |
| 31 String name: 'stats', | 32 String name: 'stats', |
| 32 String extension, | 33 String extension, |
| 33 int examples: 10}) { | 34 int examples: 10}) { |
| 34 if (_stats != null) { | 35 if (_stats != null) { |
| 35 throw new StateError('Stats have already been initialized.'); | 36 throw new StateError('Stats have already been initialized.'); |
| 36 } | 37 } |
| 38 enableDebugMode(); |
| 39 |
| 37 StatsOutput output; | 40 StatsOutput output; |
| 38 if (outputProvider != null) { | 41 if (outputProvider != null) { |
| 39 if (extension == null) { | 42 if (extension == null) { |
| 40 extension = xml ? 'xml' : 'log'; | 43 extension = xml ? 'xml' : 'log'; |
| 41 } | 44 } |
| 42 output = new SinkOutput(outputProvider(name, extension)); | 45 output = new SinkOutput(outputProvider(name, extension)); |
| 43 } else { | 46 } else { |
| 44 output = const DebugOutput(); | 47 output = const DebugOutput(); |
| 45 } | 48 } |
| 46 StatsPrinter printer; | 49 StatsPrinter printer; |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 /// Returns a new map in which the keys of [map] are sorted using [compare]. | 779 /// Returns a new map in which the keys of [map] are sorted using [compare]. |
| 777 /// If [compare] is null, the keys must be [Comparable]. | 780 /// If [compare] is null, the keys must be [Comparable]. |
| 778 Map sortMap(Map map, [int compare(a,b)]) { | 781 Map sortMap(Map map, [int compare(a,b)]) { |
| 779 List keys = map.keys.toList(); | 782 List keys = map.keys.toList(); |
| 780 keys.sort(compare); | 783 keys.sort(compare); |
| 781 Map sortedMap = new Map(); | 784 Map sortedMap = new Map(); |
| 782 keys.forEach((k) => sortedMap[k] = map[k]); | 785 keys.forEach((k) => sortedMap[k] = map[k]); |
| 783 return sortedMap; | 786 return sortedMap; |
| 784 } | 787 } |
| 785 | 788 |
| OLD | NEW |