Synchronize Android relocation packer source with AOSP.
[chromium-blink-merge.git] / tools / win / sizeviewer / main.js
blobb716319a734aed393490d1550214ab42a59a1117
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 google.load("visualization", "1", {packages:["treemap"]});
6 google.setOnLoadCallback(drawChart);
7 function drawChart() {
8 var data = google.visualization.arrayToDataTable(g_raw_data);
10 tree = new google.visualization.TreeMap(
11 document.getElementById('chart_div'));
13 tree.draw(data, {
14 minColor: '#faa',
15 midColor: '#f77',
16 maxColor: '#f44',
17 headerHeight: 20,
18 fontColor: 'black',
19 showScale: true,
20 minColorValue: 0,
21 maxColorValue: g_maxval,
22 generateTooltip: tooltip
23 });
25 // Update from 'Loading'.
26 document.getElementById('title').innerText = g_dllname;
28 // Set favicon.
29 var doc_head = document.getElementsByTagName('head')[0];
30 var new_link = document.createElement('link');
31 new_link.rel = 'shortcut icon';
32 new_link.href = 'data:image/png;base64,'+g_favicon;
33 doc_head.appendChild(new_link);
35 var cur_line_sizes = null;
36 function nodeSelect() {
37 symlist.setValue('');
38 var selected = tree.getSelection();
39 if (selected.length > 0) {
40 var filename = data.getValue(selected[0].row, 0);
41 var size = data.getValue(selected[0].row, 2);
42 if (size >= 0) {
43 // Is a leaf.
44 cur_line_sizes = g_line_data[filename];
45 var body = g_file_contents[filename];
46 editor.setValue(body);
47 var maximum_size = 0;
48 for (var line in cur_line_sizes) {
49 maximum_size = Math.max(maximum_size, cur_line_sizes[line][0]);
51 for (var line in cur_line_sizes) {
52 var symbol_indices = cur_line_sizes[line][1];
53 var symbols = [];
54 for (var i = 0; i < symbol_indices.length; ++i) {
55 symbols.push(g_symbol_list[symbol_indices[i]]);
57 var size = cur_line_sizes[line][0];
58 // Zero based lines.
59 var line_num = parseInt(line, 10) - 1;
60 if (size >= maximum_size * 0.9)
61 editor.addLineClass(line_num, 'gutter', 'linebg-top10');
62 else if (size >= maximum_size * 0.75)
63 editor.addLineClass(line_num, 'gutter', 'linebg-top25');
64 else if (size >= maximum_size * 0.5)
65 editor.addLineClass(line_num, 'gutter', 'linebg-top50');
66 function addTag() {
67 var line_num = parseInt(line, 10);
68 var symbols_tooltip = symbols.join('\n');
69 var num_syms = symbols.length;
70 // markText wants 0-based lines.
71 var mark = editor.markText({line: line_num - 1, ch: 0},
72 {line: line_num, ch: 0},
73 { className: 'symbol-tag' });
74 CodeMirror.on(mark, 'beforeCursorEnter', function(e) {
75 symlist.setValue(num_syms +
76 ' symbol(s) contributing to line ' +
77 line_num + ':\n' +
78 symbols_tooltip);
79 });
81 addTag();
86 google.visualization.events.addListener(tree, 'select', nodeSelect);
88 editor = CodeMirror.fromTextArea(
89 document.getElementById('source_view'), {
90 readOnly: "nocursor",
91 mode: { name: 'text/x-c++src' },
92 lineNumbers: true,
93 lineNumberFormatter: weightGetter
94 });
95 editor.setSize(850, 600);
97 symlist = CodeMirror.fromTextArea(
98 document.getElementById('symlist_view'), {
99 readOnly: "nocursor",
100 mode: { name: 'none' },
101 lineNumbers: false
103 symlist.setSize(850, 150);
105 function tooltip(row, size, value) {
106 return '<div style="background:#fd9;' +
107 ' padding:10px; border-style:solid"><b>' +
108 data.getValue(row, 0) + '</b><br>' +
109 data.getColumnLabel(2) +
110 ' (total value of this cell and its children): ' + size +
111 '<br>';
114 function weightGetter(line) {
115 if (cur_line_sizes && cur_line_sizes.hasOwnProperty('' + line)) {
116 return cur_line_sizes['' + line][0] + ' bytes ' + line;
118 return line;