| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 /** | 28 /** |
| 29 * @fileoverview Log Reader is used to process log file produced by V8. | 29 * @fileoverview Log Reader is used to process log file produced by V8. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Base class for processing log files. | 34 * Base class for processing log files. |
| 35 * | 35 * |
| 36 * @param {Array.<Object>} dispatchTable A table used for parsing and processing | 36 * @param {Array.<Object>} dispatchTable A table used for parsing and processing |
| 37 * log records. | 37 * log records. |
| 38 * @param {boolean} timedRange Ignore ticks outside timed range. |
| 38 * @constructor | 39 * @constructor |
| 39 */ | 40 */ |
| 40 function LogReader(dispatchTable) { | 41 function LogReader(dispatchTable, timedRange) { |
| 41 /** | 42 /** |
| 42 * @type {Array.<Object>} | 43 * @type {Array.<Object>} |
| 43 */ | 44 */ |
| 44 this.dispatchTable_ = dispatchTable; | 45 this.dispatchTable_ = dispatchTable; |
| 45 | 46 |
| 46 /** | 47 /** |
| 48 * @type {boolean} |
| 49 */ |
| 50 this.timedRange_ = timedRange; |
| 51 |
| 52 /** |
| 47 * Current line. | 53 * Current line. |
| 48 * @type {number} | 54 * @type {number} |
| 49 */ | 55 */ |
| 50 this.lineNum_ = 0; | 56 this.lineNum_ = 0; |
| 51 | 57 |
| 52 /** | 58 /** |
| 53 * CSV lines parser. | 59 * CSV lines parser. |
| 54 * @type {CsvParser} | 60 * @type {CsvParser} |
| 55 */ | 61 */ |
| 56 this.csvParser_ = new CsvParser(); | 62 this.csvParser_ = new CsvParser(); |
| 63 |
| 64 /** |
| 65 * Keeps track of whether we've seen a "current-time" tick yet. |
| 66 * @type {boolean} |
| 67 */ |
| 68 this.hasSeenTimerMarker_ = false; |
| 69 |
| 70 /** |
| 71 * List of log lines seen since last "current-time" tick. |
| 72 * @type {Array.<String>} |
| 73 */ |
| 74 this.logLinesSinceLastTimerMarker_ = []; |
| 57 }; | 75 }; |
| 58 | 76 |
| 59 | 77 |
| 60 /** | 78 /** |
| 61 * Used for printing error messages. | 79 * Used for printing error messages. |
| 62 * | 80 * |
| 63 * @param {string} str Error message. | 81 * @param {string} str Error message. |
| 64 */ | 82 */ |
| 65 LogReader.prototype.printError = function(str) { | 83 LogReader.prototype.printError = function(str) { |
| 66 // Do nothing. | 84 // Do nothing. |
| 67 }; | 85 }; |
| 68 | 86 |
| 69 | 87 |
| 70 /** | 88 /** |
| 71 * Processes a portion of V8 profiler event log. | 89 * Processes a portion of V8 profiler event log. |
| 72 * | 90 * |
| 73 * @param {string} chunk A portion of log. | 91 * @param {string} chunk A portion of log. |
| 74 */ | 92 */ |
| 75 LogReader.prototype.processLogChunk = function(chunk) { | 93 LogReader.prototype.processLogChunk = function(chunk) { |
| 76 this.processLog_(chunk.split('\n')); | 94 this.processLog_(chunk.split('\n')); |
| 77 }; | 95 }; |
| 78 | 96 |
| 79 | 97 |
| 80 /** | 98 /** |
| 81 * Processes a line of V8 profiler event log. | 99 * Processes a line of V8 profiler event log. |
| 82 * | 100 * |
| 83 * @param {string} line A line of log. | 101 * @param {string} line A line of log. |
| 84 */ | 102 */ |
| 85 LogReader.prototype.processLogLine = function(line) { | 103 LogReader.prototype.processLogLine = function(line) { |
| 86 this.processLog_([line]); | 104 if (!this.timedRange_) { |
| 105 this.processLog_([line]); |
| 106 return; |
| 107 } |
| 108 if (line.startsWith("current-time")) { |
| 109 if (this.hasSeenTimerMarker_) { |
| 110 this.processLog_(this.logLinesSinceLastTimerMarker_); |
| 111 this.logLinesSinceLastTimerMarker_ = []; |
| 112 } else { |
| 113 this.hasSeenTimerMarker_ = true; |
| 114 } |
| 115 } else { |
| 116 if (this.hasSeenTimerMarker_) { |
| 117 this.logLinesSinceLastTimerMarker_.push(line); |
| 118 } else if (!line.startsWith("tick")) { |
| 119 this.processLog_([line]); |
| 120 } |
| 121 } |
| 87 }; | 122 }; |
| 88 | 123 |
| 89 | 124 |
| 90 /** | 125 /** |
| 91 * Processes stack record. | 126 * Processes stack record. |
| 92 * | 127 * |
| 93 * @param {number} pc Program counter. | 128 * @param {number} pc Program counter. |
| 94 * @param {number} func JS Function. | 129 * @param {number} func JS Function. |
| 95 * @param {Array.<string>} stack String representation of a stack. | 130 * @param {Array.<string>} stack String representation of a stack. |
| 96 * @return {Array.<number>} Processed stack. | 131 * @return {Array.<number>} Processed stack. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 continue; | 212 continue; |
| 178 } | 213 } |
| 179 try { | 214 try { |
| 180 var fields = this.csvParser_.parseLine(line); | 215 var fields = this.csvParser_.parseLine(line); |
| 181 this.dispatchLogRow_(fields); | 216 this.dispatchLogRow_(fields); |
| 182 } catch (e) { | 217 } catch (e) { |
| 183 this.printError('line ' + (this.lineNum_ + 1) + ': ' + (e.message || e)); | 218 this.printError('line ' + (this.lineNum_ + 1) + ': ' + (e.message || e)); |
| 184 } | 219 } |
| 185 } | 220 } |
| 186 }; | 221 }; |
| OLD | NEW |