Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / importer / linux_perf_importer_test.html
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7
8 <link rel="import" href="/tracing/test_utils.html">
9 <link rel="import" href="/tracing/importer/linux_perf_importer.html">
10
11 <script>
12 'use strict';
13
14 tv.unittest.testSuite(function() { // @suppress longLineCheck
15   test('lineParserWithLegacyFmt', function() {
16     var p = tracing.importer._LinuxPerfImporterTestExports.lineParserWithLegacyFmt; // @suppress longLineCheck
17     var x = p('   <idle>-0     [001]  4467.843475: sched_switch: ' +
18         'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
19         'next_comm=SurfaceFlinger next_pid=178 next_prio=112');
20     assertNotNull(x);
21     assertEquals('<idle>', x.threadName);
22     assertEquals('0', x.pid);
23     assertEquals('001', x.cpuNumber);
24     assertEquals('4467.843475', x.timestamp);
25     assertEquals('sched_switch', x.eventName);
26     assertEquals('prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R' +
27         ' ==> next_comm=SurfaceFlinger next_pid=178 next_prio=112', x.details);
28
29     var x = p('Binder-Thread #-647   [001]   260.464294: sched_switch: ' +
30         'prev_comm=Binder Thread # prev_pid=647 prev_prio=120 prev_state=D ' +
31         ' ==> next_comm=.android.chrome next_pid=1562 next_prio=120');
32     assertNotNull(x);
33     assertEquals('Binder-Thread #', x.threadName);
34     assertEquals('647', x.pid);
35   });
36
37   test('lineParserWithIRQInfo', function() {
38     var p = tracing.importer._LinuxPerfImporterTestExports.lineParserWithIRQInfo; // @suppress longLineCheck
39     var x = p('     systrace.sh-5441  [001] d...  1031.091570: ' +
40         'sched_wakeup: comm=debugd pid=4978 prio=120 success=1 target_cpu=000');
41     assertNotNull(x);
42     assertEquals('systrace.sh', x.threadName);
43     assertEquals('5441', x.pid);
44     assertEquals('001', x.cpuNumber);
45     assertEquals('1031.091570', x.timestamp);
46     assertEquals('sched_wakeup', x.eventName);
47     assertEquals('comm=debugd pid=4978 prio=120 success=1 target_cpu=000', x.details); // @suppress longLineCheck
48   });
49
50   test('lineParserWithTGID', function() {
51     var p = tracing.importer._LinuxPerfImporterTestExports.lineParserWithTGID;
52     var x = p('     systrace.sh-5441  (54321) [001] d...  1031.091570: ' +
53         'sched_wakeup: comm=debugd pid=4978 prio=120 success=1 target_cpu=000');
54     assertNotNull(x);
55     assertEquals('systrace.sh', x.threadName);
56     assertEquals('5441', x.pid);
57     assertEquals('54321', x.tgid);
58     assertEquals('001', x.cpuNumber);
59     assertEquals('1031.091570', x.timestamp);
60     assertEquals('sched_wakeup', x.eventName);
61     assertEquals('comm=debugd pid=4978 prio=120 success=1 target_cpu=000', x.details); // @suppress longLineCheck
62
63     var x = p('     systrace.sh-5441  (  321) [001] d...  1031.091570: ' +
64         'sched_wakeup: comm=debugd pid=4978 prio=120 success=1 target_cpu=000');
65     assertNotNull(x);
66     assertEquals('321', x.tgid);
67
68     var x = p('     systrace.sh-5441  (-----) [001] d...  1031.091570: ' +
69         'sched_wakeup: comm=debugd pid=4978 prio=120 success=1 target_cpu=000');
70     assertNotNull(x);
71     assertEquals(undefined, x.tgid);
72   });
73
74   test('autodetectLineCornerCases', function() {
75     var detectParser =
76         tracing.importer._LinuxPerfImporterTestExports.autoDetectLineParser;
77     var lineParserWithLegacyFmt =
78         tracing.importer._LinuxPerfImporterTestExports.lineParserWithLegacyFmt;
79     var lineParserWithIRQInfo =
80         tracing.importer._LinuxPerfImporterTestExports.lineParserWithIRQInfo;
81     var lineParserWithTGID =
82         tracing.importer._LinuxPerfImporterTestExports.lineParserWithTGID;
83
84     var lineWithLegacyFmt =
85         'systrace.sh-8170  [001] 15180.978813: sched_switch: ' +
86         'prev_comm=systrace.sh prev_pid=8170 prev_prio=120 ' +
87         'prev_state=x ==> next_comm=kworker/1:0 next_pid=7873 ' +
88         'next_prio=120';
89     var detected = detectParser(lineWithLegacyFmt);
90     assertEquals(detected, lineParserWithLegacyFmt);
91
92     var lineWithIRQInfo =
93         'systrace.sh-8170  [001] d... 15180.978813: sched_switch: ' +
94         'prev_comm=systrace.sh prev_pid=8170 prev_prio=120 ' +
95         'prev_state=x ==> next_comm=kworker/1:0 next_pid=7873 ' +
96         'next_prio=120';
97     var detected = detectParser(lineWithIRQInfo);
98     assertEquals(detected, lineParserWithIRQInfo);
99
100     var lineWithTGID =
101         'systrace.sh-8170  (54321) [001] d... 15180.978813: sched_switch: ' +
102         'prev_comm=systrace.sh prev_pid=8170 prev_prio=120 ' +
103         'prev_state=x ==> next_comm=kworker/1:0 next_pid=7873 ' +
104         'next_prio=120';
105     var detected = detectParser(lineWithTGID);
106     assertEquals(detected, lineParserWithTGID);
107   });
108
109   test('traceEventClockSyncRE', function() {
110     var re = tracing.importer._LinuxPerfImporterTestExports.traceEventClockSyncRE; // @suppress longLineCheck
111     var x = re.exec('trace_event_clock_sync: parent_ts=19581477508');
112     assertNotNull(x);
113     assertEquals('19581477508', x[1]);
114
115     var x = re.exec('trace_event_clock_sync: parent_ts=123.456');
116     assertNotNull(x);
117     assertEquals('123.456', x[1]);
118   });
119
120   test('canImport', function() {
121     var lines = [
122       '# tracer: nop',
123       '#',
124       '#           TASK-PID    CPU#    TIMESTAMP  FUNCTION',
125       '#              | |       |          |         |',
126       '          <idle>-0     [001]  4467.843475: sched_switch: ' +
127           'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
128           'next_comm=SurfaceFlinger next_pid=178 next_prio=112',
129
130       '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
131           'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 prev_state=S ' +
132           '==> next_comm=kworker/u:2 next_pid=2844 next_prio=120',
133
134       '     kworker/u:2-2844  [001]  4467.843567: sched_switch: ' +
135           'prev_comm=kworker/u:2 prev_pid=2844 prev_prio=120 prev_state=S ' +
136           '==> next_comm=swapper next_pid=0 next_prio=120',
137
138       '          <idle>-0     [001]  4467.844208: sched_switch: ' +
139           'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
140           'next_comm=kworker/u:2 next_pid=2844 next_prio=120'
141     ];
142     assertTrue(tracing.importer.LinuxPerfImporter.canImport(lines.join('\n')));
143
144     var lines = [
145       '          <idle>-0     [001]  4467.843475: sched_switch: ' +
146           'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
147               'next_comm=SurfaceFlinger next_pid=178 next_prio=112'
148     ];
149     assertTrue(tracing.importer.LinuxPerfImporter.canImport(lines.join('\n')));
150
151     var lines = [
152       '          <idle>-0     [001]  4467.843475: sched_switch: ' +
153           'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
154           'next_comm=SurfaceFlinger next_pid=178 next_prio=112',
155
156       '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
157           'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 ' +
158           'prev_state=S ==> next_comm=kworker/u:2 next_pid=2844 ' +
159           'next_prio=120'
160     ];
161     assertTrue(tracing.importer.LinuxPerfImporter.canImport(lines.join('\n')));
162
163     var lines = [
164       'SomeRandomText',
165       'More random text'
166     ];
167     assertFalse(tracing.importer.LinuxPerfImporter.canImport(lines.join('\n')));
168   });
169
170   test('canImport34AndLater', function() {
171     var lines = [
172       '# tracer: nop',
173       '#',
174       '# entries-in-buffer/entries-written: 55191/55191   #P:2',
175       '#',
176       '#                              _-----=> irqs-off',
177       '#                             / _----=> need-resched',
178       '#                            | / _---=> hardirq/softirq',
179       '#                            || / _--=> preempt-depth',
180       '#                            ||| /     delay',
181       '#           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION',
182       '#              | |       |   ||||       |         |',
183       '     systrace.sh-5441  [001] d...  1031.091570: sched_wakeup: ' +
184           'comm=debugd pid=4978 prio=120 success=1 target_cpu=000',
185       '     systrace.sh-5441  [001] d...  1031.091584: sched_switch: ' +
186           'prev_comm=systrace.sh prev_pid=5441 prev_prio=120 prev_state=x ' +
187           '==> next_comm=chrome next_pid=5418 next_prio=120'
188     ];
189     assertTrue(tracing.importer.LinuxPerfImporter.canImport(lines.join('\n')));
190
191     var lines = [
192       '     systrace.sh-5441  [001] d...  1031.091570: sched_wakeup: ' +
193           'comm=debugd pid=4978 prio=120 success=1 target_cpu=000',
194       '     systrace.sh-5441  [001] d...  1031.091584: sched_switch: ' +
195           'prev_comm=systrace.sh prev_pid=5441 prev_prio=120 prev_state=x ' +
196           '==> next_comm=chrome next_pid=5418 next_prio=120'
197     ];
198     assertTrue(tracing.importer.LinuxPerfImporter.canImport(lines.join('\n')));
199   });
200
201   test('importOneSequence', function() {
202     var lines = [
203       '          <idle>-0     [001]  4467.843475: sched_switch: ' +
204           'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
205           'next_comm=SurfaceFlinger next_pid=178 next_prio=112',
206
207       '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
208           'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 ' +
209           'prev_state=S ==> next_comm=kworker/u:2 next_pid=2844 ' +
210           'next_prio=120',
211
212       '     kworker/u:2-2844  [001]  4467.843567: sched_switch: ' +
213           'prev_comm=kworker/u:2 prev_pid=2844 prev_prio=120 ' +
214           'prev_state=S ==> next_comm=swapper next_pid=0 next_prio=120'
215     ];
216     var m = new tracing.TraceModel(lines.join('\n'), false);
217     assertFalse(m.hasImportWarnings);
218
219     var c = m.kernel.cpus[1];
220     assertEquals(2, c.slices.length);
221
222     assertEquals('SurfaceFlinger', c.slices[0].title);
223     assertEquals(4467843.475, c.slices[0].start);
224     assertAlmostEquals(.536 - .475, c.slices[0].duration);
225   });
226
227   test('importOneSequenceWithSpacyThreadName', function() {
228     var lines = [
229       '          <idle>-0     [001]  4467.843475: sched_switch: ' +
230           'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
231           'next_comm=Surface Flinger  next_pid=178 next_prio=112',
232
233       'Surface Flinger -178   [001]  4467.843536: sched_switch: ' +
234           'prev_comm=Surface Flinger  prev_pid=178 prev_prio=112 ' +
235           'prev_state=S ==> next_comm=kworker/u:2 next_pid=2844 ' +
236           'next_prio=120',
237
238       '     kworker/u:2-2844  [001]  4467.843567: sched_switch: ' +
239           'prev_comm=kworker/u:2 prev_pid=2844 prev_prio=120 ' +
240           'prev_state=S ==> next_comm=swapper next_pid=0 next_prio=120'
241     ];
242     var m = new tracing.TraceModel(lines.join('\n'), false);
243     assertFalse(m.hasImportWarnings);
244
245     var c = m.kernel.cpus[1];
246     assertEquals(2, c.slices.length);
247
248     assertEquals('Surface Flinger ', c.slices[0].title);
249     assertEquals(4467843.475, c.slices[0].start);
250     assertAlmostEquals(.536 - .475, c.slices[0].duration);
251   });
252
253   test('importWithNewline', function() {
254     var lines = [
255       ''
256     ];
257     var m = new tracing.TraceModel(lines.join('\n'));
258     assertFalse(m.hasImportWarnings);
259   });
260
261   test('clockSync', function() {
262     var lines = [
263       '          <idle>-0     [001]  4467.843475: sched_switch: ' +
264           'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ' +
265           '==> next_comm=SurfaceFlinger next_pid=178 next_prio=112',
266       '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
267           'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 ' +
268           'prev_state=S ==> next_comm=kworker/u:2 next_pid=2844 ' +
269           'next_prio=120',
270       '     kworker/u:2-2844  [001]  4467.843567: sched_switch: ' +
271           'prev_comm=kworker/u:2 prev_pid=2844 prev_prio=120 ' +
272           'prev_state=S ==> next_comm=swapper next_pid=0 ' +
273           'next_prio=120',
274       '     kworker/u:2-2844  [001]  4467.843000: 0: ' +
275           'trace_event_clock_sync: parent_ts=0.1'
276     ];
277     var m = new tracing.TraceModel(lines.join('\n'), false);
278     assertFalse(m.hasImportWarnings);
279
280     var c = m.kernel.cpus[1];
281     assertEquals(2, c.slices.length);
282
283     assertAlmostEquals((467.843475 - (467.843 - 0.1)) * 1000,
284                        c.slices[0].start);
285   });
286
287   test('clockSyncMarkWrite', function() {
288     var lines = [
289       'systrace.sh-8170  [001] 15180.978813: sched_switch: ' +
290           'prev_comm=systrace.sh prev_pid=8170 prev_prio=120 ' +
291           'prev_state=x ==> next_comm=kworker/1:0 next_pid=7873 ' +
292           'next_prio=120',
293       ' kworker/1:0-7873  [001] 15180.978836: sched_switch: ' +
294           'prev_comm=kworker/1:0 prev_pid=7873 prev_prio=120 ' +
295           'prev_state=S ==> next_comm=debugd next_pid=4404 next_prio=120',
296       '     debugd-4404  [001] 15180.979010: sched_switch: prev_comm=debugd ' +
297           'prev_pid=4404 prev_prio=120 prev_state=S ==> ' +
298           'next_comm=dbus-daemon next_pid=510 next_prio=120',
299       'systrace.sh-8182  [000] 15186.203900: tracing_mark_write: ' +
300           'trace_event_clock_sync: parent_ts=0'
301     ];
302     var m = new tracing.TraceModel(lines.join('\n'), false);
303     assertFalse(m.hasImportWarnings);
304
305     var c = m.kernel.cpus[1];
306     assertEquals(2, c.slices.length);
307
308     assertAlmostEquals((15180.978813 - 0) * 1000, c.slices[0].start);
309   });
310
311   test('tracingMarkWriteEOLCleanup', function() {
312     var lines = [
313       'systrace.sh-8182  [001] ...1 2068001.677892: tracing_mark_write: ' +
314           'B|9304|test\\n\\',
315       'systrace.sh-8182  [002] ...1 2068991.686415: tracing_mark_write: E\\n\\'
316     ];
317
318     var m = new tracing.TraceModel(lines.join('\n'), false);
319     assertFalse(m.hasImportWarnings);
320
321     var c = m.processes[9304].threads[8182].sliceGroup;
322     assertEquals(1, c.slices.length);
323
324     assertAlmostEquals((2068001.677892 - 0) * 1000, c.slices[0].start);
325     assertAlmostEquals((2068991.686415 - 2068001.677892) * 1000,
326         c.slices[0].duration);
327   });
328
329   test('cpuCount', function() {
330     var lines = [
331       'systrace.sh-8170  [001] 15180.978813: sched_switch: ' +
332           'prev_comm=systrace.sh prev_pid=8170 prev_prio=120 ' +
333           'prev_state=x ==> next_comm=kworker/1:0 next_pid=7873 ' +
334           'next_prio=120',
335       ' kworker/1:0-7873  [001] 15180.978836: sched_switch: ' +
336           'prev_comm=kworker/1:0 prev_pid=7873 prev_prio=120 ' +
337           'prev_state=S ==> next_comm=debugd next_pid=4404 next_prio=120',
338       '     debugd-4404  [000] 15180.979010: sched_switch: prev_comm=debugd ' +
339           'prev_pid=4404 prev_prio=120 prev_state=S ==> ' +
340           'next_comm=dbus-daemon next_pid=510 next_prio=120'
341     ];
342     var m = new tracing.TraceModel(lines.join('\n'), false);
343     assertFalse(m.hasImportWarnings);
344
345     assertEquals(2, tv.dictionaryLength(m.kernel.cpus));
346     assertEquals(2, m.kernel.bestGuessAtCpuCount);
347   });
348 });
349 </script>
350