1// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5'use strict'; 6 7base.require('tracing.test_utils'); 8base.require('tracing.importer.linux_perf_importer'); 9 10base.unittest.testSuite('tracing.importer.linux_perf.cpufreq_parser', 11 function() { 12 test('cpuFreqTargetImport', function() { 13 var lines = [ 14 '<idle>-0 [000] ..s3 1043.718825: cpufreq_interactive_target: ' + 15 'cpu=0 load=2 cur=2000000 targ=300000\n', 16 '<idle>-0 [000] ..s3 1043.718825: cpufreq_interactive_target: ' + 17 'cpu=0 load=12 cur=1000000 actual=1000000 targ=200000\n' 18 ]; 19 var m = new tracing.TraceModel(lines.join('\n'), false); 20 assertEquals(0, m.importErrors.length); 21 22 var threads = m.getAllThreads(); 23 assertEquals(1, threads.length); 24 25 var thread = threads[0]; 26 assertEquals(0, thread.sliceGroup.slices[0].args['cpu']); 27 assertEquals(2, thread.sliceGroup.slices[0].args['load']); 28 assertEquals(2000000, thread.sliceGroup.slices[0].args['cur']); 29 assertEquals(300000, thread.sliceGroup.slices[0].args['targ']); 30 31 assertEquals(0, thread.sliceGroup.slices[1].args['cpu']); 32 assertEquals(12, thread.sliceGroup.slices[1].args['load']); 33 assertEquals(1000000, thread.sliceGroup.slices[1].args['cur']); 34 assertEquals(1000000, thread.sliceGroup.slices[1].args['actual']); 35 assertEquals(200000, thread.sliceGroup.slices[1].args['targ']); 36 }); 37 38 test('cpuFreqNotYetImport', function() { 39 var lines = [ 40 '<idle>-0 [001] ..s3 1043.718832: cpufreq_interactive_notyet: ' + 41 'cpu=1 load=10 cur=700000 targ=200000\n', 42 '<idle>-0 [001] ..s3 1043.718832: cpufreq_interactive_notyet: ' + 43 'cpu=1 load=10 cur=700000 actual=1000000 targ=200000\n' 44 ]; 45 var m = new tracing.TraceModel(lines.join('\n'), false); 46 assertEquals(0, m.importErrors.length); 47 48 var threads = m.getAllThreads(); 49 assertEquals(1, threads.length); 50 51 var thread = threads[0]; 52 assertEquals(1, thread.sliceGroup.slices[0].args['cpu']); 53 assertEquals(10, thread.sliceGroup.slices[0].args['load']); 54 assertEquals(700000, thread.sliceGroup.slices[0].args['cur']); 55 assertEquals(200000, thread.sliceGroup.slices[0].args['targ']); 56 57 assertEquals(1, thread.sliceGroup.slices[1].args['cpu']); 58 assertEquals(10, thread.sliceGroup.slices[1].args['load']); 59 assertEquals(700000, thread.sliceGroup.slices[1].args['cur']); 60 assertEquals(1000000, thread.sliceGroup.slices[1].args['actual']); 61 assertEquals(200000, thread.sliceGroup.slices[1].args['targ']); 62 }); 63 64 test('cpuFreqSetSpeedImport', function() { 65 var lines = [ 66 'cfinteractive-23 [001] ...1 1043.719688: ' + 67 'cpufreq_interactive_setspeed: cpu=0 targ=200000 actual=700000\n' 68 ]; 69 var m = new tracing.TraceModel(lines.join('\n'), false); 70 assertEquals(0, m.importErrors.length); 71 72 var threads = m.getAllThreads(); 73 assertEquals(1, threads.length); 74 75 var thread = threads[0]; 76 assertEquals(0, thread.sliceGroup.slices[0].args['cpu']); 77 assertEquals(200000, thread.sliceGroup.slices[0].args['targ']); 78 assertEquals(700000, thread.sliceGroup.slices[0].args['actual']); 79 }); 80 81 test('cpuFreqAlreadyImport', function() { 82 var lines = [ 83 '<idle>-0 [000] ..s3 1043.738822: cpufreq_interactive_already: cpu=0 load=18 cur=200000 actual=700000 targ=200000\n' // @suppress longLineCheck 84 ]; 85 var m = new tracing.TraceModel(lines.join('\n'), false); 86 assertEquals(0, m.importErrors.length); 87 88 var threads = m.getAllThreads(); 89 assertEquals(1, threads.length); 90 91 var thread = threads[0]; 92 assertEquals(0, thread.sliceGroup.slices[0].args['cpu']); 93 assertEquals(18, thread.sliceGroup.slices[0].args['load']); 94 assertEquals(200000, thread.sliceGroup.slices[0].args['cur']); 95 assertEquals(700000, thread.sliceGroup.slices[0].args['actual']); 96 assertEquals(200000, thread.sliceGroup.slices[0].args['targ']); 97 }); 98 99 test('cpuFreqBoostImport', function() { 100 var lines = [ 101 'InputDispatcher-465 [001] ...1 1044.213948: ' + 102 'cpufreq_interactive_boost: pulse\n' 103 ]; 104 var m = new tracing.TraceModel(lines.join('\n'), false); 105 assertEquals(0, m.importErrors.length); 106 107 var threads = m.getAllThreads(); 108 assertEquals(1, threads.length); 109 110 var thread = threads[0]; 111 assertEquals('pulse', thread.sliceGroup.slices[0].args['type']); 112 }); 113 114 test('cpuFreqUnBoostImport', function() { 115 var lines = [ 116 'InputDispatcher-465 [001] ...1 1044.213948: ' + 117 'cpufreq_interactive_unboost: pulse\n' 118 ]; 119 var m = new tracing.TraceModel(lines.join('\n'), false); 120 assertEquals(0, m.importErrors.length); 121 122 var threads = m.getAllThreads(); 123 assertEquals(1, threads.length); 124 125 var thread = threads[0]; 126 assertEquals('pulse', thread.sliceGroup.slices[0].args['type']); 127 }); 128 129 test('cpuFreqUpImport', function() { 130 var lines = [ 131 'kinteractive-69 [003] .... 414324.164432: ' + 132 'cpufreq_interactive_up: cpu=1 targ=1400000 actual=800000' 133 ]; 134 var m = new tracing.TraceModel(lines.join('\n'), false); 135 assertEquals(0, m.importErrors.length); 136 137 var threads = m.getAllThreads(); 138 assertEquals(1, threads.length); 139 140 var thread = threads[0]; 141 assertEquals(1, thread.sliceGroup.slices[0].args['cpu']); 142 assertEquals(1400000, thread.sliceGroup.slices[0].args['targ']); 143 assertEquals(800000, thread.sliceGroup.slices[0].args['actual']); 144 }); 145 146 test('cpuFreqDownImport', function() { 147 var lines = [ 148 'kinteractive-69 [003] .... 414365.834193: ' + 149 'cpufreq_interactive_down: cpu=3 targ=800000 actual=1000000' 150 ]; 151 var m = new tracing.TraceModel(lines.join('\n'), false); 152 assertEquals(0, m.importErrors.length); 153 154 var threads = m.getAllThreads(); 155 assertEquals(1, threads.length); 156 157 var thread = threads[0]; 158 assertEquals(3, thread.sliceGroup.slices[0].args['cpu']); 159 assertEquals(800000, thread.sliceGroup.slices[0].args['targ']); 160 assertEquals(1000000, thread.sliceGroup.slices[0].args['actual']); 161 }); 162 }); 163