<!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="base.js"></script> </head> <body> <script> 'use strict'; base.require('unittest'); base.require('test_utils'); base.require('linux_perf_importer'); 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 testLineREWithIRQInfo() { var re = tracing._LinuxPerfImporterTestExports.lineREWithIRQInfo; var x = re.exec(' systrace.sh-5441 [001] d... 1031.091570: ' + 'sched_wakeup: comm=debugd pid=4978 prio=120 success=1 target_cpu=000'); assertNotNull(x); assertEquals('systrace.sh-5441', x[1]); assertEquals('001', x[2]); assertEquals('1031.091570', x[3]); assertEquals('sched_wakeup', x[4]); assertEquals('comm=debugd pid=4978 prio=120 success=1 target_cpu=000', x[5]); } function testAutodetectLineCornerCases() { var line = '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'; var autoLineRE = tracing._LinuxPerfImporterTestExports.autoDetectLineRE(line); var lineRE = tracing._LinuxPerfImporterTestExports.lineRE; assertEquals(autoLineRE, lineRE, 'Mis-detected line format without IRQ info'); } 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 testCanImport34AndLater() { var lines = [ '# tracer: nop', '#', '# entries-in-buffer/entries-written: 55191/55191 #P:2', '#', '# _-----=> irqs-off', '# / _----=> need-resched', '# | / _---=> hardirq/softirq', '# || / _--=> preempt-depth', '# ||| / delay', '# TASK-PID CPU# |||| TIMESTAMP FUNCTION', '# | | | |||| | |', ' systrace.sh-5441 [001] d... 1031.091570: sched_wakeup: ' + 'comm=debugd pid=4978 prio=120 success=1 target_cpu=000', ' systrace.sh-5441 [001] d... 1031.091584: sched_switch: ' + 'prev_comm=systrace.sh prev_pid=5441 prev_prio=120 prev_state=x ' + '==> next_comm=chrome next_pid=5418 next_prio=120' ]; assertTrue(tracing.LinuxPerfImporter.canImport(lines.join('\n'))); var lines = [ ' systrace.sh-5441 [001] d... 1031.091570: sched_wakeup: ' + 'comm=debugd pid=4978 prio=120 success=1 target_cpu=000', ' systrace.sh-5441 [001] d... 1031.091584: sched_switch: ' + 'prev_comm=systrace.sh prev_pid=5441 prev_prio=120 prev_state=x ' + '==> next_comm=chrome next_pid=5418 next_prio=120' ]; assertTrue(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 testImportOneSequenceWithSpacyThreadName() { var lines = [ ' <idle>-0 [001] 4467.843475: sched_switch: ' + 'prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' + 'next_comm=Surface Flinger next_pid=178 next_prio=112', 'Surface Flinger -178 [001] 4467.843536: sched_switch: ' + 'prev_comm=Surface Flinger 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('Surface Flinger ', c.slices[0].title); assertEquals(4467843.475, c.slices[0].start); assertAlmostEquals(.536 - .475, c.slices[0].duration); } 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() { } </script> </body> </html>