Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013, 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 part of dart2js; | |
|
ahe
2013/11/27 17:59:18
This should be its own library.
sigurdm
2013/11/29 10:39:37
Done.
| |
| 6 | |
| 7 // TODO (sigurdm) A search function. | |
| 8 // TODO (sigurdm) Output size of classes. | |
| 9 // TODO (sigurdm) Print that we dumped the HTML-file. | |
| 10 // TODO (sigurdm) Include why a given element was included in the output. | |
| 11 // TODO (sigurdm) Include how much output grew because of mirror support. | |
| 12 // TODO (sigurdm) Write each function with parameter names. | |
| 13 // TODO (sigurdm) Write how much space the boilerplate takes. | |
| 14 | |
| 15 class CodeSizeCounter { | |
| 16 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
| |
| 17 | |
| 18 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.
| |
| 19 _generatedSize.putIfAbsent(element, () => 0); | |
| 20 | |
| 21 countCode(Element element, int added) { | |
|
ahe
2013/11/27 19:28:53
Add void.
sigurdm
2013/11/29 10:39:37
Done.
| |
| 22 int before = _generatedSize.putIfAbsent(element, () => 0); | |
| 23 _generatedSize[element] = before + added; | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 void dumpInfoHtml(Map info, StringSink buffer) { | |
| 28 int totalSize = info['generated size']; | |
| 29 void dumpElement(Map description, {String indent: ""}) { | |
| 30 var esc = const HtmlEscape().convert; | |
| 31 if (description['presentation'] == 'code') { | |
| 32 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
| |
| 33 '<code>${esc(description['text'])}</code>'); | |
| 34 } else { | |
| 35 String kind = '<span class="kind">${esc(description["kind"])}</span>'; | |
| 36 String modifiers = '<span class="modifiers">' | |
| 37 '${esc(description["modifiers"])}</span>'; | |
| 38 String size = description.containsKey("size") ? | |
| 39 'Size: <span class="size">${description["size"]} bytes ' | |
| 40 '(${description["size"] * 100 ~/ totalSize}%)</span>' : ''; | |
| 41 String name = '<span class="name">${esc(description["name"])}</span>'; | |
| 42 String type = '<span class="type">${esc(description["type"])}</span>'; | |
| 43 String describe = [kind, modifiers, name, size, type].join(' '); | |
| 44 | |
| 45 if (description.containsKey("contents")) { | |
| 46 buffer.write('<div class="container">'); | |
| 47 buffer.writeln("$indent+"+describe); | |
| 48 buffer.write("</div>"); | |
| 49 buffer.write('<div class="contained">'); | |
| 50 if (description["contents"].isEmpty) { | |
| 51 buffer.writeln("No members"); | |
| 52 } | |
| 53 for (Object subElementDescription in description["contents"]) { | |
| 54 dumpElement(subElementDescription, indent: indent + " "); | |
| 55 } | |
| 56 buffer.write("</div>"); | |
| 57 } else { | |
| 58 buffer.writeln(indent+describe); | |
| 59 } | |
| 60 } | |
| 61 } | |
| 62 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.
| |
| 63 buffer.writeln("<head>"); | |
| 64 buffer.writeln("<title>Dart2JS compilation information</title>"); | |
| 65 buffer.writeln( | |
| 66 '<script src="http://ajax.googleapis.com/' | |
| 67 '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
| |
| 68 '<script src="http://ajax.googleapis.com/' | |
| 69 'ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>' | |
| 70 '<style>' | |
| 71 'div.show {display:block;}' | |
| 72 'div.contained {display:none;}' | |
| 73 'div {margin-top:0px;' | |
| 74 ' margin-bottom: 0px;' | |
| 75 ' white-space: pre; /*border: 1px solid;*/}' | |
| 76 'span.kind {font-weight:bold;}' | |
| 77 'span.modifiers {font-weight:bold;}' | |
| 78 'span.name {font-style:italic}' | |
| 79 'span.type {color:blue;}' | |
| 80 '</style>'); | |
| 81 buffer.writeln("</head>"); | |
| 82 buffer.writeln("<body>"); | |
| 83 buffer.writeln("<h1>Dart2js compilation information</h1>"); | |
| 84 buffer.writeln('<h2>Compilation took place: ' | |
| 85 '${info["compilation time"]}</h2>'); | |
| 86 buffer.writeln('<h2>Compilation took: ' | |
| 87 '${info["compilation duration"]/1000000} seconds</h2>'); | |
| 88 buffer.writeln('<h2>Output size: ${info["generated size"]} bytes</h2>'); | |
| 89 if (info.containsKey("dart2js version")) { | |
| 90 buffer.writeln('<h2>Dart2js version: ${info["dart2js version"]}</h2>'); | |
| 91 } | |
| 92 for (Map library in info["libraries"]) { | |
| 93 dumpElement(library); | |
| 94 } | |
| 95 buffer.writeln("</body>"); | |
| 96 buffer.writeln("<script>"); | |
| 97 buffer.writeln(r'$(".container").click(function(event) {' | |
| 98 r' event.stopPropagation();' | |
| 99 r' $(this).next().toggle("slide", {direction: "up"});' | |
| 100 r'});'); | |
| 101 buffer.writeln("</script>"); | |
| 102 buffer.writeln("<html>"); | |
| 103 } | |
| OLD | NEW |