| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2015 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. |
| --> |
| |
| <link rel="import" href="/core/test_utils.html"> |
| <link rel="import" href="/model/ir_coverage.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| var newSliceEx = tr.c.test_utils.newSliceEx; |
| |
| test('computeCoverage', function() { |
| var model = tr.c.test_utils.newModel(function(model) { |
| var process = model.getOrCreateProcess(1); |
| var thread = process.getOrCreateThread(2); |
| var s0 = thread.sliceGroup.pushSlice(newSliceEx( |
| {title: 's0', start: 0.0, duration: 1.0})); |
| s0.cpuDuration = 0.4; |
| s0.isTopLevel = true; |
| var unassociatedEvent = thread.sliceGroup.pushSlice(newSliceEx( |
| {title: 's1', start: 6.0, duration: 1.0})); |
| unassociatedEvent.cpuDuration = 0.8; |
| unassociatedEvent.isTopLevel = true; |
| var s2 = thread.sliceGroup.pushSlice(newSliceEx( |
| {title: 's2', start: 2.0, duration: 1.0})); |
| s2.cpuDuration = 0.4; |
| s2.isTopLevel = true; |
| var f0 = tr.c.test_utils.newFlowEventEx({ |
| title: 'test1', |
| start: 0, |
| end: 10, |
| startSlice: s0, |
| endSlice: s2, |
| id: '0x100' |
| }); |
| model.flowEvents.push(f0); |
| var as1 = tr.c.test_utils.newAsyncSliceEx({ |
| title: 'InputLatency::GestureTap', |
| cat: 'benchmark,latencyInfo', |
| start: 2, |
| end: 10, |
| id: '0x100', |
| isTopLevel: true, |
| startThread: thread |
| }); |
| thread.asyncSliceGroup.push(as1); |
| var ir = new tr.model.InteractionRecord('test', 0, 0, 7); |
| ir.associatedEvents.push(as1); |
| ir.associatedEvents.push(s0); |
| ir.associatedEvents.push(s2); |
| ir.associatedEvents.push(f0); |
| model.addInteractionRecord(ir); |
| }); |
| |
| var coverage = tr.model.getIRCoverageFromModel(model); |
| assert.equal(3, coverage.associatedEvents.length); |
| assert.equal(1, coverage.unassociatedEvents.length); |
| assert.closeTo(0.75, coverage.coveredEventsRatio, 1e-3); |
| assert.closeTo(0.25, coverage.uncoveredEventsRatio, 1e-3); |
| assert.closeTo(0.8, coverage.associatedCpuMs, 1e-3); |
| assert.closeTo(0.8, coverage.unassociatedCpuMs, 1e-3); |
| assert.closeTo(0.5, coverage.coveredCpuRatio, 1e-3); |
| assert.closeTo(0.5, coverage.uncoveredCpuRatio, 1e-3); |
| }); |
| }); |
| </script> |
| |