Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / src / tracing / importer / v8_log_importer_test.js
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.
4
5 'use strict';
6
7 tvcm.require('tracing.test_utils');
8 tvcm.require('tracing.importer.v8_log_importer');
9
10 tvcm.unittest.testSuite('tracing.importer.v8_log_importer_test', function() {
11   var V8LogImporter = tracing.importer.V8LogImporter;
12
13   test('tickEventInSharedLibrary', function() {
14     var lines = [
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');
20     var t = threads[0];
21     assertEquals(1, t.samples.length);
22     assertEquals('/usr/lib/libc++.1.dylib', t.samples[0].title);
23   });
24
25   test('tickEventInGeneratedCode', function() {
26     var lines = [
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');
33     var t = threads[0];
34     assertEquals(1, t.samples.length);
35     assertEquals('StringAddStub', t.samples[0].title);
36   });
37
38   test('tickEventInUknownCode', function() {
39     var lines = [
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');
46     var t = threads[0];
47     assertEquals(1, t.samples.length);
48     assertEquals('UnknownCode', t.samples[0].title);
49     threads = p.findAllThreadsNamed('V8 JavaScript');
50     t = threads[0];
51     assertEquals(1, t.sliceGroup.slices.length);
52   });
53
54   test('tickEventWithStack', function() {
55     var lines = [
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');
61     var t = threads[0];
62     assertEquals(1, t.samples.length);
63     threads = p.findAllThreadsNamed('V8 JavaScript');
64     t = threads[0];
65     assertEquals(1, t.sliceGroup.slices.length);
66   });
67
68   test('twoTickEventsWithStack', function() {
69     var lines = [
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');
76     var t = threads[0];
77     assertEquals(2, t.samples.length);
78     threads = p.findAllThreadsNamed('V8 JavaScript');
79     t = threads[0];
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);
84   });
85
86   test('twoTickEventsWithTwoStackFrames', function() {
87     var lines = [
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');
95     var t = threads[0];
96     assertEquals(2, t.samples.length);
97     threads = p.findAllThreadsNamed('V8 JavaScript');
98     t = threads[0];
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',
109                  subSlice.title);
110   });
111
112   test('threeTickEventsWithTwoStackFrames', function() {
113     var lines = [
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');
122     var t = threads[0];
123     assertEquals(3, t.samples.length);
124     threads = p.findAllThreadsNamed('V8 JavaScript');
125     t = threads[0];
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',
136                  subSlice.title);
137     assertEquals(subSlice, t.sliceGroup.slices[1]);
138   });
139
140   test('twoSubStacks', function() {
141     var lines = [
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'
150     ];
151     var m = new tracing.TraceModel(lines.join('\n'));
152     var p = m.processes[-32];
153     var threads = p.findAllThreadsNamed('V8 PC');
154     var t = threads[0];
155     assertEquals(5, t.samples.length);
156     threads = p.findAllThreadsNamed('V8 JavaScript');
157     t = threads[0];
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',
168                  subSlice.title);
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);
174   });
175
176   test('twoUnrelatedTickEventsWithStack', function() {
177     var lines = [
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');
184     var t = threads[0];
185     assertEquals(2, t.samples.length);
186     assertEquals('UnknownCode', t.samples[0].title);
187     threads = p.findAllThreadsNamed('V8 JavaScript');
188     t = threads[0];
189     assertEquals(1, t.sliceGroup.slices.length);
190     var slice = t.sliceGroup.slices[0];
191     assertEquals(0, slice.start);
192     assertEquals(1, slice.duration);
193   });
194
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);
202     var t = threads[0];
203     assertEquals(1, t.sliceGroup.length);
204   });
205
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);
215     var t = threads[0];
216     assertEquals(t.name, 'V8 Timers');
217   });
218
219   test('canImport', function() {
220     assertTrue(V8LogImporter.canImport(
221         'timer-event,"V8.External",38189483,3'));
222     assertFalse(V8LogImporter.canImport(''));
223     assertFalse(V8LogImporter.canImport([]));
224   });
225 });