Html程序  |  354行  |  13.17 KB

<!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(undefined, x[3]);
  assertEquals('4467.843475', x[4]);
  assertEquals('sched_switch', x[5]);
  assertEquals('prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
      'next_comm=SurfaceFlinger next_pid=178 next_prio=112', x[6]);

  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.eventDefinitions['sched_switch'].format;
  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.eventDefinitions['sched_wakeup'].format;
  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>