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

Side by Side Diff: runtime/third_party/binary_size/src/template/test-data-generator.html

Issue 1754443002: - Add binary size analysis tool from Chromium. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 <!DOCTYPE html>
2 <!--
3 Copyright 2014 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7 <html>
8 <head>
9 <script>
10 function rnd(max) {
11 return Math.round(Math.random()*max);
12 }
13
14 function gen() {
15 var dirs1=['usr1', 'etc1', 'var1'];
16 var dirs2=['aaa2', 'bbb2', 'ccc2', 'ddd2', 'eee2', 'fff2', 'ggg2', 'hhh2',
17 'frobozz2', 'kazaam2', 'shazam2'];
18 var dirs3=['iii3', 'jjj3', 'kkk3', 'lll3', 'mmm3', 'nnn3', 'ooo3', 'ppp3',
19 'wonderllama3', 'excelsior3', 'src3'];
20 var filenames=['awesome.cc', 'rad.h', 'tubular.cxx', 'cool.cc', 'groovy.h',
21 'excellent.c', 'gnarly.h', 'green.C', 'articulate.cc'];
22 //All possible types (we only see a subset in practice): 'ABbCDdGgiNpRrSsTtUuV vWw-?';
23 var nm_symbol_types = 'trd';
24 var minSize = 4;
25 var maxSize = 10000;
26 var numGen = 300000;
27 var text = 'var nm_data=[\n';
28 var vtablePercent = 5;
29 for (var x=0; x<numGen; x++) {
30 var path = '/' +
31 dirs1[rnd(dirs1.length - 1)] + '/' +
32 dirs2[rnd(dirs2.length - 1)] + '/' +
33 dirs3[rnd(dirs3.length - 1)] + '/' +
34 filenames[rnd(filenames.length - 1)];
35 var isVtable = Math.floor((Math.random()*100)+1) <= vtablePercent;
36 var size = rnd(maxSize);
37 var symbol_name;
38 var type;
39 if (!isVtable) {
40 symbol_name = 'sym' + x.toString(16);
41 type = nm_symbol_types.charAt(rnd(nm_symbol_types.length - 1));
42 } else {
43 symbol_name = 'vtable for ' + x.toString(16);
44 type = '@'
45 }
46 text = text + "{'n': '" + symbol_name +
47 "', 't': '" + type +
48 "', 's': " + size +
49 ", 'p': '" + path + "'},\n";
50 }
51 text += '];';
52
53 eval(text);
54 var treeified = to_d3_tree(nm_data);
55 generateDownloadLink('tree_data=' + JSON.stringify(treeified));
56 }
57
58 function generateDownloadLink(content) {
59 var blob = new Blob([content], {type: 'text/plain'});
60 var link = document.createElement('a');
61 link.download = 'generated-content.txt';
62 link.href = window.URL.createObjectURL(blob);
63 link.textContent = 'Download ready, click here.';
64 link.dataset.downloadurl = ['text/plain', link.download, link.href].join(':');
65 link.onclick = function(e) {
66 if ('disabled' in this.dataset) { return false; }
67 link.dataset.disabled = true;
68 setTimeout(function() { window.URL.revokeObjectURL(link.href); }, 1500);
69 };
70 document.getElementById('linkcontainer').innerHTML = '';
71 document.getElementById('linkcontainer').appendChild(link);
72 }
73
74 /**
75 * This function takes in an array of nm records and converts them into a
76 * hierarchical data structure suitable for use in a d3-base treemap layout.
77 * Leaves are individual symbols. The parents of the leaves are logical
78 * groupings by common symbol-type (for BSS, read-only data, code, etc).
79 * Above this, each node represents part of a filesystem path relative
80 * to the parent node. The root node has the name '/', and represents
81 * a root (though not necessarily THE root) of a file system traversal.
82 * The root node also has a special property, 'maxDepth', to which is bound
83 * the deepest level of nesting that was found during conversion: for the
84 * record at path /a/b/c/d.foo, the maxDepth will be 6; the file 'd.foo'
85 * is at depth 4, the type-bucket is depth 5 and the symbols are depth 6.
86 */
87 function to_d3_tree(records) {
88 var result = {'n': '/', 'children': [], 'k': 'p'};
89 var maxDepth = 0;
90 //{'n': 'symbol1', 't': 'b', 's': 1000, 'p': '/usr/local/foo/foo.cc'},
91 for (index in records) {
92 var record = records[index];
93 var parts = record.p.split("/");
94 var node = result;
95 var depth = 0;
96 // Walk the tree and find the file that is named by the "location"
97 // field of the record. We create any intermediate nodes required.
98 // This is directly analogous to "mkdir -p".
99 while(parts.length > 0) {
100 var part = parts.shift();
101 if (part.length == 0) continue;
102 depth++;
103 node = _mk_child(node, part, record.s);
104 node.k = 'p'; // p for path
105 }
106 node.lastPathElement = true;
107
108 // 'node' is now the file node. Find the symbol-type bucket.
109 node = _mk_child(node, record.t, record.s);
110 node.t = record.t;
111 node.k = 'b'; // b for bucket
112 depth++;
113 // 'node' is now the symbol-type bucket. Make the child entry.
114 node = _mk_child(node, record.n, record.s);
115 delete node.children;
116 node.value = record.s;
117 node.t = record.t;
118 node.k = 's'; // s for symbol
119 depth++;
120
121 maxDepth = Math.max(maxDepth, depth);
122 }
123 result.maxDepth = maxDepth;
124 return result;
125 }
126
127 /**
128 * Given a node and a name, return the child within node.children whose
129 * name matches the specified name. If necessary, a new child node is
130 * created and appended to node.children.
131 * If this method creates a new node, the 'name' attribute is set to the
132 * specified name and the 'children' attribute is an empty array, and
133 * total_size is the specified size. Otherwise, the existing node is
134 * returned and its total_size value is incremented by the specified size.
135 */
136 function _mk_child(node, name, size) {
137 var child = undefined;
138 for (child_index in node.children) {
139 if (node.children[child_index].n == name) {
140 child = node.children[child_index];
141 }
142 }
143 if (child === undefined) {
144 child = {'n': name, 'children': []};
145 node.children.push(child);
146 }
147 return child;
148 }
149 </script>
150 </head>
151 <body style='white-space: pre; font-family: monospace;'>
152 This script generates sample data for use in D3SymbolTreeMap, and can be used
153 for testing.
154 <input type=button onclick='gen();' value='Generate data'></input>
155 <div id='linkcontainer'></div>
156 </body>
157 </html>
OLDNEW
« no previous file with comments | « runtime/third_party/binary_size/src/template/index.html ('k') | runtime/third_party/d3/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698