• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html>
3<!--
4Copyright (c) 2012 The Chromium Authors. All rights reserved.
5Use of this source code is governed by a BSD-style license that can be
6found in the LICENSE file.
7-->
8<head>
9<title>LinuxPerfImporter tests</title>
10<script src=
11    "http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js">
12</script>
13<script src="../shared/js/cr.js"></script>
14<script src="../shared/js/cr/event_target.js"></script>
15<script src="test_utils.js"></script>
16<script src="timeline_model.js"></script>
17<script src="linux_perf_importer.js"></script>
18<script>
19  goog.require('goog.testing.jsunit');
20</script>
21
22</head>
23<body>
24<script>
25function testLineRE() {
26  var re = tracing._LinuxPerfImporterTestExports.lineRE;
27  var x = re.exec('   <idle>-0     [001]  4467.843475: sched_switch: ' +
28      'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
29      'next_comm=SurfaceFlinger next_pid=178 next_prio=112');
30  assertNotNull(x);
31  assertEquals('<idle>-0', x[1]);
32  assertEquals('001', x[2]);
33  assertEquals(undefined, x[3]);
34  assertEquals('4467.843475', x[4]);
35  assertEquals('sched_switch', x[5]);
36  assertEquals('prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
37      'next_comm=SurfaceFlinger next_pid=178 next_prio=112', x[6]);
38
39  var x = re.exec('Binder Thread #-647   [001]   260.464294: sched_switch: ' +
40      'prev_comm=Binder Thread # prev_pid=647 prev_prio=120 prev_state=D ==> ' +
41      'next_comm=.android.chrome next_pid=1562 next_prio=120');
42  assertNotNull(x);
43}
44
45function testSchedSwitchRE() {
46  var re = tracing._LinuxPerfImporterTestExports.eventDefinitions['sched_switch'].format;
47  var x = re.exec('prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ' +
48      '==> next_comm=SurfaceFlinger next_pid=178 next_prio=112');
49  assertNotNull(x);
50  assertEquals('swapper', x[1]);
51  assertEquals('0', x[2]);
52  assertEquals('120', x[3]);
53  assertEquals('R', x[4]);
54  assertEquals('SurfaceFlinger', x[5]);
55  assertEquals('178', x[6]);
56  assertEquals('112', x[7]);
57
58  var x = re.exec('prev_comm=.android.chrome prev_pid=1562 prev_prio=120 ' +
59      'prev_state=R ==> next_comm=Binder Thread # next_pid=195 next_prio=120');
60  assertNotNull(x);
61  assertEquals('.android.chrome', x[1]);
62  assertEquals('Binder Thread #', x[5]);
63
64  var x = re.exec('prev_comm=Binder Thread # prev_pid=1562 prev_prio=120 ' +
65      'prev_state=R ==> next_comm=.android.chrome next_pid=195 next_prio=120');
66  assertNotNull(x);
67  assertEquals('Binder Thread #', x[1]);
68  assertEquals('.android.chrome', x[5]);
69}
70
71function testSchedWakeupRE() {
72  var re = tracing._LinuxPerfImporterTestExports.eventDefinitions['sched_wakeup'].format;
73  var x = re.exec(
74      'comm=SensorService pid=207 prio=112 success=1 target_cpu=000');
75  assertNotNull(x);
76  assertEquals('SensorService', x[1]);
77  assertEquals('207', x[2]);
78  assertEquals('112', x[3]);
79  assertEquals('1', x[4]);
80  assertEquals('000', x[5]);
81}
82
83function testTraceEventClockSyncRE() {
84  var re = tracing._LinuxPerfImporterTestExports.traceEventClockSyncRE;
85  var x = re.exec('trace_event_clock_sync: parent_ts=19581477508');
86  assertNotNull(x);
87  assertEquals('19581477508', x[1]);
88
89  var x = re.exec('trace_event_clock_sync: parent_ts=123.456');
90  assertNotNull(x);
91  assertEquals('123.456', x[1]);
92}
93
94function testCanImport() {
95  var lines = [
96    '# tracer: nop',
97    '#',
98    '#           TASK-PID    CPU#    TIMESTAMP  FUNCTION',
99    '#              | |       |          |         |',
100    '          <idle>-0     [001]  4467.843475: sched_switch: ' +
101        'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
102        'next_comm=SurfaceFlinger next_pid=178 next_prio=112',
103
104    '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
105        'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 prev_state=S ' +
106        '==> next_comm=kworker/u:2 next_pid=2844 next_prio=120',
107
108    '     kworker/u:2-2844  [001]  4467.843567: sched_switch: ' +
109        'prev_comm=kworker/u:2 prev_pid=2844 prev_prio=120 prev_state=S ' +
110        '==> next_comm=swapper next_pid=0 next_prio=120',
111
112    '          <idle>-0     [001]  4467.844208: sched_switch: ' +
113          'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
114          'next_comm=kworker/u:2 next_pid=2844 next_prio=120'
115  ];
116  assertTrue(tracing.LinuxPerfImporter.canImport(lines.join('\n')));
117
118  var lines = [
119    '          <idle>-0     [001]  4467.843475: sched_switch: ' +
120            'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
121            'next_comm=SurfaceFlinger next_pid=178 next_prio=112'
122  ];
123  assertTrue(tracing.LinuxPerfImporter.canImport(lines.join('\n')));
124
125  var lines = [
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 ' +
132              'prev_state=S ==> next_comm=kworker/u:2 next_pid=2844 ' +
133              'next_prio=120'
134  ];
135  assertTrue(tracing.LinuxPerfImporter.canImport(lines.join('\n')));
136
137  var lines = [
138    'SomeRandomText',
139    'More random text'
140  ];
141  assertFalse(tracing.LinuxPerfImporter.canImport(lines.join('\n')));
142}
143
144function testImportOneSequence() {
145  var lines = [
146    '          <idle>-0     [001]  4467.843475: sched_switch: ' +
147                'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
148                'next_comm=SurfaceFlinger next_pid=178 next_prio=112',
149
150                '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
151                'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 ' +
152                'prev_state=S ==> next_comm=kworker/u:2 next_pid=2844 ' +
153                'next_prio=120',
154
155                '     kworker/u:2-2844  [001]  4467.843567: sched_switch: ' +
156                'prev_comm=kworker/u:2 prev_pid=2844 prev_prio=120 ' +
157                'prev_state=S ==> next_comm=swapper next_pid=0 next_prio=120'
158  ];
159  var m = new tracing.TimelineModel(lines.join('\n'), false);
160  assertEquals(0, m.importErrors.length);
161
162  var c = m.cpus[1];
163  assertEquals(2, c.slices.length);
164
165  assertEquals('SurfaceFlinger', c.slices[0].title);
166  assertEquals(4467843.475, c.slices[0].start);
167  assertAlmostEquals(.536 - .475, c.slices[0].duration);
168}
169
170function testImportOneSequenceWithSchedWakeUp() {
171  // TODO(nduca): write test for this.
172}
173
174function testImportWithNewline() {
175  var lines = [
176    ''
177  ];
178  var m = new tracing.TimelineModel(lines.join('\n'));
179  assertEquals(0, m.importErrors.length);
180}
181
182function testClockSync() {
183  var lines = [
184    '          <idle>-0     [001]  4467.843475: sched_switch: ' +
185                  'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ' +
186                  '==> next_comm=SurfaceFlinger next_pid=178 next_prio=112',
187    '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
188                  'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 ' +
189                  'prev_state=S ==> next_comm=kworker/u:2 next_pid=2844 ' +
190                  'next_prio=120',
191    '     kworker/u:2-2844  [001]  4467.843567: sched_switch: ' +
192                  'prev_comm=kworker/u:2 prev_pid=2844 prev_prio=120 ' +
193                  'prev_state=S ==> next_comm=swapper next_pid=0 ' +
194                  'next_prio=120',
195    '     kworker/u:2-2844  [001]  4467.843000: 0: ' +
196                  'trace_event_clock_sync: parent_ts=0.1'
197  ];
198  var m = new tracing.TimelineModel(lines.join('\n'), false);
199  assertEquals(0, m.importErrors.length);
200
201  var c = m.cpus[1];
202  assertEquals(2, c.slices.length);
203
204  assertAlmostEquals((467.843475 - (467.843 - 0.1)) * 1000, c.slices[0].start);
205}
206
207function testClockSyncMarkWrite() {
208  var lines = [
209    'systrace.sh-8170  [001] 15180.978813: sched_switch: ' +
210              'prev_comm=systrace.sh prev_pid=8170 prev_prio=120 ' +
211              'prev_state=x ==> next_comm=kworker/1:0 next_pid=7873 ' +
212              'next_prio=120',
213    ' kworker/1:0-7873  [001] 15180.978836: sched_switch: ' +
214              'prev_comm=kworker/1:0 prev_pid=7873 prev_prio=120 ' +
215              'prev_state=S ==> next_comm=debugd next_pid=4404 next_prio=120',
216    '     debugd-4404  [001] 15180.979010: sched_switch: prev_comm=debugd ' +
217              'prev_pid=4404 prev_prio=120 prev_state=S ==> ' +
218              'next_comm=dbus-daemon next_pid=510 next_prio=120',
219    'systrace.sh-8182  [000] 15186.203900: tracing_mark_write: ' +
220              'trace_event_clock_sync: parent_ts=0'
221  ];
222  var m = new tracing.TimelineModel(lines.join('\n'), false);
223  assertEquals(0, m.importErrors.length);
224
225  var c = m.cpus[1];
226  assertEquals(2, c.slices.length);
227
228  assertAlmostEquals((15180.978813 - 0) * 1000, c.slices[0].start);
229}
230
231
232function testImportWithoutClockSyncDeletesEverything() {
233}
234
235function testWorkQueueImport() {
236  var lines = [
237    ' kworker/0:3-6880  [000]  2784.771958: workqueue_execute_start: ' +
238               'work struct ffff8800a5083a20: function intel_unpin_work_fn',
239    ' kworker/0:3-6880  [000]  2784.771966: workqueue_execute_end: ' +
240               'work struct ffff8800a5083a20',
241    ' kworker/1:2-7269  [001]  2784.805966: workqueue_execute_start: ' +
242               'work struct ffff88014fb0f158: function do_dbs_timer',
243    ' kworker/1:2-7269  [001]  2784.805975: workqueue_execute_end: ' +
244               'work struct ffff88014fb0f158'
245  ];
246  var m = new tracing.TimelineModel(lines.join('\n'), false);
247  assertEquals(0, m.importErrors.length);
248
249  assertEquals(1, m.processes['6880'].threads['6880'].subRows.length);
250  assertEquals(1, m.processes['7269'].threads['7269'].subRows.length);
251}
252
253function testPowerStartImport() {
254}
255
256function testPowerFrequencyImport() {
257  var lines = [
258    ' kworker/0:3-6880  [000]  2784.783015: power_frequency: ' +
259               'type=2 state=1000000 cpu_id=0',
260    ' kworker/1:2-7269  [001]  2784.788993: power_frequency: ' +
261               'type=2 state=800000 cpu_id=1',
262    ' kworker/1:2-7269  [001]  2784.993120: power_frequency: ' +
263               'type=2 state=1300000 cpu_id=1'
264  ];
265  var m = new tracing.TimelineModel(lines.join('\n'), false);
266  assertEquals(0, m.importErrors.length);
267
268  var c0 = m.cpus[0];
269  assertEquals(0, c0.slices.length);
270  assertEquals(1, c0.counters['Power Frequency'].samples.length);
271
272  var c1 = m.cpus[1];
273  assertEquals(0, c1.slices.length);
274  assertEquals(2, c1.counters['Power Frequency'].samples.length);
275}
276
277function testCpuFrequencyImport() {
278  var lines = [
279    '     kworker/1:0-9665  [001] 15051.007301: cpu_frequency: ' +
280                   'state=800000 cpu_id=1',
281    '     kworker/1:0-9665  [001] 15051.010278: cpu_frequency: ' +
282                   'state=1300000 cpu_id=1',
283    '     kworker/0:2-7972  [000] 15051.010278: cpu_frequency: ' +
284                   'state=1000000 cpu_id=0',
285    '     kworker/0:2-7972  [000] 15051.020304: cpu_frequency: ' +
286                   'state=800000 cpu_id=0'
287  ];
288  var m = new tracing.TimelineModel(lines.join('\n'), false);
289  assertEquals(0, m.importErrors.length);
290
291  var c0 = m.cpus[0];
292  assertEquals(0, c0.slices.length);
293  assertEquals(2, c0.counters['Clock Frequency'].samples.length);
294
295  var c1 = m.cpus[1];
296  assertEquals(0, c1.slices.length);
297  assertEquals(2, c1.counters['Clock Frequency'].samples.length);
298}
299
300function testCpuIdleImport() {
301  var lines = [
302    '          <idle>-0     [000] 15050.992883: cpu_idle: ' +
303                  'state=1 cpu_id=0',
304    '          <idle>-0     [000] 15050.993027: cpu_idle: ' +
305                  'state=4294967295 cpu_id=0',
306    '          <idle>-0     [001] 15050.993132: cpu_idle: ' +
307                  'state=1 cpu_id=1',
308    '          <idle>-0     [001] 15050.993276: cpu_idle: ' +
309                  'state=4294967295 cpu_id=1',
310    '          <idle>-0     [001] 15050.993279: cpu_idle: ' +
311                  'state=3 cpu_id=1',
312    '          <idle>-0     [001] 15050.993457: cpu_idle: ' +
313                  'state=4294967295 cpu_id=1',
314  ];
315  var m = new tracing.TimelineModel(lines.join('\n'), false);
316  assertEquals(0, m.importErrors.length);
317
318  var c0 = m.cpus[0];
319  assertEquals(0, c0.slices.length);
320  assertEquals(2, c0.counters['C-State'].samples.length);
321
322  var c1 = m.cpus[1];
323  assertEquals(0, c1.slices.length);
324  assertEquals(4, c1.counters['C-State'].samples.length);
325}
326
327function testi915Import() {
328  var lines = [
329    '          chrome-1223  [000]  2784.773556: i915_gem_object_pwrite: ' +
330               'obj=ffff88013f13fc00, offset=0, len=2984',
331    '               X-964   [000]  2784.774864: i915_flip_request: ' +
332               'plane=0, obj=ffff88013f0b9a00',
333    '          <idle>-0     [000]  2784.788644: i915_flip_complete: ' +
334               'plane=0, obj=ffff88013f0b9a00'
335  ];
336  var m = new tracing.TimelineModel(lines.join('\n'), false);
337  assertEquals(0, m.importErrors.length);
338
339  assertEquals('i915_gem', m.processes['0'].threads['1'].name);
340  assertEquals(1, m.processes['0'].threads['1'].subRows.length);
341
342  assertEquals('i915_flip', m.processes['0'].threads['2'].name);
343  assertEquals(1, m.processes['0'].threads['1'].subRows.length);
344
345  assertAlmostEquals(2784.774864 * 1000.0,
346      m.processes['0'].threads['2'].subRows[0][0].start);
347  assertAlmostEquals((2784.788644 - 2784.774864) * 1000.0,
348      m.processes['0'].threads['2'].subRows[0][0].duration);
349}
350
351</script>
352</body>
353</html>
354