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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
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 function Profile(separateIc) { | 29 function inherits(childCtor, parentCtor) { |
30 devtools.profiler.Profile.call(this); | 30 childCtor.prototype.__proto__ = parentCtor.prototype; |
| 31 }; |
| 32 |
| 33 |
| 34 function V8Profile(separateIc) { |
| 35 Profile.call(this); |
31 if (!separateIc) { | 36 if (!separateIc) { |
32 this.skipThisFunction = function(name) { return Profile.IC_RE.test(name); }; | 37 this.skipThisFunction = function(name) { return V8Profile.IC_RE.test(name);
}; |
33 } | 38 } |
34 }; | 39 }; |
35 Profile.prototype = devtools.profiler.Profile.prototype; | 40 inherits(V8Profile, Profile); |
36 | 41 |
37 | 42 |
38 Profile.IC_RE = | 43 V8Profile.IC_RE = |
39 /^(?:CallIC|LoadIC|StoreIC)|(?:Builtin: (?:Keyed)?(?:Call|Load|Store)IC_)/; | 44 /^(?:CallIC|LoadIC|StoreIC)|(?:Builtin: (?:Keyed)?(?:Call|Load|Store)IC_)/; |
40 | 45 |
41 | 46 |
42 /** | 47 /** |
43 * A thin wrapper around shell's 'read' function showing a file name on error. | 48 * A thin wrapper around shell's 'read' function showing a file name on error. |
44 */ | 49 */ |
45 function readFile(fileName) { | 50 function readFile(fileName) { |
46 try { | 51 try { |
47 return read(fileName); | 52 return read(fileName); |
48 } catch (e) { | 53 } catch (e) { |
49 print(fileName + ': ' + (e.message || e)); | 54 print(fileName + ': ' + (e.message || e)); |
50 throw e; | 55 throw e; |
51 } | 56 } |
52 } | 57 } |
53 | 58 |
54 | 59 |
55 function inherits(childCtor, parentCtor) { | |
56 childCtor.prototype.__proto__ = parentCtor.prototype; | |
57 }; | |
58 | |
59 | |
60 function SnapshotLogProcessor() { | 60 function SnapshotLogProcessor() { |
61 devtools.profiler.LogReader.call(this, { | 61 LogReader.call(this, { |
62 'code-creation': { | 62 'code-creation': { |
63 parsers: [null, parseInt, parseInt, null], | 63 parsers: [null, parseInt, parseInt, null], |
64 processor: this.processCodeCreation }, | 64 processor: this.processCodeCreation }, |
65 'code-move': { parsers: [parseInt, parseInt], | 65 'code-move': { parsers: [parseInt, parseInt], |
66 processor: this.processCodeMove }, | 66 processor: this.processCodeMove }, |
67 'code-delete': { parsers: [parseInt], | 67 'code-delete': { parsers: [parseInt], |
68 processor: this.processCodeDelete }, | 68 processor: this.processCodeDelete }, |
69 'function-creation': null, | 69 'function-creation': null, |
70 'function-move': null, | 70 'function-move': null, |
71 'function-delete': null, | 71 'function-delete': null, |
72 'snapshot-pos': { parsers: [parseInt, parseInt], | 72 'snapshot-pos': { parsers: [parseInt, parseInt], |
73 processor: this.processSnapshotPosition }}); | 73 processor: this.processSnapshotPosition }}); |
74 | 74 |
75 Profile.prototype.handleUnknownCode = function(operation, addr) { | 75 V8Profile.prototype.handleUnknownCode = function(operation, addr) { |
76 var op = devtools.profiler.Profile.Operation; | 76 var op = Profile.Operation; |
77 switch (operation) { | 77 switch (operation) { |
78 case op.MOVE: | 78 case op.MOVE: |
79 print('Snapshot: Code move event for unknown code: 0x' + | 79 print('Snapshot: Code move event for unknown code: 0x' + |
80 addr.toString(16)); | 80 addr.toString(16)); |
81 break; | 81 break; |
82 case op.DELETE: | 82 case op.DELETE: |
83 print('Snapshot: Code delete event for unknown code: 0x' + | 83 print('Snapshot: Code delete event for unknown code: 0x' + |
84 addr.toString(16)); | 84 addr.toString(16)); |
85 break; | 85 break; |
86 } | 86 } |
87 }; | 87 }; |
88 | 88 |
89 this.profile_ = new Profile(); | 89 this.profile_ = new V8Profile(); |
90 this.serializedEntries_ = []; | 90 this.serializedEntries_ = []; |
91 } | 91 } |
92 inherits(SnapshotLogProcessor, devtools.profiler.LogReader); | 92 inherits(SnapshotLogProcessor, LogReader); |
93 | 93 |
94 | 94 |
95 SnapshotLogProcessor.prototype.processCodeCreation = function( | 95 SnapshotLogProcessor.prototype.processCodeCreation = function( |
96 type, start, size, name) { | 96 type, start, size, name) { |
97 var entry = this.profile_.addCode(type, name, start, size); | 97 var entry = this.profile_.addCode(type, name, start, size); |
98 }; | 98 }; |
99 | 99 |
100 | 100 |
101 SnapshotLogProcessor.prototype.processCodeMove = function(from, to) { | 101 SnapshotLogProcessor.prototype.processCodeMove = function(from, to) { |
102 this.profile_.moveCode(from, to); | 102 this.profile_.moveCode(from, to); |
(...skipping 17 matching lines...) Expand all Loading... |
120 | 120 |
121 | 121 |
122 SnapshotLogProcessor.prototype.getSerializedEntryName = function(pos) { | 122 SnapshotLogProcessor.prototype.getSerializedEntryName = function(pos) { |
123 var entry = this.serializedEntries_[pos]; | 123 var entry = this.serializedEntries_[pos]; |
124 return entry ? entry.getRawName() : null; | 124 return entry ? entry.getRawName() : null; |
125 }; | 125 }; |
126 | 126 |
127 | 127 |
128 function TickProcessor( | 128 function TickProcessor( |
129 cppEntriesProvider, separateIc, ignoreUnknown, stateFilter, snapshotLogProce
ssor) { | 129 cppEntriesProvider, separateIc, ignoreUnknown, stateFilter, snapshotLogProce
ssor) { |
130 devtools.profiler.LogReader.call(this, { | 130 LogReader.call(this, { |
131 'shared-library': { parsers: [null, parseInt, parseInt], | 131 'shared-library': { parsers: [null, parseInt, parseInt], |
132 processor: this.processSharedLibrary }, | 132 processor: this.processSharedLibrary }, |
133 'code-creation': { | 133 'code-creation': { |
134 parsers: [null, parseInt, parseInt, null], | 134 parsers: [null, parseInt, parseInt, null], |
135 processor: this.processCodeCreation }, | 135 processor: this.processCodeCreation }, |
136 'code-move': { parsers: [parseInt, parseInt], | 136 'code-move': { parsers: [parseInt, parseInt], |
137 processor: this.processCodeMove }, | 137 processor: this.processCodeMove }, |
138 'code-delete': { parsers: [parseInt], | 138 'code-delete': { parsers: [parseInt], |
139 processor: this.processCodeDelete }, | 139 processor: this.processCodeDelete }, |
140 'function-creation': { parsers: [parseInt, parseInt], | 140 'function-creation': { parsers: [parseInt, parseInt], |
(...skipping 24 matching lines...) Expand all Loading... |
165 'end-code-region': null }); | 165 'end-code-region': null }); |
166 | 166 |
167 this.cppEntriesProvider_ = cppEntriesProvider; | 167 this.cppEntriesProvider_ = cppEntriesProvider; |
168 this.ignoreUnknown_ = ignoreUnknown; | 168 this.ignoreUnknown_ = ignoreUnknown; |
169 this.stateFilter_ = stateFilter; | 169 this.stateFilter_ = stateFilter; |
170 this.snapshotLogProcessor_ = snapshotLogProcessor; | 170 this.snapshotLogProcessor_ = snapshotLogProcessor; |
171 this.deserializedEntriesNames_ = []; | 171 this.deserializedEntriesNames_ = []; |
172 var ticks = this.ticks_ = | 172 var ticks = this.ticks_ = |
173 { total: 0, unaccounted: 0, excluded: 0, gc: 0 }; | 173 { total: 0, unaccounted: 0, excluded: 0, gc: 0 }; |
174 | 174 |
175 Profile.prototype.handleUnknownCode = function( | 175 V8Profile.prototype.handleUnknownCode = function( |
176 operation, addr, opt_stackPos) { | 176 operation, addr, opt_stackPos) { |
177 var op = devtools.profiler.Profile.Operation; | 177 var op = Profile.Operation; |
178 switch (operation) { | 178 switch (operation) { |
179 case op.MOVE: | 179 case op.MOVE: |
180 print('Code move event for unknown code: 0x' + addr.toString(16)); | 180 print('Code move event for unknown code: 0x' + addr.toString(16)); |
181 break; | 181 break; |
182 case op.DELETE: | 182 case op.DELETE: |
183 print('Code delete event for unknown code: 0x' + addr.toString(16)); | 183 print('Code delete event for unknown code: 0x' + addr.toString(16)); |
184 break; | 184 break; |
185 case op.TICK: | 185 case op.TICK: |
186 // Only unknown PCs (the first frame) are reported as unaccounted, | 186 // Only unknown PCs (the first frame) are reported as unaccounted, |
187 // otherwise tick balance will be corrupted (this behavior is compatible | 187 // otherwise tick balance will be corrupted (this behavior is compatible |
188 // with the original tickprocessor.py script.) | 188 // with the original tickprocessor.py script.) |
189 if (opt_stackPos == 0) { | 189 if (opt_stackPos == 0) { |
190 ticks.unaccounted++; | 190 ticks.unaccounted++; |
191 } | 191 } |
192 break; | 192 break; |
193 } | 193 } |
194 }; | 194 }; |
195 | 195 |
196 this.profile_ = new Profile(separateIc); | 196 this.profile_ = new V8Profile(separateIc); |
197 this.codeTypes_ = {}; | 197 this.codeTypes_ = {}; |
198 // Count each tick as a time unit. | 198 // Count each tick as a time unit. |
199 this.viewBuilder_ = new devtools.profiler.ViewBuilder(1); | 199 this.viewBuilder_ = new ViewBuilder(1); |
200 this.lastLogFileName_ = null; | 200 this.lastLogFileName_ = null; |
201 | 201 |
202 this.generation_ = 1; | 202 this.generation_ = 1; |
203 this.currentProducerProfile_ = null; | 203 this.currentProducerProfile_ = null; |
204 }; | 204 }; |
205 inherits(TickProcessor, devtools.profiler.LogReader); | 205 inherits(TickProcessor, LogReader); |
206 | 206 |
207 | 207 |
208 TickProcessor.VmStates = { | 208 TickProcessor.VmStates = { |
209 JS: 0, | 209 JS: 0, |
210 GC: 1, | 210 GC: 1, |
211 COMPILER: 2, | 211 COMPILER: 2, |
212 OTHER: 3, | 212 OTHER: 3, |
213 EXTERNAL: 4 | 213 EXTERNAL: 4 |
214 }; | 214 }; |
215 | 215 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } | 349 } |
350 } | 350 } |
351 } | 351 } |
352 | 352 |
353 this.profile_.recordTick(this.processStack(pc, func, stack)); | 353 this.profile_.recordTick(this.processStack(pc, func, stack)); |
354 }; | 354 }; |
355 | 355 |
356 | 356 |
357 TickProcessor.prototype.processHeapSampleBegin = function(space, state, ticks) { | 357 TickProcessor.prototype.processHeapSampleBegin = function(space, state, ticks) { |
358 if (space != 'Heap') return; | 358 if (space != 'Heap') return; |
359 this.currentProducerProfile_ = new devtools.profiler.CallTree(); | 359 this.currentProducerProfile_ = new CallTree(); |
360 }; | 360 }; |
361 | 361 |
362 | 362 |
363 TickProcessor.prototype.processHeapSampleEnd = function(space, state) { | 363 TickProcessor.prototype.processHeapSampleEnd = function(space, state) { |
364 if (space != 'Heap' || !this.currentProducerProfile_) return; | 364 if (space != 'Heap' || !this.currentProducerProfile_) return; |
365 | 365 |
366 print('Generation ' + this.generation_ + ':'); | 366 print('Generation ' + this.generation_ + ':'); |
367 var tree = this.currentProducerProfile_; | 367 var tree = this.currentProducerProfile_; |
368 tree.computeTotalWeights(); | 368 tree.computeTotalWeights(); |
369 var producersView = this.viewBuilder_.buildView(tree); | 369 var producersView = this.viewBuilder_.buildView(tree); |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 if (arg !== synArg && dispatch === this.argsDispatch_[synArg]) { | 845 if (arg !== synArg && dispatch === this.argsDispatch_[synArg]) { |
846 synonims.push(synArg); | 846 synonims.push(synArg); |
847 delete this.argsDispatch_[synArg]; | 847 delete this.argsDispatch_[synArg]; |
848 } | 848 } |
849 } | 849 } |
850 print(' ' + padRight(synonims.join(', '), 20) + dispatch[2]); | 850 print(' ' + padRight(synonims.join(', '), 20) + dispatch[2]); |
851 } | 851 } |
852 quit(2); | 852 quit(2); |
853 }; | 853 }; |
854 | 854 |
OLD | NEW |