OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 "use strict"; | 5 "use strict"; |
6 | 6 |
7 class DisassemblyView extends TextView { | 7 class DisassemblyView extends TextView { |
8 constructor(id, broker, sortedPositionList) { | 8 constructor(id, broker, sortedPositionList) { |
9 super(id, broker, null, false); | 9 super(id, broker, null, false); |
10 this.pos_start = -1; | 10 this.pos_start = -1; |
11 this.pos_lines = null; | 11 this.pos_lines = null; |
| 12 this.addr_event_counts = null; |
| 13 this.total_event_counts = null; |
| 14 |
12 let view = this; | 15 let view = this; |
13 let ADDRESS_STYLE = { | 16 let ADDRESS_STYLE = { |
14 css: 'tag', | 17 css: 'tag', |
15 location: function(text) { | 18 location: function(text) { |
16 ADDRESS_STYLE.last_address = text; | 19 ADDRESS_STYLE.last_address = text; |
17 return undefined; | 20 return undefined; |
18 } | 21 } |
19 }; | 22 }; |
20 let ADDRESS_LINK_STYLE = { | 23 let ADDRESS_LINK_STYLE = { |
21 css: 'tag', | 24 css: 'tag', |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 else if (view.pos_start != -1) { | 139 else if (view.pos_start != -1) { |
137 if (result === undefined) result = {}; | 140 if (result === undefined) result = {}; |
138 result.pos_start = view.pos_start; | 141 result.pos_start = view.pos_start; |
139 result.pos_end = result.pos_start + 1; | 142 result.pos_end = result.pos_start + 1; |
140 } | 143 } |
141 } | 144 } |
142 } | 145 } |
143 return result; | 146 return result; |
144 } | 147 } |
145 | 148 |
| 149 initializeContent(data, rememberedSelection) { |
| 150 this.data = data; |
| 151 super.initializeContent(data, rememberedSelection); |
| 152 } |
| 153 |
146 initializeCode(sourceText, sourcePosition) { | 154 initializeCode(sourceText, sourcePosition) { |
147 let view = this; | 155 let view = this; |
148 view.pos_lines = new Array(); | 156 view.pos_lines = new Array(); |
149 // Comment lines for line 0 include sourcePosition already, only need to | 157 // Comment lines for line 0 include sourcePosition already, only need to |
150 // add sourcePosition for lines > 0. | 158 // add sourcePosition for lines > 0. |
151 view.pos_lines[0] = sourcePosition; | 159 view.pos_lines[0] = sourcePosition; |
152 if (sourceText != "") { | 160 if (sourceText != "") { |
153 let base = sourcePosition; | 161 let base = sourcePosition; |
154 let current = 0; | 162 let current = 0; |
155 let source_lines = sourceText.split("\n"); | 163 let source_lines = sourceText.split("\n"); |
156 for (i=1; i < source_lines.length; i++) { | 164 for (let i = 1; i < source_lines.length; i++) { |
157 // Add 1 for newline character that is split off. | 165 // Add 1 for newline character that is split off. |
158 current += source_lines[i-1].length + 1; | 166 current += source_lines[i-1].length + 1; |
159 view.pos_lines[i] = base + current; | 167 view.pos_lines[i] = base + current; |
160 } | 168 } |
161 } | 169 } |
162 } | 170 } |
163 | 171 |
| 172 initializePerfProfile(eventCounts) { |
| 173 let view = this; |
| 174 if (eventCounts !== undefined) { |
| 175 view.addr_event_counts = eventCounts; |
| 176 |
| 177 view.total_event_counts = {}; |
| 178 for (var ev_name in view.addr_event_counts) { |
| 179 let keys = Object.keys(view.addr_event_counts[ev_name]); |
| 180 let values = keys.map(key => view.addr_event_counts[ev_name][key]); |
| 181 view.total_event_counts[ev_name] = values.reduce((a, b) => a + b); |
| 182 } |
| 183 } |
| 184 else { |
| 185 view.addr_event_counts = null; |
| 186 view.total_event_counts = null; |
| 187 } |
| 188 } |
| 189 |
| 190 // Shorten decimals and remove trailing zeroes for readability. |
| 191 humanize(num) { |
| 192 return num.toFixed(3).replace(/\.?0+$/, "") + "%"; |
| 193 } |
| 194 |
164 processLine(line) { | 195 processLine(line) { |
165 let view = this; | 196 let view = this; |
166 let func = function(match, p1, p2, p3) { | 197 let func = function(match, p1, p2, p3) { |
167 let nums = p2.split(":"); | 198 let nums = p2.split(":"); |
168 let li = Number(nums[0]); | 199 let li = Number(nums[0]); |
169 let pos = Number(nums[1]); | 200 let pos = Number(nums[1]); |
170 if(li === 0) | 201 if(li === 0) |
171 pos -= view.pos_lines[0]; | 202 pos -= view.pos_lines[0]; |
172 li++; | 203 li++; |
173 return p1 + li + ":" + pos + p3; | 204 return p1 + li + ":" + pos + p3; |
174 }; | 205 }; |
175 line = line.replace(view.SOURCE_POSITION_HEADER_REGEX, func); | 206 line = line.replace(view.SOURCE_POSITION_HEADER_REGEX, func); |
176 let fragments = super.processLine(line); | 207 let fragments = super.processLine(line); |
| 208 |
| 209 // Add profiling data per instruction if available. |
| 210 if (view.total_event_counts) { |
| 211 let event_selector = document.getElementById('event-selector'); |
| 212 if (event_selector.length !== 0) { |
| 213 let event = event_selector.value; |
| 214 let matches = /^(0x[0-9a-fA-F]+)\s+\d+\s+[0-9a-fA-F]+/.exec(line); |
| 215 if (matches) { |
| 216 let count = view.addr_event_counts[event][matches[1]]; |
| 217 let str = ""; |
| 218 let css_cls = undefined; |
| 219 if(count !== undefined) { |
| 220 let perc = count / view.total_event_counts[event] * 100; |
| 221 |
| 222 str = "(" + view.humanize(perc) + ") "; |
| 223 |
| 224 css_cls = "prof-low"; |
| 225 if(perc > PROF_HIGH) |
| 226 css_cls = "prof-high"; |
| 227 else if(perc > PROF_MED) |
| 228 css_cls = "prof-med"; |
| 229 } |
| 230 // Pad extra spaces to keep alignment for all instructions. |
| 231 str = (" ".repeat(10) + str).slice(-10); |
| 232 |
| 233 fragments.splice(0, 0, view.createFragment(str, css_cls)); |
| 234 } |
| 235 } |
| 236 } |
177 return fragments; | 237 return fragments; |
178 } | 238 } |
179 } | 239 } |
OLD | NEW |