Home | History | Annotate | Download | only in src
      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 Copyright (c) 2012 The Chromium Authors. All rights reserved.
      5 Use of this source code is governed by a BSD-style license that can be
      6 found in the LICENSE file.
      7 -->
      8 <head>
      9 <title>LinuxPerfImporter tests</title>
     10 <script src="base.js"></script>
     11 </head>
     12 <body>
     13 <script>
     14 'use strict';
     15 
     16 base.require('unittest');
     17 base.require('test_utils');
     18 base.require('linux_perf_importer');
     19 
     20 function testLineRE() {
     21   var re = tracing._LinuxPerfImporterTestExports.lineRE;
     22   var x = re.exec('   <idle>-0     [001]  4467.843475: sched_switch: ' +
     23       'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
     24       'next_comm=SurfaceFlinger next_pid=178 next_prio=112');
     25   assertNotNull(x);
     26   assertEquals('<idle>-0', x[1]);
     27   assertEquals('001', x[2]);
     28   assertEquals('4467.843475', x[3]);
     29   assertEquals('sched_switch', x[4]);
     30   assertEquals('prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
     31       'next_comm=SurfaceFlinger next_pid=178 next_prio=112', x[5]);
     32 
     33   var x = re.exec('Binder Thread #-647   [001]   260.464294: sched_switch: ' +
     34       'prev_comm=Binder Thread # prev_pid=647 prev_prio=120 prev_state=D ==> ' +
     35       'next_comm=.android.chrome next_pid=1562 next_prio=120');
     36   assertNotNull(x);
     37 }
     38 
     39 function testLineREWithIRQInfo() {
     40   var re = tracing._LinuxPerfImporterTestExports.lineREWithIRQInfo;
     41   var x = re.exec('     systrace.sh-5441  [001] d...  1031.091570: ' +
     42         'sched_wakeup: comm=debugd pid=4978 prio=120 success=1 target_cpu=000');
     43   assertNotNull(x);
     44   assertEquals('systrace.sh-5441', x[1]);
     45   assertEquals('001', x[2]);
     46   assertEquals('1031.091570', x[3]);
     47   assertEquals('sched_wakeup', x[4]);
     48   assertEquals('comm=debugd pid=4978 prio=120 success=1 target_cpu=000', x[5]);
     49 }
     50 
     51 function testAutodetectLineCornerCases() {
     52   var line = 'systrace.sh-8170  [001] 15180.978813: sched_switch: ' +
     53              'prev_comm=systrace.sh prev_pid=8170 prev_prio=120 ' +
     54              'prev_state=x ==> next_comm=kworker/1:0 next_pid=7873 ' +
     55              'next_prio=120';
     56   var autoLineRE = tracing._LinuxPerfImporterTestExports.autoDetectLineRE(line);
     57   var lineRE = tracing._LinuxPerfImporterTestExports.lineRE;
     58   assertEquals(autoLineRE, lineRE, 'Mis-detected line format without IRQ info');
     59 }
     60 
     61 function testTraceEventClockSyncRE() {
     62   var re = tracing._LinuxPerfImporterTestExports.traceEventClockSyncRE;
     63   var x = re.exec('trace_event_clock_sync: parent_ts=19581477508');
     64   assertNotNull(x);
     65   assertEquals('19581477508', x[1]);
     66 
     67   var x = re.exec('trace_event_clock_sync: parent_ts=123.456');
     68   assertNotNull(x);
     69   assertEquals('123.456', x[1]);
     70 }
     71 
     72 function testCanImport() {
     73   var lines = [
     74     '# tracer: nop',
     75     '#',
     76     '#           TASK-PID    CPU#    TIMESTAMP  FUNCTION',
     77     '#              | |       |          |         |',
     78     '          <idle>-0     [001]  4467.843475: sched_switch: ' +
     79         'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
     80         'next_comm=SurfaceFlinger next_pid=178 next_prio=112',
     81 
     82     '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
     83         'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 prev_state=S ' +
     84         '==> next_comm=kworker/u:2 next_pid=2844 next_prio=120',
     85 
     86     '     kworker/u:2-2844  [001]  4467.843567: sched_switch: ' +
     87         'prev_comm=kworker/u:2 prev_pid=2844 prev_prio=120 prev_state=S ' +
     88         '==> next_comm=swapper next_pid=0 next_prio=120',
     89 
     90     '          <idle>-0     [001]  4467.844208: sched_switch: ' +
     91           'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
     92           'next_comm=kworker/u:2 next_pid=2844 next_prio=120'
     93   ];
     94   assertTrue(tracing.LinuxPerfImporter.canImport(lines.join('\n')));
     95 
     96   var lines = [
     97     '          <idle>-0     [001]  4467.843475: sched_switch: ' +
     98             'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
     99             'next_comm=SurfaceFlinger next_pid=178 next_prio=112'
    100   ];
    101   assertTrue(tracing.LinuxPerfImporter.canImport(lines.join('\n')));
    102 
    103   var lines = [
    104     '          <idle>-0     [001]  4467.843475: sched_switch: ' +
    105               'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
    106               'next_comm=SurfaceFlinger next_pid=178 next_prio=112',
    107 
    108     '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
    109               'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 ' +
    110               'prev_state=S ==> next_comm=kworker/u:2 next_pid=2844 ' +
    111               'next_prio=120'
    112   ];
    113   assertTrue(tracing.LinuxPerfImporter.canImport(lines.join('\n')));
    114 
    115   var lines = [
    116     'SomeRandomText',
    117     'More random text'
    118   ];
    119   assertFalse(tracing.LinuxPerfImporter.canImport(lines.join('\n')));
    120 }
    121 
    122 function testCanImport34AndLater() {
    123   var lines = [
    124     '# tracer: nop',
    125     '#',
    126     '# entries-in-buffer/entries-written: 55191/55191   #P:2',
    127     '#',
    128     '#                              _-----=> irqs-off',
    129     '#                             / _----=> need-resched',
    130     '#                            | / _---=> hardirq/softirq',
    131     '#                            || / _--=> preempt-depth',
    132     '#                            ||| /     delay',
    133     '#           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION',
    134     '#              | |       |   ||||       |         |',
    135     '     systrace.sh-5441  [001] d...  1031.091570: sched_wakeup: ' +
    136         'comm=debugd pid=4978 prio=120 success=1 target_cpu=000',
    137     '     systrace.sh-5441  [001] d...  1031.091584: sched_switch: ' +
    138         'prev_comm=systrace.sh prev_pid=5441 prev_prio=120 prev_state=x ' +
    139         '==> next_comm=chrome next_pid=5418 next_prio=120'
    140   ];
    141   assertTrue(tracing.LinuxPerfImporter.canImport(lines.join('\n')));
    142 
    143   var lines = [
    144     '     systrace.sh-5441  [001] d...  1031.091570: sched_wakeup: ' +
    145         'comm=debugd pid=4978 prio=120 success=1 target_cpu=000',
    146     '     systrace.sh-5441  [001] d...  1031.091584: sched_switch: ' +
    147         'prev_comm=systrace.sh prev_pid=5441 prev_prio=120 prev_state=x ' +
    148         '==> next_comm=chrome next_pid=5418 next_prio=120'
    149   ];
    150   assertTrue(tracing.LinuxPerfImporter.canImport(lines.join('\n')));
    151 }
    152 
    153 function testImportOneSequence() {
    154   var lines = [
    155     '          <idle>-0     [001]  4467.843475: sched_switch: ' +
    156                 'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
    157                 'next_comm=SurfaceFlinger next_pid=178 next_prio=112',
    158 
    159                 '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
    160                 'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 ' +
    161                 'prev_state=S ==> next_comm=kworker/u:2 next_pid=2844 ' +
    162                 'next_prio=120',
    163 
    164                 '     kworker/u:2-2844  [001]  4467.843567: sched_switch: ' +
    165                 'prev_comm=kworker/u:2 prev_pid=2844 prev_prio=120 ' +
    166                 'prev_state=S ==> next_comm=swapper next_pid=0 next_prio=120'
    167   ];
    168   var m = new tracing.TimelineModel(lines.join('\n'), false);
    169   assertEquals(0, m.importErrors.length);
    170 
    171   var c = m.cpus[1];
    172   assertEquals(2, c.slices.length);
    173 
    174   assertEquals('SurfaceFlinger', c.slices[0].title);
    175   assertEquals(4467843.475, c.slices[0].start);
    176   assertAlmostEquals(.536 - .475, c.slices[0].duration);
    177 }
    178 
    179 function testImportOneSequenceWithSpacyThreadName() {
    180   var lines = [
    181     '          <idle>-0     [001]  4467.843475: sched_switch: ' +
    182                 'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
    183                 'next_comm=Surface Flinger  next_pid=178 next_prio=112',
    184 
    185                 'Surface Flinger -178   [001]  4467.843536: sched_switch: ' +
    186                 'prev_comm=Surface Flinger  prev_pid=178 prev_prio=112 ' +
    187                 'prev_state=S ==> next_comm=kworker/u:2 next_pid=2844 ' +
    188                 'next_prio=120',
    189 
    190                 '     kworker/u:2-2844  [001]  4467.843567: sched_switch: ' +
    191                 'prev_comm=kworker/u:2 prev_pid=2844 prev_prio=120 ' +
    192                 'prev_state=S ==> next_comm=swapper next_pid=0 next_prio=120'
    193   ];
    194   var m = new tracing.TimelineModel(lines.join('\n'), false);
    195   assertEquals(0, m.importErrors.length);
    196 
    197   var c = m.cpus[1];
    198   assertEquals(2, c.slices.length);
    199 
    200   assertEquals('Surface Flinger ', c.slices[0].title);
    201   assertEquals(4467843.475, c.slices[0].start);
    202   assertAlmostEquals(.536 - .475, c.slices[0].duration);
    203 }
    204 
    205 function testImportWithNewline() {
    206   var lines = [
    207     ''
    208   ];
    209   var m = new tracing.TimelineModel(lines.join('\n'));
    210   assertEquals(0, m.importErrors.length);
    211 }
    212 
    213 function testClockSync() {
    214   var lines = [
    215     '          <idle>-0     [001]  4467.843475: sched_switch: ' +
    216                   'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ' +
    217                   '==> next_comm=SurfaceFlinger next_pid=178 next_prio=112',
    218     '  SurfaceFlinger-178   [001]  4467.843536: sched_switch: ' +
    219                   'prev_comm=SurfaceFlinger prev_pid=178 prev_prio=112 ' +
    220                   'prev_state=S ==> next_comm=kworker/u:2 next_pid=2844 ' +
    221                   'next_prio=120',
    222     '     kworker/u:2-2844  [001]  4467.843567: sched_switch: ' +
    223                   'prev_comm=kworker/u:2 prev_pid=2844 prev_prio=120 ' +
    224                   'prev_state=S ==> next_comm=swapper next_pid=0 ' +
    225                   'next_prio=120',
    226     '     kworker/u:2-2844  [001]  4467.843000: 0: ' +
    227                   'trace_event_clock_sync: parent_ts=0.1'
    228   ];
    229   var m = new tracing.TimelineModel(lines.join('\n'), false);
    230   assertEquals(0, m.importErrors.length);
    231 
    232   var c = m.cpus[1];
    233   assertEquals(2, c.slices.length);
    234 
    235   assertAlmostEquals((467.843475 - (467.843 - 0.1)) * 1000, c.slices[0].start);
    236 }
    237 
    238 function testClockSyncMarkWrite() {
    239   var lines = [
    240     'systrace.sh-8170  [001] 15180.978813: sched_switch: ' +
    241               'prev_comm=systrace.sh prev_pid=8170 prev_prio=120 ' +
    242               'prev_state=x ==> next_comm=kworker/1:0 next_pid=7873 ' +
    243               'next_prio=120',
    244     ' kworker/1:0-7873  [001] 15180.978836: sched_switch: ' +
    245               'prev_comm=kworker/1:0 prev_pid=7873 prev_prio=120 ' +
    246               'prev_state=S ==> next_comm=debugd next_pid=4404 next_prio=120',
    247     '     debugd-4404  [001] 15180.979010: sched_switch: prev_comm=debugd ' +
    248               'prev_pid=4404 prev_prio=120 prev_state=S ==> ' +
    249               'next_comm=dbus-daemon next_pid=510 next_prio=120',
    250     'systrace.sh-8182  [000] 15186.203900: tracing_mark_write: ' +
    251               'trace_event_clock_sync: parent_ts=0'
    252   ];
    253   var m = new tracing.TimelineModel(lines.join('\n'), false);
    254   assertEquals(0, m.importErrors.length);
    255 
    256   var c = m.cpus[1];
    257   assertEquals(2, c.slices.length);
    258 
    259   assertAlmostEquals((15180.978813 - 0) * 1000, c.slices[0].start);
    260 }
    261 
    262 
    263 function testImportWithoutClockSyncDeletesEverything() {
    264 }
    265 
    266 </script>
    267 </body>
    268 </html>
    269