OLD | NEW |
| (Empty) |
1 // Copyright 2009 the V8 project authors. All rights reserved. | |
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 // Load implementations from <project root>/tools. | |
29 // Files: tools/splaytree.js tools/codemap.js tools/csvparser.js | |
30 // Files: tools/consarray.js tools/profile.js tools/profile_view.js | |
31 // Files: tools/logreader.js tools/tickprocessor.js | |
32 | |
33 (function testArgumentsProcessor() { | |
34 var p_default = new ArgumentsProcessor([]); | |
35 assertTrue(p_default.parse()); | |
36 assertEquals(ArgumentsProcessor.DEFAULTS, p_default.result()); | |
37 | |
38 var p_logFile = new ArgumentsProcessor(['logfile.log']); | |
39 assertTrue(p_logFile.parse()); | |
40 assertEquals('logfile.log', p_logFile.result().logFileName); | |
41 | |
42 var p_platformAndLog = new ArgumentsProcessor(['--windows', 'winlog.log']); | |
43 assertTrue(p_platformAndLog.parse()); | |
44 assertEquals('windows', p_platformAndLog.result().platform); | |
45 assertEquals('winlog.log', p_platformAndLog.result().logFileName); | |
46 | |
47 var p_flags = new ArgumentsProcessor(['--gc', '--separate-ic']); | |
48 assertTrue(p_flags.parse()); | |
49 assertEquals(TickProcessor.VmStates.GC, p_flags.result().stateFilter); | |
50 assertTrue(p_flags.result().separateIc); | |
51 | |
52 var p_nmAndLog = new ArgumentsProcessor(['--nm=mn', 'nmlog.log']); | |
53 assertTrue(p_nmAndLog.parse()); | |
54 assertEquals('mn', p_nmAndLog.result().nm); | |
55 assertEquals('nmlog.log', p_nmAndLog.result().logFileName); | |
56 | |
57 var p_bad = new ArgumentsProcessor(['--unknown', 'badlog.log']); | |
58 assertFalse(p_bad.parse()); | |
59 })(); | |
60 | |
61 | |
62 (function testUnixCppEntriesProvider() { | |
63 var oldLoadSymbols = UnixCppEntriesProvider.prototype.loadSymbols; | |
64 | |
65 // shell executable | |
66 UnixCppEntriesProvider.prototype.loadSymbols = function(libName) { | |
67 this.symbols = [[ | |
68 ' U operator delete[](void*)@@GLIBCXX_3.4', | |
69 '08049790 T _init', | |
70 '08049f50 T _start', | |
71 '08139150 t v8::internal::Runtime_StringReplaceRegExpWithString(v8::intern
al::Arguments)', | |
72 '08139ca0 T v8::internal::Runtime::GetElementOrCharAt(v8::internal::Handle
<v8::internal::Object>, unsigned int)', | |
73 '0813a0b0 t v8::internal::Runtime_DebugGetPropertyDetails(v8::internal::Ar
guments)', | |
74 '08181d30 W v8::internal::RegExpMacroAssemblerIrregexp::stack_limit_slack(
)', | |
75 ' w __gmon_start__', | |
76 '081f08a0 B stdout' | |
77 ].join('\n'), '']; | |
78 }; | |
79 | |
80 var shell_prov = new UnixCppEntriesProvider(); | |
81 var shell_syms = []; | |
82 shell_prov.parseVmSymbols('shell', 0x08048000, 0x081ee000, | |
83 function (name, start, end) { | |
84 shell_syms.push(Array.prototype.slice.apply(arguments, [0])); | |
85 }); | |
86 assertEquals( | |
87 [['_init', 0x08049790, 0x08049f50], | |
88 ['_start', 0x08049f50, 0x08139150], | |
89 ['v8::internal::Runtime_StringReplaceRegExpWithString(v8::internal::Argum
ents)', 0x08139150, 0x08139ca0], | |
90 ['v8::internal::Runtime::GetElementOrCharAt(v8::internal::Handle<v8::inte
rnal::Object>, unsigned int)', 0x08139ca0, 0x0813a0b0], | |
91 ['v8::internal::Runtime_DebugGetPropertyDetails(v8::internal::Arguments)'
, 0x0813a0b0, 0x08181d30], | |
92 ['v8::internal::RegExpMacroAssemblerIrregexp::stack_limit_slack()', 0x081
81d30, 0x081ee000]], | |
93 shell_syms); | |
94 | |
95 // libc library | |
96 UnixCppEntriesProvider.prototype.loadSymbols = function(libName) { | |
97 this.symbols = [[ | |
98 '000162a0 T __libc_init_first', | |
99 '0002a5f0 T __isnan', | |
100 '0002a5f0 W isnan', | |
101 '0002aaa0 W scalblnf', | |
102 '0002aaa0 W scalbnf', | |
103 '0011a340 T __libc_thread_freeres', | |
104 '00128860 R _itoa_lower_digits'].join('\n'), '']; | |
105 }; | |
106 var libc_prov = new UnixCppEntriesProvider(); | |
107 var libc_syms = []; | |
108 libc_prov.parseVmSymbols('libc', 0xf7c5c000, 0xf7da5000, | |
109 function (name, start, end) { | |
110 libc_syms.push(Array.prototype.slice.apply(arguments, [0])); | |
111 }); | |
112 assertEquals( | |
113 [['__libc_init_first', 0xf7c5c000 + 0x000162a0, 0xf7c5c000 + 0x0002a5f0], | |
114 ['isnan', 0xf7c5c000 + 0x0002a5f0, 0xf7c5c000 + 0x0002aaa0], | |
115 ['scalbnf', 0xf7c5c000 + 0x0002aaa0, 0xf7c5c000 + 0x0011a340], | |
116 ['__libc_thread_freeres', 0xf7c5c000 + 0x0011a340, 0xf7da5000]], | |
117 libc_syms); | |
118 | |
119 UnixCppEntriesProvider.prototype.loadSymbols = oldLoadSymbols; | |
120 })(); | |
121 | |
122 | |
123 (function testWindowsCppEntriesProvider() { | |
124 var oldLoadSymbols = WindowsCppEntriesProvider.prototype.loadSymbols; | |
125 | |
126 WindowsCppEntriesProvider.prototype.loadSymbols = function(libName) { | |
127 this.symbols = [ | |
128 ' Start Length Name Class', | |
129 ' 0001:00000000 000ac902H .text CODE', | |
130 ' 0001:000ac910 000005e2H .text$yc CODE', | |
131 ' Address Publics by Value Rva+Base Lib:Object
', | |
132 ' 0000:00000000 __except_list 00000000 <absolute>', | |
133 ' 0001:00000000 ?ReadFile@@YA?AV?$Handle@VString@v8@@@v8@@PBD@Z 0040
1000 f shell.obj', | |
134 ' 0001:000000a0 ?Print@@YA?AV?$Handle@VValue@v8@@@v8@@ABVArguments@2
@@Z 004010a0 f shell.obj', | |
135 ' 0001:00001230 ??1UTF8Buffer@internal@v8@@QAE@XZ 00402230 f v8_sn
apshot:scanner.obj', | |
136 ' 0001:00001230 ??1Utf8Value@String@v8@@QAE@XZ 00402230 f v8_snaps
hot:api.obj', | |
137 ' 0001:000954ba __fclose_nolock 004964ba f LIBCMT:fclos
e.obj', | |
138 ' 0002:00000000 __imp__SetThreadPriority@8 004af000 kernel32:KER
NEL32.dll', | |
139 ' 0003:00000418 ?in_use_list_@PreallocatedStorage@internal@v8@@0V123
@A 00544418 v8_snapshot:allocation.obj', | |
140 ' Static symbols', | |
141 ' 0001:00000b70 ?DefaultFatalErrorHandler@v8@@YAXPBD0@Z 00401b70 f
v8_snapshot:api.obj', | |
142 ' 0001:000010b0 ?EnsureInitialized@v8@@YAXPBD@Z 004020b0 f v8_snap
shot:api.obj', | |
143 ' 0001:000ad17b ??__Fnomem@?5???2@YAPAXI@Z@YAXXZ 004ae17b f LIBCMT
:new.obj' | |
144 ].join('\r\n'); | |
145 }; | |
146 var shell_prov = new WindowsCppEntriesProvider(); | |
147 var shell_syms = []; | |
148 shell_prov.parseVmSymbols('shell.exe', 0x00400000, 0x0057c000, | |
149 function (name, start, end) { | |
150 shell_syms.push(Array.prototype.slice.apply(arguments, [0])); | |
151 }); | |
152 assertEquals( | |
153 [['ReadFile', 0x00401000, 0x004010a0], | |
154 ['Print', 0x004010a0, 0x00402230], | |
155 ['v8::String::?1Utf8Value', 0x00402230, 0x004964ba], | |
156 ['v8::DefaultFatalErrorHandler', 0x00401b70, 0x004020b0], | |
157 ['v8::EnsureInitialized', 0x004020b0, 0x0057c000]], | |
158 shell_syms); | |
159 | |
160 WindowsCppEntriesProvider.prototype.loadSymbols = oldLoadSymbols; | |
161 })(); | |
162 | |
163 | |
164 function CppEntriesProviderMock() { | |
165 }; | |
166 | |
167 | |
168 CppEntriesProviderMock.prototype.parseVmSymbols = function( | |
169 name, startAddr, endAddr, symbolAdder) { | |
170 var symbols = { | |
171 'shell': | |
172 [['v8::internal::JSObject::LocalLookupRealNamedProperty(v8::internal::St
ring*, v8::internal::LookupResult*)', 0x080f8800, 0x080f8d90], | |
173 ['v8::internal::HashTable<v8::internal::StringDictionaryShape, v8::inte
rnal::String*>::FindEntry(v8::internal::String*)', 0x080f8210, 0x080f8800], | |
174 ['v8::internal::Runtime_Math_exp(v8::internal::Arguments)', 0x08123b20,
0x08123b80]], | |
175 '/lib32/libm-2.7.so': | |
176 [['exp', startAddr + 0x00009e80, startAddr + 0x00009f30], | |
177 ['fegetexcept', startAddr + 0x000061e0, startAddr + 0x00008b10]], | |
178 'ffffe000-fffff000': []}; | |
179 assertTrue(name in symbols); | |
180 var syms = symbols[name]; | |
181 for (var i = 0; i < syms.length; ++i) { | |
182 symbolAdder.apply(null, syms[i]); | |
183 } | |
184 }; | |
185 | |
186 | |
187 function PrintMonitor(outputOrFileName) { | |
188 var expectedOut = typeof outputOrFileName == 'string' ? | |
189 this.loadExpectedOutput(outputOrFileName) : outputOrFileName; | |
190 var outputPos = 0; | |
191 var diffs = this.diffs = []; | |
192 var realOut = this.realOut = []; | |
193 | |
194 this.oldPrint = print; | |
195 print = function(str) { | |
196 var strSplit = str.split('\n'); | |
197 for (var i = 0; i < strSplit.length; ++i) { | |
198 s = strSplit[i]; | |
199 realOut.push(s); | |
200 assertTrue(outputPos < expectedOut.length, | |
201 'unexpected output: "' + s + '"'); | |
202 if (expectedOut[outputPos] != s) { | |
203 diffs.push('line ' + outputPos + ': expected <' + | |
204 expectedOut[outputPos] + '> found <' + s + '>\n'); | |
205 } | |
206 outputPos++; | |
207 } | |
208 }; | |
209 }; | |
210 | |
211 | |
212 PrintMonitor.prototype.loadExpectedOutput = function(fileName) { | |
213 var output = readFile(fileName); | |
214 return output.split('\n'); | |
215 }; | |
216 | |
217 | |
218 PrintMonitor.prototype.finish = function() { | |
219 print = this.oldPrint; | |
220 if (this.diffs.length > 0) { | |
221 print(this.realOut.join('\n')); | |
222 assertEquals([], this.diffs); | |
223 } | |
224 }; | |
225 | |
226 | |
227 function driveTickProcessorTest( | |
228 separateIc, ignoreUnknown, stateFilter, logInput, refOutput) { | |
229 var TEST_PATH = 'test/mjsunit/tools/'; | |
230 var tp = new TickProcessor( | |
231 new CppEntriesProviderMock(), separateIc, ignoreUnknown, stateFilter); | |
232 var pm = new PrintMonitor(TEST_PATH + refOutput); | |
233 tp.processLogFile(TEST_PATH + logInput); | |
234 // Hack file name to avoid dealing with platform specifics. | |
235 tp.lastLogFileName_ = 'v8.log'; | |
236 tp.printStatistics(); | |
237 pm.finish(); | |
238 }; | |
239 | |
240 | |
241 (function testProcessing() { | |
242 var testData = { | |
243 'Default': [ | |
244 false, false, null, | |
245 'tickprocessor-test.log', 'tickprocessor-test.default'], | |
246 'SeparateIc': [ | |
247 true, false, null, | |
248 'tickprocessor-test.log', 'tickprocessor-test.separate-ic'], | |
249 'IgnoreUnknown': [ | |
250 false, true, null, | |
251 'tickprocessor-test.log', 'tickprocessor-test.ignore-unknown'], | |
252 'GcState': [ | |
253 false, false, TickProcessor.VmStates.GC, | |
254 'tickprocessor-test.log', 'tickprocessor-test.gc-state'] | |
255 }; | |
256 for (var testName in testData) { | |
257 print('=== testProcessing-' + testName + ' ==='); | |
258 driveTickProcessorTest.apply(null, testData[testName]); | |
259 } | |
260 })(); | |
OLD | NEW |