1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 tvcm.require('tracing.test_utils');
8 tvcm.require('tracing.importer.v8_log_importer');
10 tvcm.unittest.testSuite('tracing.importer.v8_log_importer_test', function() {
11 var V8LogImporter = tracing.importer.V8LogImporter;
13 test('tickEventInSharedLibrary', function() {
15 'shared-library,"/usr/lib/libc++.1.dylib",0x99d8aae0,0x99dce729',
16 'tick,0x99d8aae4,12158,0,0x0,5'];
17 var m = new tracing.TraceModel(lines.join('\n'));
18 var p = m.processes[-32];
19 var threads = p.findAllThreadsNamed('V8 PC');
21 assertEquals(1, t.samples.length);
22 assertEquals('/usr/lib/libc++.1.dylib', t.samples[0].title);
25 test('tickEventInGeneratedCode', function() {
27 'shared-library,"/usr/lib/libc++.1.dylib",0x99d8aae0,0x99dce729',
28 'code-creation,Stub,2,0x5b60ce80,1259,"StringAddStub"',
29 'tick,0x5b60ce84,12158,0,0x0,5'];
30 var m = new tracing.TraceModel(lines.join('\n'));
31 var p = m.processes[-32];
32 var threads = p.findAllThreadsNamed('V8 PC');
34 assertEquals(1, t.samples.length);
35 assertEquals('StringAddStub', t.samples[0].title);
38 test('tickEventInUknownCode', function() {
40 'shared-library,"/usr/lib/libc++.1.dylib",0x99d8aae0,0x99dce729',
41 'code-creation,Stub,2,0x5b60ce80,1259,"StringAddStub"',
42 'tick,0x4,0xbff02f08,12158,0,0x0,5'];
43 var m = new tracing.TraceModel(lines.join('\n'));
44 var p = m.processes[-32];
45 var threads = p.findAllThreadsNamed('V8 PC');
47 assertEquals(1, t.samples.length);
48 assertEquals('UnknownCode', t.samples[0].title);
49 threads = p.findAllThreadsNamed('V8 JavaScript');
51 assertEquals(1, t.sliceGroup.slices.length);
54 test('tickEventWithStack', function() {
56 'code-creation,LazyCompile,0,0x2905d0c0,1800,"InstantiateFunction native apinatives.js:26:29",0x56b19124,', // @suppress longLineCheck
57 'tick,0x7fc6fe34,528674,0,0x3,0,0x2905d304'];
58 var m = new tracing.TraceModel(lines.join('\n'));
59 var p = m.processes[-32];
60 var threads = p.findAllThreadsNamed('V8 PC');
62 assertEquals(1, t.samples.length);
63 threads = p.findAllThreadsNamed('V8 JavaScript');
65 assertEquals(1, t.sliceGroup.slices.length);
68 test('twoTickEventsWithStack', function() {
70 'code-creation,LazyCompile,0,0x2905d0c0,1800,"InstantiateFunction native apinatives.js:26:29",0x56b19124,', // @suppress longLineCheck
71 'tick,0x7fc6fe34,528674,0,0x3,0,0x2905d304',
72 'tick,0x7fd2a534,536213,0,0x81d8d080,0,0x2905d304'];
73 var m = new tracing.TraceModel(lines.join('\n'));
74 var p = m.processes[-32];
75 var threads = p.findAllThreadsNamed('V8 PC');
77 assertEquals(2, t.samples.length);
78 threads = p.findAllThreadsNamed('V8 JavaScript');
80 assertEquals(1, t.sliceGroup.slices.length);
81 var slice = t.sliceGroup.slices[0];
82 assertEquals(0, slice.start);
83 assertAlmostEquals((536213 - 528674) / 1000, slice.duration);
86 test('twoTickEventsWithTwoStackFrames', function() {
88 'code-creation,LazyCompile,0,0x2904d560,876,"Instantiate native apinatives.js:9:21",0x56b190c8,~', // @suppress longLineCheck
89 'code-creation,LazyCompile,0,0x2905d0c0,1800,"InstantiateFunction native apinatives.js:26:29",0x56b19124,', // @suppress longLineCheck
90 'tick,0x7fc6fe34,528674,0,0x3,0,0x2905d304,0x2904d6e8',
91 'tick,0x7fd2a534,536213,0,0x81d8d080,0,0x2905d304,0x2904d6e8'];
92 var m = new tracing.TraceModel(lines.join('\n'));
93 var p = m.processes[-32];
94 var threads = p.findAllThreadsNamed('V8 PC');
96 assertEquals(2, t.samples.length);
97 threads = p.findAllThreadsNamed('V8 JavaScript');
99 assertEquals(2, t.sliceGroup.slices.length);
100 var slice = t.sliceGroup.slices[0];
101 assertEquals(0, slice.start);
102 assertAlmostEquals((536213 - 528674) / 1000, slice.duration);
103 assertEquals('Instantiate native apinatives.js:9:21', slice.title);
104 assertEquals(1, slice.subSlices.length);
105 var subSlice = slice.subSlices[0];
106 assertEquals(0, subSlice.start);
107 assertAlmostEquals((536213 - 528674) / 1000, subSlice.duration);
108 assertEquals('InstantiateFunction native apinatives.js:26:29',
112 test('threeTickEventsWithTwoStackFrames', function() {
114 'code-creation,LazyCompile,0,0x2904d560,876,"Instantiate native apinatives.js:9:21",0x56b190c8,~', // @suppress longLineCheck
115 'code-creation,LazyCompile,0,0x2905d0c0,1800,"InstantiateFunction native apinatives.js:26:29",0x56b19124,', // @suppress longLineCheck
116 'tick,0x7fd7f75c,518328,0,0x81d86da8,2,0x2904d6e8',
117 'tick,0x7fc6fe34,528674,0,0x3,0,0x2905d304,0x2904d6e8',
118 'tick,0x7fd2a534,536213,0,0x81d8d080,0,0x2905d304,0x2904d6e8'];
119 var m = new tracing.TraceModel(lines.join('\n'));
120 var p = m.processes[-32];
121 var threads = p.findAllThreadsNamed('V8 PC');
123 assertEquals(3, t.samples.length);
124 threads = p.findAllThreadsNamed('V8 JavaScript');
126 assertEquals(2, t.sliceGroup.slices.length);
127 var slice = t.sliceGroup.slices[0];
128 assertEquals(0, slice.start);
129 assertAlmostEquals((536213 - 518328) / 1000, slice.duration);
130 assertEquals('Instantiate native apinatives.js:9:21', slice.title);
131 assertEquals(1, slice.subSlices.length);
132 var subSlice = slice.subSlices[0];
133 assertAlmostEquals((528674 - 518328) / 1000, subSlice.start);
134 assertAlmostEquals((536213 - 528674) / 1000, subSlice.duration);
135 assertEquals('InstantiateFunction native apinatives.js:26:29',
137 assertEquals(subSlice, t.sliceGroup.slices[1]);
140 test('twoSubStacks', function() {
142 'code-creation,LazyCompile,0,0x2904d560,876,"Instantiate native apinatives.js:9:21",0x56b190c8,~', // @suppress longLineCheck
143 'code-creation,LazyCompile,0,0x2905d0c0,1800,"InstantiateFunction native apinatives.js:26:29",0x56b19124,', // @suppress longLineCheck
144 'tick,0x7fd7f75c,518328,0,0x81d86da8,2,0x2904d6e8',
145 'tick,0x7fc6fe34,528674,0,0x3,0,0x2905d304,0x2904d6e8',
146 'tick,0x7fd2a534,536213,0,0x81d8d080,0,0x2905d304,0x2904d6e8',
147 'code-creation,Script,0,0x2906a7c0,792,"http://www.google.com/",0x5b12fe50,~', // @suppress longLineCheck
148 'tick,0xb6f51d30,794049,0,0xb6f7b368,2,0x2906a914',
149 'tick,0xb6f51d30,799146,0,0xb6f7b368,0,0x2906a914'
151 var m = new tracing.TraceModel(lines.join('\n'));
152 var p = m.processes[-32];
153 var threads = p.findAllThreadsNamed('V8 PC');
155 assertEquals(5, t.samples.length);
156 threads = p.findAllThreadsNamed('V8 JavaScript');
158 assertEquals(3, t.sliceGroup.slices.length);
159 var slice = t.sliceGroup.slices[0];
160 assertEquals(0, slice.start);
161 assertAlmostEquals((536213 - 518328) / 1000, slice.duration);
162 assertEquals('Instantiate native apinatives.js:9:21', slice.title);
163 assertEquals(1, slice.subSlices.length);
164 var subSlice = slice.subSlices[0];
165 assertAlmostEquals((528674 - 518328) / 1000, subSlice.start);
166 assertAlmostEquals((536213 - 528674) / 1000, subSlice.duration);
167 assertEquals('InstantiateFunction native apinatives.js:26:29',
169 assertEquals(subSlice, t.sliceGroup.slices[1]);
170 slice = t.sliceGroup.slices[2];
171 assertAlmostEquals((794049 - 518328) / 1000, slice.start);
172 assertAlmostEquals((799146 - 794049) / 1000, slice.duration);
173 assertEquals('http://www.google.com/', slice.title);
176 test('twoUnrelatedTickEventsWithStack', function() {
178 'code-creation,LazyCompile,0,0x2905d0c0,1800,"InstantiateFunction native apinatives.js:26:29",0x56b19124,', // @suppress longLineCheck
179 'tick,0x7fc6fe34,528674,0,0x3,0,0x2905d304',
180 'tick,0x7fc6fe34,529674,0,0x3,0,0x2905d304'];
181 var m = new tracing.TraceModel(lines.join('\n'));
182 var p = m.processes[-32];
183 var threads = p.findAllThreadsNamed('V8 PC');
185 assertEquals(2, t.samples.length);
186 assertEquals('UnknownCode', t.samples[0].title);
187 threads = p.findAllThreadsNamed('V8 JavaScript');
189 assertEquals(1, t.sliceGroup.slices.length);
190 var slice = t.sliceGroup.slices[0];
191 assertEquals(0, slice.start);
192 assertEquals(1, slice.duration);
195 test('timerEventSliceCreation', function() {
196 var lines = ['timer-event,"V8.External",38189483,3'];
197 var m = new tracing.TraceModel(lines.join('\n'));
198 var p = m.processes[-32];
199 var threads = p.findAllThreadsNamed('V8 Timers');
200 assertNotUndefined(threads);
201 assertEquals(1, threads.length);
203 assertEquals(1, t.sliceGroup.length);
206 test('processThreadCreation', function() {
207 var lines = ['timer-event,"V8.External",38189483,3'];
208 var m = new tracing.TraceModel(lines.join('\n'));
209 assertNotUndefined(m);
210 var p = m.processes[-32];
211 assertNotUndefined(p);
212 var threads = p.findAllThreadsNamed('V8 Timers');
213 assertNotUndefined(threads);
214 assertEquals(threads.length, 1);
216 assertEquals(t.name, 'V8 Timers');
219 test('canImport', function() {
220 assertTrue(V8LogImporter.canImport(
221 'timer-event,"V8.External",38189483,3'));
222 assertFalse(V8LogImporter.canImport(''));
223 assertFalse(V8LogImporter.canImport([]));