Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: bin/inference/print_summary.dart

Issue 1372333002: Add measurements and send-metrics to dart2js's info. (Closed) Base URL: git@github.com:dart-lang/dart2js_info.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 /// Utility to display statistics about "sends" as a table on the command line.
6 library compiler.tool.stats.print_summary;
7
8 import 'dart:io';
9 import 'dart:convert';
10 import 'package:dart2js_info/info.dart';
11 import 'package:dart2js_info/src/table.dart';
12
13 main(args) {
14 var file = args.length > 0 ? args[0] : 'out.js.info.json';
15 var json = JSON.decode(new File(file).readAsStringSync());
16 var results = AllInfo.parseFromJson(json);
17 print(formatAsTable(results));
18 }
19
20 /// Formats [results] as a table.
21 String formatAsTable(AllInfo all) {
22 var visitor = new _Counter();
23 all.accept(visitor);
24 var table = new Table();
25 table.declareColumn('bundle');
26
27 int colorIndex = 0;
28 visitAllMetrics((m, _) {
29 if (m is GroupedMetric) colorIndex = (colorIndex + 1) % _groupColors.length;
30 table.declareColumn(m.name,
31 abbreviate: true, color: _groupColors[colorIndex]);
32 });
33 table.addHeader();
34 appendCount(n) => table.addEntry(n == null ? 0 : n);
35
36 for (var bundle in visitor.bundleTotals.keys) {
37 table.addEntry(bundle);
38 visitAllMetrics(
39 (m, _) => appendCount(visitor.bundleTotals[bundle].counters[m]));
40 }
41 table.addEmptyRow();
42 table.addHeader();
43 table.addEntry('total');
44 visitAllMetrics((m, _) => appendCount(visitor.totals.counters[m]));
45
46 appendPercent(count, total) {
47 if (count == null) count = 0;
48 if (total == null) total = 0;
49 var percent = count * 100 / total;
50 table.addEntry(percent == 100 ? 100 : percent.toStringAsFixed(2));
51 }
52
53 table.addEntry('%');
54 visitAllMetrics((metric, parents) {
55 if (parents == null || parents.isEmpty) {
56 table.addEntry(100);
57 } else {
58 appendPercent(
59 visitor.totals.counters[metric], visitor.totals.counters[parents[0]]);
60 }
61 });
62
63 return table.toString();
64 }
65
66 /// Visitor that adds up results for all functions in libraries, and all
67 /// libraries in a bundle.
68 class _Counter extends RecursiveInfoVisitor {
69 Map<String, Measurements> bundleTotals = {};
70 Measurements currentBundleTotals;
71 Measurements totals = new Measurements();
72
73 visitLibrary(LibraryInfo info) {
74 var uri = info.uri;
75 var bundle = uri.scheme == 'package'
76 ? uri.pathSegments.first
77 : uri.scheme == 'file' ? uri.pathSegments.last : '$uri';
78 currentBundleTotals =
79 bundleTotals.putIfAbsent(bundle, () => new Measurements());
80 super.visitLibrary(info);
81 totals.addFrom(currentBundleTotals);
82 }
83
84 visitFunction(FunctionInfo function) {
85 var measurements = function.measurements;
86 if (measurements == null) return;
87 currentBundleTotals.addFrom(measurements);
88 }
89 }
90
91 const _groupColors = const [_YELLOW_COLOR, _NO_COLOR];
92
93 const _NO_COLOR = "\x1b[0m";
94 const _GREEN_COLOR = "\x1b[32m";
95 const _YELLOW_COLOR = "\x1b[33m";
96 const _WHITE_COLOR = "\x1b[37m";
OLDNEW
« no previous file with comments | « bin/inference/index.html ('k') | bin/inference/server.dart » ('j') | lib/src/table.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698