1 <!DOCTYPE html> 2 <!-- 3 Copyright 2015 The Chromium Authors. All rights reserved. 4 Use of this source code is governed by a BSD-style license that can be 5 found in the LICENSE file. 6 --> 7 8 <link rel="import" href="/perf_insights/mappers/scheduling/map_wake_ups.html"> 9 <link rel="import" href="/perf_insights/mre/mre_result.html"> 10 <link rel="import" href="/tracing/base/iteration_helpers.html"> 11 <link rel="import" href="/tracing/core/test_utils.html"> 12 13 <script> 14 'use strict'; 15 16 tr.b.unittest.testSuite(function() { 17 var TestUtils = tr.c.TestUtils; 18 19 test('mapperTest', function() { 20 var m = TestUtils.newModel(function(m) { 21 var p1 = m.getOrCreateProcess(1); 22 var t2 = p1.getOrCreateThread(2); 23 t2.name = 'mainThread'; 24 t2.sliceGroup.pushSlice(TestUtils.newSliceEx({ 25 title: 'goingToSleep', 26 start: 0, duration: 10 27 })); 28 29 // This slice doesn't count as a wake-up because it occurs too soon after 30 // the previous one. 31 t2.sliceGroup.pushSlice(TestUtils.newSliceEx({ 32 title: 'notAWakeUp', 33 start: 10, duration: 1 34 })); 35 36 t2.sliceGroup.pushSlice(TestUtils.newSliceEx({ 37 title: 'wakeUp1', 38 start: 20, duration: 10 39 })); 40 41 var p3 = m.getOrCreateProcess(3); 42 var t4 = p1.getOrCreateThread(4); 43 t4.name = 'mainThread'; 44 t4.sliceGroup.pushSlice(TestUtils.newSliceEx({ 45 title: 'goingToSleep', 46 start: 0, duration: 10 47 })); 48 49 // This wake-up gets merged with the one above because it has the same 50 // title. 51 t4.sliceGroup.pushSlice(TestUtils.newSliceEx({ 52 title: 'wakeUp1', 53 start: 25, duration: 1 54 })); 55 56 // The name of this wake-up gets sanitized. 57 t4.sliceGroup.pushSlice(TestUtils.newSliceEx({ 58 title: 'MessageLoop::RunTask', 59 args: {src_file: 'c:\\foo\\file', src_func: 'func'}, 60 start: 29, duration: 1 61 })); 62 }); 63 64 var result = new pi.mre.MreResult(); 65 pie.mapWakeUpsForTest(result, m); 66 67 assert.equal(tr.b.dictionaryLength(result.pairs), 1); 68 69 var wakeUps = result.pairs.wakeUps; 70 assert.equal(Object.keys(wakeUps.mainThread).length, 2); 71 assert.equal(wakeUps.mainThread.wakeUp1.frequency, 200 / 3); 72 assert.deepEqual(wakeUps.mainThread.wakeUp1.sleepTimes, [9, 15]); 73 assert.deepEqual(wakeUps.mainThread['file:func'].sleepTimes, [3]); 74 }); 75 }); 76 77 </script> 78