Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/dump_info.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/dump_info.dart b/sdk/lib/_internal/compiler/implementation/dump_info.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c33823edf952f38730c0084e9e03cc9e32257db2 |
| --- /dev/null |
| +++ b/sdk/lib/_internal/compiler/implementation/dump_info.dart |
| @@ -0,0 +1,103 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +part of dart2js; |
|
ahe
2013/11/27 17:59:18
This should be its own library.
sigurdm
2013/11/29 10:39:37
Done.
|
| + |
| +// TODO (sigurdm) A search function. |
| +// TODO (sigurdm) Output size of classes. |
| +// TODO (sigurdm) Print that we dumped the HTML-file. |
| +// TODO (sigurdm) Include why a given element was included in the output. |
| +// TODO (sigurdm) Include how much output grew because of mirror support. |
| +// TODO (sigurdm) Write each function with parameter names. |
| +// TODO (sigurdm) Write how much space the boilerplate takes. |
| + |
| +class CodeSizeCounter { |
| + final Map<Element, int> _generatedSize = new Map<Element, int>(); |
|
ahe
2013/11/27 19:28:53
Why is this field private?
sigurdm
2013/11/29 10:39:37
Because I miss a map with a default answer.
But I
|
| + |
| + int generatedSize(Element element) => |
|
ahe
2013/11/27 19:28:53
I find this method rather peculiar. Sounds like a
ahe
2013/11/27 19:28:53
Please use "return" when it doesn't fit on one lin
sigurdm
2013/11/29 10:39:37
Done.
|
| + _generatedSize.putIfAbsent(element, () => 0); |
| + |
| + countCode(Element element, int added) { |
|
ahe
2013/11/27 19:28:53
Add void.
sigurdm
2013/11/29 10:39:37
Done.
|
| + int before = _generatedSize.putIfAbsent(element, () => 0); |
| + _generatedSize[element] = before + added; |
| + } |
| +} |
| + |
| +void dumpInfoHtml(Map info, StringSink buffer) { |
| + int totalSize = info['generated size']; |
| + void dumpElement(Map description, {String indent: ""}) { |
| + var esc = const HtmlEscape().convert; |
| + if (description['presentation'] == 'code') { |
| + buffer.write('<div class="kind">${description['name']}</div>' |
|
karlklose
2013/11/27 14:19:23
You could define helpers for these, like:
String s
sigurdm
2013/11/29 10:39:37
Nice idea, done
|
| + '<code>${esc(description['text'])}</code>'); |
| + } else { |
| + String kind = '<span class="kind">${esc(description["kind"])}</span>'; |
| + String modifiers = '<span class="modifiers">' |
| + '${esc(description["modifiers"])}</span>'; |
| + String size = description.containsKey("size") ? |
| + 'Size: <span class="size">${description["size"]} bytes ' |
| + '(${description["size"] * 100 ~/ totalSize}%)</span>' : ''; |
| + String name = '<span class="name">${esc(description["name"])}</span>'; |
| + String type = '<span class="type">${esc(description["type"])}</span>'; |
| + String describe = [kind, modifiers, name, size, type].join(' '); |
| + |
| + if (description.containsKey("contents")) { |
| + buffer.write('<div class="container">'); |
| + buffer.writeln("$indent+"+describe); |
| + buffer.write("</div>"); |
| + buffer.write('<div class="contained">'); |
| + if (description["contents"].isEmpty) { |
| + buffer.writeln("No members"); |
| + } |
| + for (Object subElementDescription in description["contents"]) { |
| + dumpElement(subElementDescription, indent: indent + " "); |
| + } |
| + buffer.write("</div>"); |
| + } else { |
| + buffer.writeln(indent+describe); |
| + } |
| + } |
| + } |
| + buffer.writeln("<html>"); |
|
ahe
2013/11/27 19:28:53
I feel this code could benefit tremendously from u
sigurdm
2013/11/29 10:39:37
Done.
|
| + buffer.writeln("<head>"); |
| + buffer.writeln("<title>Dart2JS compilation information</title>"); |
| + buffer.writeln( |
| + '<script src="http://ajax.googleapis.com/' |
| + 'ajax/libs/jquery/2.0.3/jquery.min.js"></script>' |
|
ahe
2013/11/27 17:59:18
WTF?
sigurdm
2013/11/29 10:39:37
I removed the folding view - we need a way to spec
|
| + '<script src="http://ajax.googleapis.com/' |
| + 'ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>' |
| + '<style>' |
| + 'div.show {display:block;}' |
| + 'div.contained {display:none;}' |
| + 'div {margin-top:0px;' |
| + ' margin-bottom: 0px;' |
| + ' white-space: pre; /*border: 1px solid;*/}' |
| + 'span.kind {font-weight:bold;}' |
| + 'span.modifiers {font-weight:bold;}' |
| + 'span.name {font-style:italic}' |
| + 'span.type {color:blue;}' |
| + '</style>'); |
| + buffer.writeln("</head>"); |
| + buffer.writeln("<body>"); |
| + buffer.writeln("<h1>Dart2js compilation information</h1>"); |
| + buffer.writeln('<h2>Compilation took place: ' |
| + '${info["compilation time"]}</h2>'); |
| + buffer.writeln('<h2>Compilation took: ' |
| + '${info["compilation duration"]/1000000} seconds</h2>'); |
| + buffer.writeln('<h2>Output size: ${info["generated size"]} bytes</h2>'); |
| + if (info.containsKey("dart2js version")) { |
| + buffer.writeln('<h2>Dart2js version: ${info["dart2js version"]}</h2>'); |
| + } |
| + for (Map library in info["libraries"]) { |
| + dumpElement(library); |
| + } |
| + buffer.writeln("</body>"); |
| + buffer.writeln("<script>"); |
| + buffer.writeln(r'$(".container").click(function(event) {' |
| + r' event.stopPropagation();' |
| + r' $(this).next().toggle("slide", {direction: "up"});' |
| + r'});'); |
| + buffer.writeln("</script>"); |
| + buffer.writeln("<html>"); |
| +} |