summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/tracing/linux_perf_importer_test.html
blob: 847e11130277cd9d33c58bb4dbf9d4d865759945 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<!DOCTYPE html>
<html>
<!--
Copyright (c) 2012 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<title>LinuxPerfImporter tests</title>
<script src=
    "http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js">
</script>
<script src="../shared/js/cr.js"></script>
<script src="../shared/js/cr/event_target.js"></script>
<script src="test_utils.js"></script>
<script src="timeline_model.js"></script>
<script src="linux_perf_importer.js"></script>
<script>
  goog.require('goog.testing.jsunit');
</script>

</head>
<body>
<script>
function testLineRE() {
  var re = tracing._LinuxPerfImporterTestExports.lineRE;
  var x = re.exec('   <idle>-0     [001]  4467.843475: sched_switch: ' +
      'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
      'next_comm=SurfaceFlinger next_pid=178 next_prio=112');
  assertNotNull(x);
  assertEquals('<idle>-0', x[1]);
  assertEquals('001', x[2]);
  assertEquals('4467.843475', x[3]);
  assertEquals('sched_switch', x[4]);
  assertEquals('prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
      'next_comm=SurfaceFlinger next_pid=178 next_prio=112', x[5]);

  var x = re.exec('Binder Thread #-647   [001]   260.464294: sched_switch: ' +
      'prev_comm=Binder Thread # prev_pid=647 prev_prio=120 prev_state=D ==> ' +
      'next_comm=.android.chrome next_pid=1562 next_prio=120');
  assertNotNull(x);
}

function testSchedSwitchRE() {
  var re = tracing._LinuxPerfImporterTestExports.schedSwitchRE;
  var x = re.exec('prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ' +
      '==> next_comm=SurfaceFlinger next_pid=178 next_prio=112');
  assertNotNull(x);
  assertEquals('swapper', x[1]);
  assertEquals('0', x[2]);
  assertEquals('120', x[3]);
  assertEquals('R', x[4]);
  assertEquals('SurfaceFlinger', x[5]);
  assertEquals('178', x[6]);
  assertEquals('112', x[7]);

  var x = re.exec('prev_comm=.android.chrome prev_pid=1562 prev_prio=120 ' +
      'prev_state=R ==> next_comm=Binder Thread # next_pid=195 next_prio=120');
  assertNotNull(x);
  assertEquals('.android.chrome', x[1]);
  assertEquals('Binder Thread #', x[5]);

  var x = re.exec('prev_comm=Binder Thread # prev_pid=1562 prev_prio=120 ' +
      'prev_state=R ==> next_comm=.android.chrome next_pid=195 next_prio=120');
  assertNotNull(x);
  assertEquals('Binder Thread #', x[1]);
  assertEquals('.android.chrome', x[5]);
}

function testSchedWakeupRE() {
  var re = tracing._LinuxPerfImporterTestExports.schedWakeupRE;
  var x = re.exec(
      'comm=SensorService pid=207 prio=112 success=1 target_cpu=000');
  assertNotNull(x);
  assertEquals('SensorService', x[1]);
  assertEquals('207', x[2]);
  assertEquals('112', x[3]);
  assertEquals('1', x[4]);
  assertEquals('000', x[5]);
}

function testTraceEventClockSyncRE() {
  var re = tracing._LinuxPerfImporterTestExports.traceEventClockSyncRE;
  var x = re.exec('trace_event_clock_sync: parent_ts=19581477508');
  assertNotNull(x);
  assertEquals('19581477508', x[1]);

  var x = re.exec('trace_event_clock_sync: parent_ts=123.456');
  assertNotNull(x);
  assertEquals('123.456', x[1]);
}

function testCanImport() {
  var lines = [
    '# tracer: nop',
    '#',
    '#           TASK-PID    CPU#    TIMESTAMP  FUNCTION',
    '#              | |       |          |         |',
    '          <idle>-0     [001]  4467.843475: sched_switch: ' +
        'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
        'next_comm=SurfaceFlinger next_pid=178 next_prio=112',

    '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
        'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 prev_state=S ' +
        '==> next_comm=kworker/u:2 next_pid=2844 next_prio=120',

    '     kworker/u:2-2844  [001]  4467.843567: sched_switch: ' +
        'prev_comm=kworker/u:2 prev_pid=2844 prev_prio=120 prev_state=S ' +
        '==> next_comm=swapper next_pid=0 next_prio=120',

    '          <idle>-0     [001]  4467.844208: sched_switch: ' +
          'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
          'next_comm=kworker/u:2 next_pid=2844 next_prio=120'
  ];
  assertTrue(tracing.LinuxPerfImporter.canImport(lines.join('\n')));

  var lines = [
    '          <idle>-0     [001]  4467.843475: sched_switch: ' +
            'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
            'next_comm=SurfaceFlinger next_pid=178 next_prio=112'
  ];
  assertTrue(tracing.LinuxPerfImporter.canImport(lines.join('\n')));

  var lines = [
    '          <idle>-0     [001]  4467.843475: sched_switch: ' +
              'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
              'next_comm=SurfaceFlinger next_pid=178 next_prio=112',

    '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
              'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 ' +
              'prev_state=S ==> next_comm=kworker/u:2 next_pid=2844 ' +
              'next_prio=120'
  ];
  assertTrue(tracing.LinuxPerfImporter.canImport(lines.join('\n')));

  var lines = [
    'SomeRandomText',
    'More random text'
  ];
  assertFalse(tracing.LinuxPerfImporter.canImport(lines.join('\n')));
}

function testImportOneSequence() {
  var lines = [
    '          <idle>-0     [001]  4467.843475: sched_switch: ' +
                'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
                'next_comm=SurfaceFlinger next_pid=178 next_prio=112',

                '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
                'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 ' +
                'prev_state=S ==> next_comm=kworker/u:2 next_pid=2844 ' +
                'next_prio=120',

                '     kworker/u:2-2844  [001]  4467.843567: sched_switch: ' +
                'prev_comm=kworker/u:2 prev_pid=2844 prev_prio=120 ' +
                'prev_state=S ==> next_comm=swapper next_pid=0 next_prio=120'
  ];
  var m = new tracing.TimelineModel(lines.join('\n'), false);
  assertEquals(0, m.importErrors.length);

  var c = m.cpus[1];
  assertEquals(2, c.slices.length);

  assertEquals('SurfaceFlinger', c.slices[0].title);
  assertEquals(4467843.475, c.slices[0].start);
  assertAlmostEquals(.536 - .475, c.slices[0].duration);
}

function testImportOneSequenceWithSchedWakeUp() {
  // TODO(nduca): write test for this.
}

function testImportWithNewline() {
  var lines = [
    ''
  ];
  var m = new tracing.TimelineModel(lines.join('\n'));
  assertEquals(0, m.importErrors.length);
}

function testClockSync() {
  var lines = [
    '          <idle>-0     [001]  4467.843475: sched_switch: ' +
                  'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ' +
                  '==> next_comm=SurfaceFlinger next_pid=178 next_prio=112',
    '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
                  'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 ' +
                  'prev_state=S ==> next_comm=kworker/u:2 next_pid=2844 ' +
                  'next_prio=120',
    '     kworker/u:2-2844  [001]  4467.843567: sched_switch: ' +
                  'prev_comm=kworker/u:2 prev_pid=2844 prev_prio=120 ' +
                  'prev_state=S ==> next_comm=swapper next_pid=0 ' +
                  'next_prio=120',
    '     kworker/u:2-2844  [001]  4467.843000: 0: ' +
                  'trace_event_clock_sync: parent_ts=0.1'
  ];
  var m = new tracing.TimelineModel(lines.join('\n'), false);
  assertEquals(0, m.importErrors.length);

  var c = m.cpus[1];
  assertEquals(2, c.slices.length);

  assertAlmostEquals((467.843475 - (467.843 - 0.1)) * 1000, c.slices[0].start);
}

function testClockSyncMarkWrite() {
  var lines = [
    'systrace.sh-8170  [001] 15180.978813: sched_switch: ' +
              'prev_comm=systrace.sh prev_pid=8170 prev_prio=120 ' +
              'prev_state=x ==> next_comm=kworker/1:0 next_pid=7873 ' +
              'next_prio=120',
    ' kworker/1:0-7873  [001] 15180.978836: sched_switch: ' +
              'prev_comm=kworker/1:0 prev_pid=7873 prev_prio=120 ' +
              'prev_state=S ==> next_comm=debugd next_pid=4404 next_prio=120',
    '     debugd-4404  [001] 15180.979010: sched_switch: prev_comm=debugd ' +
              'prev_pid=4404 prev_prio=120 prev_state=S ==> ' +
              'next_comm=dbus-daemon next_pid=510 next_prio=120',
    'systrace.sh-8182  [000] 15186.203900: tracing_mark_write: ' +
              'trace_event_clock_sync: parent_ts=0'
  ];
  var m = new tracing.TimelineModel(lines.join('\n'), false);
  assertEquals(0, m.importErrors.length);

  var c = m.cpus[1];
  assertEquals(2, c.slices.length);

  assertAlmostEquals((15180.978813 - 0) * 1000, c.slices[0].start);
}


function testImportWithoutClockSyncDeletesEverything() {
}

function testWorkQueueImport() {
  var lines = [
    ' kworker/0:3-6880  [000]  2784.771958: workqueue_execute_start: ' +
               'work struct ffff8800a5083a20: function intel_unpin_work_fn',
    ' kworker/0:3-6880  [000]  2784.771966: workqueue_execute_end: ' +
               'work struct ffff8800a5083a20',
    ' kworker/1:2-7269  [001]  2784.805966: workqueue_execute_start: ' +
               'work struct ffff88014fb0f158: function do_dbs_timer',
    ' kworker/1:2-7269  [001]  2784.805975: workqueue_execute_end: ' +
               'work struct ffff88014fb0f158'
  ];
  var m = new tracing.TimelineModel(lines.join('\n'), false);
  assertEquals(0, m.importErrors.length);

  assertEquals(1, m.processes['6880'].threads['6880'].subRows.length);
  assertEquals(1, m.processes['7269'].threads['7269'].subRows.length);
}

function testPowerStartImport() {
}

function testPowerFrequencyImport() {
  var lines = [
    ' kworker/0:3-6880  [000]  2784.783015: power_frequency: ' +
               'type=2 state=1000000 cpu_id=0',
    ' kworker/1:2-7269  [001]  2784.788993: power_frequency: ' +
               'type=2 state=800000 cpu_id=1',
    ' kworker/1:2-7269  [001]  2784.993120: power_frequency: ' +
               'type=2 state=1300000 cpu_id=1'
  ];
  var m = new tracing.TimelineModel(lines.join('\n'), false);
  assertEquals(0, m.importErrors.length);

  var c0 = m.cpus[0];
  assertEquals(0, c0.slices.length);
  assertEquals(1, c0.counters['Power Frequency'].samples.length);

  var c1 = m.cpus[1];
  assertEquals(0, c1.slices.length);
  assertEquals(2, c1.counters['Power Frequency'].samples.length);
}

function testCpuFrequencyImport() {
  var lines = [
    '     kworker/1:0-9665  [001] 15051.007301: cpu_frequency: ' +
                   'state=800000 cpu_id=1',
    '     kworker/1:0-9665  [001] 15051.010278: cpu_frequency: ' +
                   'state=1300000 cpu_id=1',
    '     kworker/0:2-7972  [000] 15051.010278: cpu_frequency: ' +
                   'state=1000000 cpu_id=0',
    '     kworker/0:2-7972  [000] 15051.020304: cpu_frequency: ' +
                   'state=800000 cpu_id=0'
  ];
  var m = new tracing.TimelineModel(lines.join('\n'), false);
  assertEquals(0, m.importErrors.length);

  var c0 = m.cpus[0];
  assertEquals(0, c0.slices.length);
  assertEquals(2, c0.counters['Clock Frequency'].samples.length);

  var c1 = m.cpus[1];
  assertEquals(0, c1.slices.length);
  assertEquals(2, c1.counters['Clock Frequency'].samples.length);
}

function testCpuIdleImport() {
  var lines = [
    '          <idle>-0     [000] 15050.992883: cpu_idle: ' +
                  'state=1 cpu_id=0',
    '          <idle>-0     [000] 15050.993027: cpu_idle: ' +
                  'state=4294967295 cpu_id=0',
    '          <idle>-0     [001] 15050.993132: cpu_idle: ' +
                  'state=1 cpu_id=1',
    '          <idle>-0     [001] 15050.993276: cpu_idle: ' +
                  'state=4294967295 cpu_id=1',
    '          <idle>-0     [001] 15050.993279: cpu_idle: ' +
                  'state=3 cpu_id=1',
    '          <idle>-0     [001] 15050.993457: cpu_idle: ' +
                  'state=4294967295 cpu_id=1',
  ];
  var m = new tracing.TimelineModel(lines.join('\n'), false);
  assertEquals(0, m.importErrors.length);

  var c0 = m.cpus[0];
  assertEquals(0, c0.slices.length);
  assertEquals(2, c0.counters['C-State'].samples.length);

  var c1 = m.cpus[1];
  assertEquals(0, c1.slices.length);
  assertEquals(4, c1.counters['C-State'].samples.length);
}

function testi915Import() {
  var lines = [
    '          chrome-1223  [000]  2784.773556: i915_gem_object_pwrite: ' +
               'obj=ffff88013f13fc00, offset=0, len=2984',
    '               X-964   [000]  2784.774864: i915_flip_request: ' +
               'plane=0, obj=ffff88013f0b9a00',
    '          <idle>-0     [000]  2784.788644: i915_flip_complete: ' +
               'plane=0, obj=ffff88013f0b9a00'
  ];
  var m = new tracing.TimelineModel(lines.join('\n'), false);
  assertEquals(0, m.importErrors.length);

  assertEquals('i915_gem', m.processes['0'].threads['1'].name);
  assertEquals(1, m.processes['0'].threads['1'].subRows.length);

  assertEquals('i915_flip', m.processes['0'].threads['2'].name);
  assertEquals(1, m.processes['0'].threads['1'].subRows.length);

  assertAlmostEquals(2784.774864 * 1000.0,
      m.processes['0'].threads['2'].subRows[0][0].start);
  assertAlmostEquals((2784.788644 - 2784.774864) * 1000.0,
      m.processes['0'].threads['2'].subRows[0][0].duration);
}

</script>
</body>
</html>