| <!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="/tracing/core/test_utils.html"> |
| <link rel="import" href="/tracing/model/ir_coverage.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| var newSliceEx = tr.c.TestUtils.newSliceEx; |
| |
| function createModel() { |
| return tr.c.TestUtils.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.isTopLevel = true; |
| var unassociatedEvent = thread.sliceGroup.pushSlice(newSliceEx( |
| {title: 's1', start: 6.0, duration: 1.0})); |
| unassociatedEvent.isTopLevel = true; |
| var s2 = thread.sliceGroup.pushSlice(newSliceEx( |
| {title: 's2', start: 2.0, duration: 1.0})); |
| s2.isTopLevel = true; |
| var f0 = tr.c.TestUtils.newFlowEventEx({ |
| title: 'test1', |
| start: 0, |
| end: 10, |
| startSlice: s0, |
| endSlice: s2, |
| id: '0x100' |
| }); |
| model.flowEvents.push(f0); |
| var as1 = tr.c.TestUtils.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.um.StubExpectation( |
| {parentModel: model, start: 0, duration: 7}); |
| ir.associatedEvents.push(as1); |
| ir.associatedEvents.push(s0); |
| ir.associatedEvents.push(s2); |
| ir.associatedEvents.push(f0); |
| model.userModel.expectations.push(ir); |
| }); |
| } |
| |
| test('computeCoverage', function() { |
| var model = createModel(); |
| model.iterateAllEvents(function(event) { |
| if (event.title === 's0' || event.title === 's2') { |
| event.cpuSelfTime = 0.4; |
| } else if (event.title === 's1') { |
| event.cpuSelfTime = 0.8; |
| } |
| }); |
| |
| var coverage = tr.model.getIRCoverageFromModel(model); |
| assert.equal(3, coverage.associatedEventsCount); |
| assert.equal(1, coverage.unassociatedEventsCount); |
| assert.closeTo(0.75, coverage.coveredEventsCountRatio, 1e-3); |
| assert.closeTo(0.8, coverage.associatedEventsCpuTimeMs, 1e-3); |
| assert.closeTo(0.8, coverage.unassociatedEventsCpuTimeMs, 1e-3); |
| assert.closeTo(0.5, coverage.coveredEventsCpuTimeRatio, 1e-3); |
| }); |
| |
| test('zeroCPU', function() { |
| var model = createModel(); |
| var coverage = tr.model.getIRCoverageFromModel(model); |
| assert.equal(3, coverage.associatedEventsCount); |
| assert.equal(1, coverage.unassociatedEventsCount); |
| assert.closeTo(0.75, coverage.coveredEventsCountRatio, 1e-3); |
| assert.closeTo(0.0, coverage.associatedEventsCpuTimeMs, 1e-3); |
| assert.closeTo(0.0, coverage.unassociatedEventsCpuTimeMs, 1e-3); |
| assert.equal(undefined, coverage.coveredEventsCpuTimeRatio, 1e-3); |
| }); |
| }); |
| </script> |
| |