OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 11 matching lines...) Expand all Loading... |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
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 // Initlialize namespaces | |
33 var devtools = devtools || {}; | |
34 devtools.profiler = devtools.profiler || {}; | |
35 | |
36 | 32 |
37 /** | 33 /** |
38 * Base class for processing log files. | 34 * Base class for processing log files. |
39 * | 35 * |
40 * @param {Array.<Object>} dispatchTable A table used for parsing and processing | 36 * @param {Array.<Object>} dispatchTable A table used for parsing and processing |
41 * log records. | 37 * log records. |
42 * @constructor | 38 * @constructor |
43 */ | 39 */ |
44 devtools.profiler.LogReader = function(dispatchTable) { | 40 function LogReader(dispatchTable) { |
45 /** | 41 /** |
46 * @type {Array.<Object>} | 42 * @type {Array.<Object>} |
47 */ | 43 */ |
48 this.dispatchTable_ = dispatchTable; | 44 this.dispatchTable_ = dispatchTable; |
49 | 45 |
50 /** | 46 /** |
51 * Current line. | 47 * Current line. |
52 * @type {number} | 48 * @type {number} |
53 */ | 49 */ |
54 this.lineNum_ = 0; | 50 this.lineNum_ = 0; |
55 | 51 |
56 /** | 52 /** |
57 * CSV lines parser. | 53 * CSV lines parser. |
58 * @type {devtools.profiler.CsvParser} | 54 * @type {CsvParser} |
59 */ | 55 */ |
60 this.csvParser_ = new devtools.profiler.CsvParser(); | 56 this.csvParser_ = new CsvParser(); |
61 }; | 57 }; |
62 | 58 |
63 | 59 |
64 /** | 60 /** |
65 * Used for printing error messages. | 61 * Used for printing error messages. |
66 * | 62 * |
67 * @param {string} str Error message. | 63 * @param {string} str Error message. |
68 */ | 64 */ |
69 devtools.profiler.LogReader.prototype.printError = function(str) { | 65 LogReader.prototype.printError = function(str) { |
70 // Do nothing. | 66 // Do nothing. |
71 }; | 67 }; |
72 | 68 |
73 | 69 |
74 /** | 70 /** |
75 * Processes a portion of V8 profiler event log. | 71 * Processes a portion of V8 profiler event log. |
76 * | 72 * |
77 * @param {string} chunk A portion of log. | 73 * @param {string} chunk A portion of log. |
78 */ | 74 */ |
79 devtools.profiler.LogReader.prototype.processLogChunk = function(chunk) { | 75 LogReader.prototype.processLogChunk = function(chunk) { |
80 this.processLog_(chunk.split('\n')); | 76 this.processLog_(chunk.split('\n')); |
81 }; | 77 }; |
82 | 78 |
83 | 79 |
84 /** | 80 /** |
85 * Processes a line of V8 profiler event log. | 81 * Processes a line of V8 profiler event log. |
86 * | 82 * |
87 * @param {string} line A line of log. | 83 * @param {string} line A line of log. |
88 */ | 84 */ |
89 devtools.profiler.LogReader.prototype.processLogLine = function(line) { | 85 LogReader.prototype.processLogLine = function(line) { |
90 this.processLog_([line]); | 86 this.processLog_([line]); |
91 }; | 87 }; |
92 | 88 |
93 | 89 |
94 /** | 90 /** |
95 * Processes stack record. | 91 * Processes stack record. |
96 * | 92 * |
97 * @param {number} pc Program counter. | 93 * @param {number} pc Program counter. |
98 * @param {number} func JS Function. | 94 * @param {number} func JS Function. |
99 * @param {Array.<string>} stack String representation of a stack. | 95 * @param {Array.<string>} stack String representation of a stack. |
100 * @return {Array.<number>} Processed stack. | 96 * @return {Array.<number>} Processed stack. |
101 */ | 97 */ |
102 devtools.profiler.LogReader.prototype.processStack = function(pc, func, stack) { | 98 LogReader.prototype.processStack = function(pc, func, stack) { |
103 var fullStack = func ? [pc, func] : [pc]; | 99 var fullStack = func ? [pc, func] : [pc]; |
104 var prevFrame = pc; | 100 var prevFrame = pc; |
105 for (var i = 0, n = stack.length; i < n; ++i) { | 101 for (var i = 0, n = stack.length; i < n; ++i) { |
106 var frame = stack[i]; | 102 var frame = stack[i]; |
107 var firstChar = frame.charAt(0); | 103 var firstChar = frame.charAt(0); |
108 if (firstChar == '+' || firstChar == '-') { | 104 if (firstChar == '+' || firstChar == '-') { |
109 // An offset from the previous frame. | 105 // An offset from the previous frame. |
110 prevFrame += parseInt(frame, 16); | 106 prevFrame += parseInt(frame, 16); |
111 fullStack.push(prevFrame); | 107 fullStack.push(prevFrame); |
112 // Filter out possible 'overflow' string. | 108 // Filter out possible 'overflow' string. |
113 } else if (firstChar != 'o') { | 109 } else if (firstChar != 'o') { |
114 fullStack.push(parseInt(frame, 16)); | 110 fullStack.push(parseInt(frame, 16)); |
115 } | 111 } |
116 } | 112 } |
117 return fullStack; | 113 return fullStack; |
118 }; | 114 }; |
119 | 115 |
120 | 116 |
121 /** | 117 /** |
122 * Returns whether a particular dispatch must be skipped. | 118 * Returns whether a particular dispatch must be skipped. |
123 * | 119 * |
124 * @param {!Object} dispatch Dispatch record. | 120 * @param {!Object} dispatch Dispatch record. |
125 * @return {boolean} True if dispatch must be skipped. | 121 * @return {boolean} True if dispatch must be skipped. |
126 */ | 122 */ |
127 devtools.profiler.LogReader.prototype.skipDispatch = function(dispatch) { | 123 LogReader.prototype.skipDispatch = function(dispatch) { |
128 return false; | 124 return false; |
129 }; | 125 }; |
130 | 126 |
131 | 127 |
132 /** | 128 /** |
133 * Does a dispatch of a log record. | 129 * Does a dispatch of a log record. |
134 * | 130 * |
135 * @param {Array.<string>} fields Log record. | 131 * @param {Array.<string>} fields Log record. |
136 * @private | 132 * @private |
137 */ | 133 */ |
138 devtools.profiler.LogReader.prototype.dispatchLogRow_ = function(fields) { | 134 LogReader.prototype.dispatchLogRow_ = function(fields) { |
139 // Obtain the dispatch. | 135 // Obtain the dispatch. |
140 var command = fields[0]; | 136 var command = fields[0]; |
141 if (!(command in this.dispatchTable_)) { | 137 if (!(command in this.dispatchTable_)) { |
142 throw new Error('unknown command: ' + command); | 138 throw new Error('unknown command: ' + command); |
143 } | 139 } |
144 var dispatch = this.dispatchTable_[command]; | 140 var dispatch = this.dispatchTable_[command]; |
145 | 141 |
146 if (dispatch === null || this.skipDispatch(dispatch)) { | 142 if (dispatch === null || this.skipDispatch(dispatch)) { |
147 return; | 143 return; |
148 } | 144 } |
(...skipping 17 matching lines...) Expand all Loading... |
166 dispatch.processor.apply(this, parsedFields); | 162 dispatch.processor.apply(this, parsedFields); |
167 }; | 163 }; |
168 | 164 |
169 | 165 |
170 /** | 166 /** |
171 * Processes log lines. | 167 * Processes log lines. |
172 * | 168 * |
173 * @param {Array.<string>} lines Log lines. | 169 * @param {Array.<string>} lines Log lines. |
174 * @private | 170 * @private |
175 */ | 171 */ |
176 devtools.profiler.LogReader.prototype.processLog_ = function(lines) { | 172 LogReader.prototype.processLog_ = function(lines) { |
177 for (var i = 0, n = lines.length; i < n; ++i, ++this.lineNum_) { | 173 for (var i = 0, n = lines.length; i < n; ++i, ++this.lineNum_) { |
178 var line = lines[i]; | 174 var line = lines[i]; |
179 if (!line) { | 175 if (!line) { |
180 continue; | 176 continue; |
181 } | 177 } |
182 try { | 178 try { |
183 var fields = this.csvParser_.parseLine(line); | 179 var fields = this.csvParser_.parseLine(line); |
184 this.dispatchLogRow_(fields); | 180 this.dispatchLogRow_(fields); |
185 } catch (e) { | 181 } catch (e) { |
186 this.printError('line ' + (this.lineNum_ + 1) + ': ' + (e.message || e)); | 182 this.printError('line ' + (this.lineNum_ + 1) + ': ' + (e.message || e)); |
187 } | 183 } |
188 } | 184 } |
189 }; | 185 }; |
OLD | NEW |