Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 29 | function inherits(childCtor, parentCtor) { |
| 30 | childCtor.prototype.__proto__ = parentCtor.prototype; |
| 31 | }; |
| 32 | |
| 33 | |
| 34 | function V8Profile(separateIc) { |
| 35 | Profile.call(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 36 | if (!separateIc) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 37 | this.skipThisFunction = function(name) { return V8Profile.IC_RE.test(name); }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 38 | } |
| 39 | }; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 40 | inherits(V8Profile, Profile); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 41 | |
| 42 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 43 | V8Profile.IC_RE = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | /^(?:CallIC|LoadIC|StoreIC)|(?:Builtin: (?:Keyed)?(?:Call|Load|Store)IC_)/; |
| 45 | |
| 46 | |
| 47 | /** |
| 48 | * A thin wrapper around shell's 'read' function showing a file name on error. |
| 49 | */ |
| 50 | function readFile(fileName) { |
| 51 | try { |
| 52 | return read(fileName); |
| 53 | } catch (e) { |
| 54 | print(fileName + ': ' + (e.message || e)); |
| 55 | throw e; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 60 | /** |
| 61 | * Parser for dynamic code optimization state. |
| 62 | */ |
| 63 | function parseState(s) { |
| 64 | switch (s) { |
| 65 | case "": return Profile.CodeState.COMPILED; |
| 66 | case "~": return Profile.CodeState.OPTIMIZABLE; |
| 67 | case "*": return Profile.CodeState.OPTIMIZED; |
| 68 | } |
| 69 | throw new Error("unknown code state: " + s); |
| 70 | } |
| 71 | |
| 72 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 73 | function TickProcessor( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 74 | cppEntriesProvider, |
| 75 | separateIc, |
| 76 | callGraphSize, |
| 77 | ignoreUnknown, |
| 78 | stateFilter, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 79 | distortion, |
| 80 | range, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 81 | sourceMap, |
| 82 | timedRange, |
| 83 | pairwiseTimedRange, |
| 84 | onlySummary) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 85 | LogReader.call(this, { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 86 | 'shared-library': { parsers: [null, parseInt, parseInt], |
| 87 | processor: this.processSharedLibrary }, |
| 88 | 'code-creation': { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 89 | parsers: [null, parseInt, parseInt, parseInt, null, 'var-args'], |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 90 | processor: this.processCodeCreation }, |
| 91 | 'code-move': { parsers: [parseInt, parseInt], |
| 92 | processor: this.processCodeMove }, |
| 93 | 'code-delete': { parsers: [parseInt], |
| 94 | processor: this.processCodeDelete }, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 95 | 'sfi-move': { parsers: [parseInt, parseInt], |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 96 | processor: this.processFunctionMove }, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 97 | 'tick': { |
| 98 | parsers: [parseInt, parseInt, parseInt, |
| 99 | parseInt, parseInt, 'var-args'], |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 100 | processor: this.processTick }, |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 101 | 'heap-sample-begin': { parsers: [null, null, parseInt], |
| 102 | processor: this.processHeapSampleBegin }, |
| 103 | 'heap-sample-end': { parsers: [null, null], |
| 104 | processor: this.processHeapSampleEnd }, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 105 | 'timer-event-start' : { parsers: [null, null, null], |
| 106 | processor: this.advanceDistortion }, |
| 107 | 'timer-event-end' : { parsers: [null, null, null], |
| 108 | processor: this.advanceDistortion }, |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 109 | // Ignored events. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 110 | 'profiler': null, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 111 | 'function-creation': null, |
| 112 | 'function-move': null, |
| 113 | 'function-delete': null, |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 114 | 'heap-sample-item': null, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 115 | 'current-time': null, // Handled specially, not parsed. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 116 | // Obsolete row types. |
| 117 | 'code-allocate': null, |
| 118 | 'begin-code-region': null, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 119 | 'end-code-region': null }, |
| 120 | timedRange, |
| 121 | pairwiseTimedRange); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 122 | |
| 123 | this.cppEntriesProvider_ = cppEntriesProvider; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 124 | this.callGraphSize_ = callGraphSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 125 | this.ignoreUnknown_ = ignoreUnknown; |
| 126 | this.stateFilter_ = stateFilter; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 127 | this.sourceMap = sourceMap; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 128 | this.deserializedEntriesNames_ = []; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 129 | var ticks = this.ticks_ = |
| 130 | { total: 0, unaccounted: 0, excluded: 0, gc: 0 }; |
| 131 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 132 | distortion = parseInt(distortion); |
| 133 | // Convert picoseconds to nanoseconds. |
| 134 | this.distortion_per_entry = isNaN(distortion) ? 0 : (distortion / 1000); |
| 135 | this.distortion = 0; |
| 136 | var rangelimits = range ? range.split(",") : []; |
| 137 | var range_start = parseInt(rangelimits[0]); |
| 138 | var range_end = parseInt(rangelimits[1]); |
| 139 | // Convert milliseconds to nanoseconds. |
| 140 | this.range_start = isNaN(range_start) ? -Infinity : (range_start * 1000); |
| 141 | this.range_end = isNaN(range_end) ? Infinity : (range_end * 1000) |
| 142 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 143 | V8Profile.prototype.handleUnknownCode = function( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 144 | operation, addr, opt_stackPos) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 145 | var op = Profile.Operation; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 146 | switch (operation) { |
| 147 | case op.MOVE: |
| 148 | print('Code move event for unknown code: 0x' + addr.toString(16)); |
| 149 | break; |
| 150 | case op.DELETE: |
| 151 | print('Code delete event for unknown code: 0x' + addr.toString(16)); |
| 152 | break; |
| 153 | case op.TICK: |
| 154 | // Only unknown PCs (the first frame) are reported as unaccounted, |
| 155 | // otherwise tick balance will be corrupted (this behavior is compatible |
| 156 | // with the original tickprocessor.py script.) |
| 157 | if (opt_stackPos == 0) { |
| 158 | ticks.unaccounted++; |
| 159 | } |
| 160 | break; |
| 161 | } |
| 162 | }; |
| 163 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 164 | this.profile_ = new V8Profile(separateIc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 165 | this.codeTypes_ = {}; |
| 166 | // Count each tick as a time unit. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 167 | this.viewBuilder_ = new ViewBuilder(1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 168 | this.lastLogFileName_ = null; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 169 | |
| 170 | this.generation_ = 1; |
| 171 | this.currentProducerProfile_ = null; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 172 | this.onlySummary_ = onlySummary; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 173 | }; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 174 | inherits(TickProcessor, LogReader); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 175 | |
| 176 | |
| 177 | TickProcessor.VmStates = { |
| 178 | JS: 0, |
| 179 | GC: 1, |
| 180 | COMPILER: 2, |
| 181 | OTHER: 3, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 182 | EXTERNAL: 4, |
| 183 | IDLE: 5 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | |
| 187 | TickProcessor.CodeTypes = { |
| 188 | CPP: 0, |
| 189 | SHARED_LIB: 1 |
| 190 | }; |
| 191 | // Otherwise, this is JS-related code. We are not adding it to |
| 192 | // codeTypes_ map because there can be zillions of them. |
| 193 | |
| 194 | |
| 195 | TickProcessor.CALL_PROFILE_CUTOFF_PCT = 2.0; |
| 196 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 197 | TickProcessor.CALL_GRAPH_SIZE = 5; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 198 | |
| 199 | /** |
| 200 | * @override |
| 201 | */ |
| 202 | TickProcessor.prototype.printError = function(str) { |
| 203 | print(str); |
| 204 | }; |
| 205 | |
| 206 | |
| 207 | TickProcessor.prototype.setCodeType = function(name, type) { |
| 208 | this.codeTypes_[name] = TickProcessor.CodeTypes[type]; |
| 209 | }; |
| 210 | |
| 211 | |
| 212 | TickProcessor.prototype.isSharedLibrary = function(name) { |
| 213 | return this.codeTypes_[name] == TickProcessor.CodeTypes.SHARED_LIB; |
| 214 | }; |
| 215 | |
| 216 | |
| 217 | TickProcessor.prototype.isCppCode = function(name) { |
| 218 | return this.codeTypes_[name] == TickProcessor.CodeTypes.CPP; |
| 219 | }; |
| 220 | |
| 221 | |
| 222 | TickProcessor.prototype.isJsCode = function(name) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 223 | return name !== "UNKNOWN" && !(name in this.codeTypes_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 224 | }; |
| 225 | |
| 226 | |
| 227 | TickProcessor.prototype.processLogFile = function(fileName) { |
| 228 | this.lastLogFileName_ = fileName; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 229 | var line; |
| 230 | while (line = readline()) { |
| 231 | this.processLogLine(line); |
| 232 | } |
| 233 | }; |
| 234 | |
| 235 | |
| 236 | TickProcessor.prototype.processLogFileInTest = function(fileName) { |
| 237 | // Hack file name to avoid dealing with platform specifics. |
| 238 | this.lastLogFileName_ = 'v8.log'; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 239 | var contents = readFile(fileName); |
| 240 | this.processLogChunk(contents); |
| 241 | }; |
| 242 | |
| 243 | |
| 244 | TickProcessor.prototype.processSharedLibrary = function( |
| 245 | name, startAddr, endAddr) { |
| 246 | var entry = this.profile_.addLibrary(name, startAddr, endAddr); |
| 247 | this.setCodeType(entry.getName(), 'SHARED_LIB'); |
| 248 | |
| 249 | var self = this; |
| 250 | var libFuncs = this.cppEntriesProvider_.parseVmSymbols( |
| 251 | name, startAddr, endAddr, function(fName, fStart, fEnd) { |
| 252 | self.profile_.addStaticCode(fName, fStart, fEnd); |
| 253 | self.setCodeType(fName, 'CPP'); |
| 254 | }); |
| 255 | }; |
| 256 | |
| 257 | |
| 258 | TickProcessor.prototype.processCodeCreation = function( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 259 | type, kind, start, size, name, maybe_func) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 260 | name = this.deserializedEntriesNames_[start] || name; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 261 | if (maybe_func.length) { |
| 262 | var funcAddr = parseInt(maybe_func[0]); |
| 263 | var state = parseState(maybe_func[1]); |
| 264 | this.profile_.addFuncCode(type, name, start, size, funcAddr, state); |
| 265 | } else { |
| 266 | this.profile_.addCode(type, name, start, size); |
| 267 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 268 | }; |
| 269 | |
| 270 | |
| 271 | TickProcessor.prototype.processCodeMove = function(from, to) { |
| 272 | this.profile_.moveCode(from, to); |
| 273 | }; |
| 274 | |
| 275 | |
| 276 | TickProcessor.prototype.processCodeDelete = function(start) { |
| 277 | this.profile_.deleteCode(start); |
| 278 | }; |
| 279 | |
| 280 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 281 | TickProcessor.prototype.processFunctionMove = function(from, to) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 282 | this.profile_.moveFunc(from, to); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 286 | TickProcessor.prototype.includeTick = function(vmState) { |
| 287 | return this.stateFilter_ == null || this.stateFilter_ == vmState; |
| 288 | }; |
| 289 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 290 | TickProcessor.prototype.processTick = function(pc, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 291 | ns_since_start, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 292 | is_external_callback, |
| 293 | tos_or_external_callback, |
| 294 | vmState, |
| 295 | stack) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 296 | this.distortion += this.distortion_per_entry; |
| 297 | ns_since_start -= this.distortion; |
| 298 | if (ns_since_start < this.range_start || ns_since_start > this.range_end) { |
| 299 | return; |
| 300 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 301 | this.ticks_.total++; |
| 302 | if (vmState == TickProcessor.VmStates.GC) this.ticks_.gc++; |
| 303 | if (!this.includeTick(vmState)) { |
| 304 | this.ticks_.excluded++; |
| 305 | return; |
| 306 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 307 | if (is_external_callback) { |
| 308 | // Don't use PC when in external callback code, as it can point |
| 309 | // inside callback's code, and we will erroneously report |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 310 | // that a callback calls itself. Instead we use tos_or_external_callback, |
| 311 | // as simply resetting PC will produce unaccounted ticks. |
| 312 | pc = tos_or_external_callback; |
| 313 | tos_or_external_callback = 0; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 314 | } else if (tos_or_external_callback) { |
| 315 | // Find out, if top of stack was pointing inside a JS function |
| 316 | // meaning that we have encountered a frameless invocation. |
| 317 | var funcEntry = this.profile_.findEntry(tos_or_external_callback); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 318 | if (!funcEntry || !funcEntry.isJSFunction || !funcEntry.isJSFunction()) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 319 | tos_or_external_callback = 0; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 323 | this.profile_.recordTick(this.processStack(pc, tos_or_external_callback, stack)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 324 | }; |
| 325 | |
| 326 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 327 | TickProcessor.prototype.advanceDistortion = function() { |
| 328 | this.distortion += this.distortion_per_entry; |
| 329 | } |
| 330 | |
| 331 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 332 | TickProcessor.prototype.processHeapSampleBegin = function(space, state, ticks) { |
| 333 | if (space != 'Heap') return; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 334 | this.currentProducerProfile_ = new CallTree(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 335 | }; |
| 336 | |
| 337 | |
| 338 | TickProcessor.prototype.processHeapSampleEnd = function(space, state) { |
| 339 | if (space != 'Heap' || !this.currentProducerProfile_) return; |
| 340 | |
| 341 | print('Generation ' + this.generation_ + ':'); |
| 342 | var tree = this.currentProducerProfile_; |
| 343 | tree.computeTotalWeights(); |
| 344 | var producersView = this.viewBuilder_.buildView(tree); |
| 345 | // Sort by total time, desc, then by name, desc. |
| 346 | producersView.sort(function(rec1, rec2) { |
| 347 | return rec2.totalTime - rec1.totalTime || |
| 348 | (rec2.internalFuncName < rec1.internalFuncName ? -1 : 1); }); |
| 349 | this.printHeavyProfile(producersView.head.children); |
| 350 | |
| 351 | this.currentProducerProfile_ = null; |
| 352 | this.generation_++; |
| 353 | }; |
| 354 | |
| 355 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 356 | TickProcessor.prototype.printStatistics = function() { |
| 357 | print('Statistical profiling result from ' + this.lastLogFileName_ + |
| 358 | ', (' + this.ticks_.total + |
| 359 | ' ticks, ' + this.ticks_.unaccounted + ' unaccounted, ' + |
| 360 | this.ticks_.excluded + ' excluded).'); |
| 361 | |
| 362 | if (this.ticks_.total == 0) return; |
| 363 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 364 | var flatProfile = this.profile_.getFlatProfile(); |
| 365 | var flatView = this.viewBuilder_.buildView(flatProfile); |
| 366 | // Sort by self time, desc, then by name, desc. |
| 367 | flatView.sort(function(rec1, rec2) { |
| 368 | return rec2.selfTime - rec1.selfTime || |
| 369 | (rec2.internalFuncName < rec1.internalFuncName ? -1 : 1); }); |
| 370 | var totalTicks = this.ticks_.total; |
| 371 | if (this.ignoreUnknown_) { |
| 372 | totalTicks -= this.ticks_.unaccounted; |
| 373 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 374 | var printAllTicks = !this.onlySummary_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 375 | |
| 376 | // Count library ticks |
| 377 | var flatViewNodes = flatView.head.children; |
| 378 | var self = this; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 379 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 380 | var libraryTicks = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 381 | if(printAllTicks) this.printHeader('Shared libraries'); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 382 | this.printEntries(flatViewNodes, totalTicks, null, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 383 | function(name) { return self.isSharedLibrary(name); }, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 384 | function(rec) { libraryTicks += rec.selfTime; }, printAllTicks); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 385 | var nonLibraryTicks = totalTicks - libraryTicks; |
| 386 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 387 | var jsTicks = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 388 | if(printAllTicks) this.printHeader('JavaScript'); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 389 | this.printEntries(flatViewNodes, totalTicks, nonLibraryTicks, |
| 390 | function(name) { return self.isJsCode(name); }, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 391 | function(rec) { jsTicks += rec.selfTime; }, printAllTicks); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 392 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 393 | var cppTicks = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 394 | if(printAllTicks) this.printHeader('C++'); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 395 | this.printEntries(flatViewNodes, totalTicks, nonLibraryTicks, |
| 396 | function(name) { return self.isCppCode(name); }, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 397 | function(rec) { cppTicks += rec.selfTime; }, printAllTicks); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 398 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 399 | this.printHeader('Summary'); |
| 400 | this.printLine('JavaScript', jsTicks, totalTicks, nonLibraryTicks); |
| 401 | this.printLine('C++', cppTicks, totalTicks, nonLibraryTicks); |
| 402 | this.printLine('GC', this.ticks_.gc, totalTicks, nonLibraryTicks); |
| 403 | this.printLine('Shared libraries', libraryTicks, totalTicks, null); |
| 404 | if (!this.ignoreUnknown_ && this.ticks_.unaccounted > 0) { |
| 405 | this.printLine('Unaccounted', this.ticks_.unaccounted, |
| 406 | this.ticks_.total, null); |
| 407 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 408 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 409 | if(printAllTicks) { |
| 410 | print('\n [C++ entry points]:'); |
| 411 | print(' ticks cpp total name'); |
| 412 | var c_entry_functions = this.profile_.getCEntryProfile(); |
| 413 | var total_c_entry = c_entry_functions[0].ticks; |
| 414 | for (var i = 1; i < c_entry_functions.length; i++) { |
| 415 | c = c_entry_functions[i]; |
| 416 | this.printLine(c.name, c.ticks, total_c_entry, totalTicks); |
| 417 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 418 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 419 | this.printHeavyProfHeader(); |
| 420 | var heavyProfile = this.profile_.getBottomUpProfile(); |
| 421 | var heavyView = this.viewBuilder_.buildView(heavyProfile); |
| 422 | // To show the same percentages as in the flat profile. |
| 423 | heavyView.head.totalTime = totalTicks; |
| 424 | // Sort by total time, desc, then by name, desc. |
| 425 | heavyView.sort(function(rec1, rec2) { |
| 426 | return rec2.totalTime - rec1.totalTime || |
| 427 | (rec2.internalFuncName < rec1.internalFuncName ? -1 : 1); }); |
| 428 | this.printHeavyProfile(heavyView.head.children); |
| 429 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 430 | }; |
| 431 | |
| 432 | |
| 433 | function padLeft(s, len) { |
| 434 | s = s.toString(); |
| 435 | if (s.length < len) { |
| 436 | var padLength = len - s.length; |
| 437 | if (!(padLength in padLeft)) { |
| 438 | padLeft[padLength] = new Array(padLength + 1).join(' '); |
| 439 | } |
| 440 | s = padLeft[padLength] + s; |
| 441 | } |
| 442 | return s; |
| 443 | }; |
| 444 | |
| 445 | |
| 446 | TickProcessor.prototype.printHeader = function(headerTitle) { |
| 447 | print('\n [' + headerTitle + ']:'); |
| 448 | print(' ticks total nonlib name'); |
| 449 | }; |
| 450 | |
| 451 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 452 | TickProcessor.prototype.printLine = function( |
| 453 | entry, ticks, totalTicks, nonLibTicks) { |
| 454 | var pct = ticks * 100 / totalTicks; |
| 455 | var nonLibPct = nonLibTicks != null |
| 456 | ? padLeft((ticks * 100 / nonLibTicks).toFixed(1), 5) + '% ' |
| 457 | : ' '; |
| 458 | print(' ' + padLeft(ticks, 5) + ' ' + |
| 459 | padLeft(pct.toFixed(1), 5) + '% ' + |
| 460 | nonLibPct + |
| 461 | entry); |
| 462 | } |
| 463 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 464 | TickProcessor.prototype.printHeavyProfHeader = function() { |
| 465 | print('\n [Bottom up (heavy) profile]:'); |
| 466 | print(' Note: percentage shows a share of a particular caller in the ' + |
| 467 | 'total\n' + |
| 468 | ' amount of its parent calls.'); |
| 469 | print(' Callers occupying less than ' + |
| 470 | TickProcessor.CALL_PROFILE_CUTOFF_PCT.toFixed(1) + |
| 471 | '% are not shown.\n'); |
| 472 | print(' ticks parent name'); |
| 473 | }; |
| 474 | |
| 475 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 476 | TickProcessor.prototype.processProfile = function( |
| 477 | profile, filterP, func) { |
| 478 | for (var i = 0, n = profile.length; i < n; ++i) { |
| 479 | var rec = profile[i]; |
| 480 | if (!filterP(rec.internalFuncName)) { |
| 481 | continue; |
| 482 | } |
| 483 | func(rec); |
| 484 | } |
| 485 | }; |
| 486 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 487 | TickProcessor.prototype.getLineAndColumn = function(name) { |
| 488 | var re = /:([0-9]+):([0-9]+)$/; |
| 489 | var array = re.exec(name); |
| 490 | if (!array) { |
| 491 | return null; |
| 492 | } |
| 493 | return {line: array[1], column: array[2]}; |
| 494 | } |
| 495 | |
| 496 | TickProcessor.prototype.hasSourceMap = function() { |
| 497 | return this.sourceMap != null; |
| 498 | }; |
| 499 | |
| 500 | |
| 501 | TickProcessor.prototype.formatFunctionName = function(funcName) { |
| 502 | if (!this.hasSourceMap()) { |
| 503 | return funcName; |
| 504 | } |
| 505 | var lc = this.getLineAndColumn(funcName); |
| 506 | if (lc == null) { |
| 507 | return funcName; |
| 508 | } |
| 509 | // in source maps lines and columns are zero based |
| 510 | var lineNumber = lc.line - 1; |
| 511 | var column = lc.column - 1; |
| 512 | var entry = this.sourceMap.findEntry(lineNumber, column); |
| 513 | var sourceFile = entry[2]; |
| 514 | var sourceLine = entry[3] + 1; |
| 515 | var sourceColumn = entry[4] + 1; |
| 516 | |
| 517 | return sourceFile + ':' + sourceLine + ':' + sourceColumn + ' -> ' + funcName; |
| 518 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 519 | |
| 520 | TickProcessor.prototype.printEntries = function( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 521 | profile, totalTicks, nonLibTicks, filterP, callback, printAllTicks) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 522 | var that = this; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 523 | this.processProfile(profile, filterP, function (rec) { |
| 524 | if (rec.selfTime == 0) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 525 | callback(rec); |
| 526 | var funcName = that.formatFunctionName(rec.internalFuncName); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 527 | if(printAllTicks) { |
| 528 | that.printLine(funcName, rec.selfTime, totalTicks, nonLibTicks); |
| 529 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 530 | }); |
| 531 | }; |
| 532 | |
| 533 | |
| 534 | TickProcessor.prototype.printHeavyProfile = function(profile, opt_indent) { |
| 535 | var self = this; |
| 536 | var indent = opt_indent || 0; |
| 537 | var indentStr = padLeft('', indent); |
| 538 | this.processProfile(profile, function() { return true; }, function (rec) { |
| 539 | // Cut off too infrequent callers. |
| 540 | if (rec.parentTotalPercent < TickProcessor.CALL_PROFILE_CUTOFF_PCT) return; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 541 | var funcName = self.formatFunctionName(rec.internalFuncName); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 542 | print(' ' + padLeft(rec.totalTime, 5) + ' ' + |
| 543 | padLeft(rec.parentTotalPercent.toFixed(1), 5) + '% ' + |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 544 | indentStr + funcName); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 545 | // Limit backtrace depth. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 546 | if (indent < 2 * self.callGraphSize_) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 547 | self.printHeavyProfile(rec.children, indent + 2); |
| 548 | } |
| 549 | // Delimit top-level functions. |
| 550 | if (indent == 0) { |
| 551 | print(''); |
| 552 | } |
| 553 | }); |
| 554 | }; |
| 555 | |
| 556 | |
| 557 | function CppEntriesProvider() { |
| 558 | }; |
| 559 | |
| 560 | |
| 561 | CppEntriesProvider.prototype.parseVmSymbols = function( |
| 562 | libName, libStart, libEnd, processorFunc) { |
| 563 | this.loadSymbols(libName); |
| 564 | |
| 565 | var prevEntry; |
| 566 | |
| 567 | function addEntry(funcInfo) { |
| 568 | // Several functions can be mapped onto the same address. To avoid |
| 569 | // creating zero-sized entries, skip such duplicates. |
| 570 | // Also double-check that function belongs to the library address space. |
| 571 | if (prevEntry && !prevEntry.end && |
| 572 | prevEntry.start < funcInfo.start && |
| 573 | prevEntry.start >= libStart && funcInfo.start <= libEnd) { |
| 574 | processorFunc(prevEntry.name, prevEntry.start, funcInfo.start); |
| 575 | } |
| 576 | if (funcInfo.end && |
| 577 | (!prevEntry || prevEntry.start != funcInfo.start) && |
| 578 | funcInfo.start >= libStart && funcInfo.end <= libEnd) { |
| 579 | processorFunc(funcInfo.name, funcInfo.start, funcInfo.end); |
| 580 | } |
| 581 | prevEntry = funcInfo; |
| 582 | } |
| 583 | |
| 584 | while (true) { |
| 585 | var funcInfo = this.parseNextLine(); |
| 586 | if (funcInfo === null) { |
| 587 | continue; |
| 588 | } else if (funcInfo === false) { |
| 589 | break; |
| 590 | } |
| 591 | if (funcInfo.start < libStart && funcInfo.start < libEnd - libStart) { |
| 592 | funcInfo.start += libStart; |
| 593 | } |
| 594 | if (funcInfo.size) { |
| 595 | funcInfo.end = funcInfo.start + funcInfo.size; |
| 596 | } |
| 597 | addEntry(funcInfo); |
| 598 | } |
| 599 | addEntry({name: '', start: libEnd}); |
| 600 | }; |
| 601 | |
| 602 | |
| 603 | CppEntriesProvider.prototype.loadSymbols = function(libName) { |
| 604 | }; |
| 605 | |
| 606 | |
| 607 | CppEntriesProvider.prototype.parseNextLine = function() { |
| 608 | return false; |
| 609 | }; |
| 610 | |
| 611 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 612 | function UnixCppEntriesProvider(nmExec, targetRootFS) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 613 | this.symbols = []; |
| 614 | this.parsePos = 0; |
| 615 | this.nmExec = nmExec; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 616 | this.targetRootFS = targetRootFS; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 617 | this.FUNC_RE = /^([0-9a-fA-F]{8,16}) ([0-9a-fA-F]{8,16} )?[tTwW] (.*)$/; |
| 618 | }; |
| 619 | inherits(UnixCppEntriesProvider, CppEntriesProvider); |
| 620 | |
| 621 | |
| 622 | UnixCppEntriesProvider.prototype.loadSymbols = function(libName) { |
| 623 | this.parsePos = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 624 | libName = this.targetRootFS + libName; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 625 | try { |
| 626 | this.symbols = [ |
| 627 | os.system(this.nmExec, ['-C', '-n', '-S', libName], -1, -1), |
| 628 | os.system(this.nmExec, ['-C', '-n', '-S', '-D', libName], -1, -1) |
| 629 | ]; |
| 630 | } catch (e) { |
| 631 | // If the library cannot be found on this system let's not panic. |
| 632 | this.symbols = ['', '']; |
| 633 | } |
| 634 | }; |
| 635 | |
| 636 | |
| 637 | UnixCppEntriesProvider.prototype.parseNextLine = function() { |
| 638 | if (this.symbols.length == 0) { |
| 639 | return false; |
| 640 | } |
| 641 | var lineEndPos = this.symbols[0].indexOf('\n', this.parsePos); |
| 642 | if (lineEndPos == -1) { |
| 643 | this.symbols.shift(); |
| 644 | this.parsePos = 0; |
| 645 | return this.parseNextLine(); |
| 646 | } |
| 647 | |
| 648 | var line = this.symbols[0].substring(this.parsePos, lineEndPos); |
| 649 | this.parsePos = lineEndPos + 1; |
| 650 | var fields = line.match(this.FUNC_RE); |
| 651 | var funcInfo = null; |
| 652 | if (fields) { |
| 653 | funcInfo = { name: fields[3], start: parseInt(fields[1], 16) }; |
| 654 | if (fields[2]) { |
| 655 | funcInfo.size = parseInt(fields[2], 16); |
| 656 | } |
| 657 | } |
| 658 | return funcInfo; |
| 659 | }; |
| 660 | |
| 661 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 662 | function MacCppEntriesProvider(nmExec, targetRootFS) { |
| 663 | UnixCppEntriesProvider.call(this, nmExec, targetRootFS); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 664 | // Note an empty group. It is required, as UnixCppEntriesProvider expects 3 groups. |
| 665 | this.FUNC_RE = /^([0-9a-fA-F]{8,16}) ()[iItT] (.*)$/; |
| 666 | }; |
| 667 | inherits(MacCppEntriesProvider, UnixCppEntriesProvider); |
| 668 | |
| 669 | |
| 670 | MacCppEntriesProvider.prototype.loadSymbols = function(libName) { |
| 671 | this.parsePos = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 672 | libName = this.targetRootFS + libName; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 673 | |
| 674 | // It seems that in OS X `nm` thinks that `-f` is a format option, not a |
| 675 | // "flat" display option flag. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 676 | try { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 677 | this.symbols = [os.system(this.nmExec, ['-n', libName], -1, -1), '']; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 678 | } catch (e) { |
| 679 | // If the library cannot be found on this system let's not panic. |
| 680 | this.symbols = ''; |
| 681 | } |
| 682 | }; |
| 683 | |
| 684 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 685 | function WindowsCppEntriesProvider(_ignored_nmExec, targetRootFS) { |
| 686 | this.targetRootFS = targetRootFS; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 687 | this.symbols = ''; |
| 688 | this.parsePos = 0; |
| 689 | }; |
| 690 | inherits(WindowsCppEntriesProvider, CppEntriesProvider); |
| 691 | |
| 692 | |
| 693 | WindowsCppEntriesProvider.FILENAME_RE = /^(.*)\.([^.]+)$/; |
| 694 | |
| 695 | |
| 696 | WindowsCppEntriesProvider.FUNC_RE = |
| 697 | /^\s+0001:[0-9a-fA-F]{8}\s+([_\?@$0-9a-zA-Z]+)\s+([0-9a-fA-F]{8}).*$/; |
| 698 | |
| 699 | |
| 700 | WindowsCppEntriesProvider.IMAGE_BASE_RE = |
| 701 | /^\s+0000:00000000\s+___ImageBase\s+([0-9a-fA-F]{8}).*$/; |
| 702 | |
| 703 | |
| 704 | // This is almost a constant on Windows. |
| 705 | WindowsCppEntriesProvider.EXE_IMAGE_BASE = 0x00400000; |
| 706 | |
| 707 | |
| 708 | WindowsCppEntriesProvider.prototype.loadSymbols = function(libName) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 709 | libName = this.targetRootFS + libName; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 710 | var fileNameFields = libName.match(WindowsCppEntriesProvider.FILENAME_RE); |
| 711 | if (!fileNameFields) return; |
| 712 | var mapFileName = fileNameFields[1] + '.map'; |
| 713 | this.moduleType_ = fileNameFields[2].toLowerCase(); |
| 714 | try { |
| 715 | this.symbols = read(mapFileName); |
| 716 | } catch (e) { |
| 717 | // If .map file cannot be found let's not panic. |
| 718 | this.symbols = ''; |
| 719 | } |
| 720 | }; |
| 721 | |
| 722 | |
| 723 | WindowsCppEntriesProvider.prototype.parseNextLine = function() { |
| 724 | var lineEndPos = this.symbols.indexOf('\r\n', this.parsePos); |
| 725 | if (lineEndPos == -1) { |
| 726 | return false; |
| 727 | } |
| 728 | |
| 729 | var line = this.symbols.substring(this.parsePos, lineEndPos); |
| 730 | this.parsePos = lineEndPos + 2; |
| 731 | |
| 732 | // Image base entry is above all other symbols, so we can just |
| 733 | // terminate parsing. |
| 734 | var imageBaseFields = line.match(WindowsCppEntriesProvider.IMAGE_BASE_RE); |
| 735 | if (imageBaseFields) { |
| 736 | var imageBase = parseInt(imageBaseFields[1], 16); |
| 737 | if ((this.moduleType_ == 'exe') != |
| 738 | (imageBase == WindowsCppEntriesProvider.EXE_IMAGE_BASE)) { |
| 739 | return false; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | var fields = line.match(WindowsCppEntriesProvider.FUNC_RE); |
| 744 | return fields ? |
| 745 | { name: this.unmangleName(fields[1]), start: parseInt(fields[2], 16) } : |
| 746 | null; |
| 747 | }; |
| 748 | |
| 749 | |
| 750 | /** |
| 751 | * Performs very simple unmangling of C++ names. |
| 752 | * |
| 753 | * Does not handle arguments and template arguments. The mangled names have |
| 754 | * the form: |
| 755 | * |
| 756 | * ?LookupInDescriptor@JSObject@internal@v8@@...arguments info... |
| 757 | */ |
| 758 | WindowsCppEntriesProvider.prototype.unmangleName = function(name) { |
| 759 | // Empty or non-mangled name. |
| 760 | if (name.length < 1 || name.charAt(0) != '?') return name; |
| 761 | var nameEndPos = name.indexOf('@@'); |
| 762 | var components = name.substring(1, nameEndPos).split('@'); |
| 763 | components.reverse(); |
| 764 | return components.join('::'); |
| 765 | }; |
| 766 | |
| 767 | |
| 768 | function ArgumentsProcessor(args) { |
| 769 | this.args_ = args; |
| 770 | this.result_ = ArgumentsProcessor.DEFAULTS; |
| 771 | |
| 772 | this.argsDispatch_ = { |
| 773 | '-j': ['stateFilter', TickProcessor.VmStates.JS, |
| 774 | 'Show only ticks from JS VM state'], |
| 775 | '-g': ['stateFilter', TickProcessor.VmStates.GC, |
| 776 | 'Show only ticks from GC VM state'], |
| 777 | '-c': ['stateFilter', TickProcessor.VmStates.COMPILER, |
| 778 | 'Show only ticks from COMPILER VM state'], |
| 779 | '-o': ['stateFilter', TickProcessor.VmStates.OTHER, |
| 780 | 'Show only ticks from OTHER VM state'], |
| 781 | '-e': ['stateFilter', TickProcessor.VmStates.EXTERNAL, |
| 782 | 'Show only ticks from EXTERNAL VM state'], |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 783 | '--call-graph-size': ['callGraphSize', TickProcessor.CALL_GRAPH_SIZE, |
| 784 | 'Set the call graph size'], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 785 | '--ignore-unknown': ['ignoreUnknown', true, |
| 786 | 'Exclude ticks of unknown code entries from processing'], |
| 787 | '--separate-ic': ['separateIc', true, |
| 788 | 'Separate IC entries'], |
| 789 | '--unix': ['platform', 'unix', |
| 790 | 'Specify that we are running on *nix platform'], |
| 791 | '--windows': ['platform', 'windows', |
| 792 | 'Specify that we are running on Windows platform'], |
| 793 | '--mac': ['platform', 'mac', |
| 794 | 'Specify that we are running on Mac OS X platform'], |
| 795 | '--nm': ['nm', 'nm', |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 796 | 'Specify the \'nm\' executable to use (e.g. --nm=/my_dir/nm)'], |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 797 | '--target': ['targetRootFS', '', |
| 798 | 'Specify the target root directory for cross environment'], |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 799 | '--range': ['range', 'auto,auto', |
| 800 | 'Specify the range limit as [start],[end]'], |
| 801 | '--distortion': ['distortion', 0, |
| 802 | 'Specify the logging overhead in picoseconds'], |
| 803 | '--source-map': ['sourceMap', null, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 804 | 'Specify the source map that should be used for output'], |
| 805 | '--timed-range': ['timedRange', true, |
| 806 | 'Ignore ticks before first and after last Date.now() call'], |
| 807 | '--pairwise-timed-range': ['pairwiseTimedRange', true, |
| 808 | 'Ignore ticks outside pairs of Date.now() calls'], |
| 809 | '--only-summary': ['onlySummary', true, |
| 810 | 'Print only tick summary, exclude other information'] |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 811 | }; |
| 812 | this.argsDispatch_['--js'] = this.argsDispatch_['-j']; |
| 813 | this.argsDispatch_['--gc'] = this.argsDispatch_['-g']; |
| 814 | this.argsDispatch_['--compiler'] = this.argsDispatch_['-c']; |
| 815 | this.argsDispatch_['--other'] = this.argsDispatch_['-o']; |
| 816 | this.argsDispatch_['--external'] = this.argsDispatch_['-e']; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 817 | this.argsDispatch_['--ptr'] = this.argsDispatch_['--pairwise-timed-range']; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 818 | }; |
| 819 | |
| 820 | |
| 821 | ArgumentsProcessor.DEFAULTS = { |
| 822 | logFileName: 'v8.log', |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 823 | platform: 'unix', |
| 824 | stateFilter: null, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 825 | callGraphSize: 5, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 826 | ignoreUnknown: false, |
| 827 | separateIc: false, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 828 | targetRootFS: '', |
| 829 | nm: 'nm', |
| 830 | range: 'auto,auto', |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 831 | distortion: 0, |
| 832 | timedRange: false, |
| 833 | pairwiseTimedRange: false, |
| 834 | onlySummary: false |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 835 | }; |
| 836 | |
| 837 | |
| 838 | ArgumentsProcessor.prototype.parse = function() { |
| 839 | while (this.args_.length) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 840 | var arg = this.args_.shift(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 841 | if (arg.charAt(0) != '-') { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 842 | this.result_.logFileName = arg; |
| 843 | continue; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 844 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 845 | var userValue = null; |
| 846 | var eqPos = arg.indexOf('='); |
| 847 | if (eqPos != -1) { |
| 848 | userValue = arg.substr(eqPos + 1); |
| 849 | arg = arg.substr(0, eqPos); |
| 850 | } |
| 851 | if (arg in this.argsDispatch_) { |
| 852 | var dispatch = this.argsDispatch_[arg]; |
| 853 | this.result_[dispatch[0]] = userValue == null ? dispatch[1] : userValue; |
| 854 | } else { |
| 855 | return false; |
| 856 | } |
| 857 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 858 | return true; |
| 859 | }; |
| 860 | |
| 861 | |
| 862 | ArgumentsProcessor.prototype.result = function() { |
| 863 | return this.result_; |
| 864 | }; |
| 865 | |
| 866 | |
| 867 | ArgumentsProcessor.prototype.printUsageAndExit = function() { |
| 868 | |
| 869 | function padRight(s, len) { |
| 870 | s = s.toString(); |
| 871 | if (s.length < len) { |
| 872 | s = s + (new Array(len - s.length + 1).join(' ')); |
| 873 | } |
| 874 | return s; |
| 875 | } |
| 876 | |
| 877 | print('Cmdline args: [options] [log-file-name]\n' + |
| 878 | 'Default log file name is "' + |
| 879 | ArgumentsProcessor.DEFAULTS.logFileName + '".\n'); |
| 880 | print('Options:'); |
| 881 | for (var arg in this.argsDispatch_) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 882 | var synonyms = [arg]; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 883 | var dispatch = this.argsDispatch_[arg]; |
| 884 | for (var synArg in this.argsDispatch_) { |
| 885 | if (arg !== synArg && dispatch === this.argsDispatch_[synArg]) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 886 | synonyms.push(synArg); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 887 | delete this.argsDispatch_[synArg]; |
| 888 | } |
| 889 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 890 | print(' ' + padRight(synonyms.join(', '), 20) + " " + dispatch[2]); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 891 | } |
| 892 | quit(2); |
| 893 | }; |