| <!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/metrics/system_health/efficiency_metric.html"> |
| <link rel="import" href="/tracing/metrics/value_list.html"> |
| <link rel="import" href="/tracing/model/user_model/idle_expectation.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| function createModel() { |
| return tr.c.TestUtils.newModel(function(model) { |
| model.p1 = model.getOrCreateProcess(1); |
| model.t2 = model.p1.getOrCreateThread(2); |
| |
| var slice = tr.c.TestUtils.newSliceEx({ |
| title: 'foo', |
| start: 0, |
| end: 100, |
| type: tr.model.ThreadSlice |
| }); |
| slice.isTopLevel = true; |
| |
| var idle = new tr.model.um.IdleExpectation(model, 0, 100); |
| idle.associatedEvents.push(slice); |
| model.userModel.expectations.push(idle); |
| }); |
| } |
| |
| test('optimalEfficiency', function() { |
| var model = createModel(); |
| model.userModel.expectations[0].associatedEvents[0].cpuSelfTime = 10; |
| var valueList = new tr.metrics.ValueList(); |
| tr.metrics.sh.EfficiencyMetric(valueList, model); |
| assert.equal(1, valueList.valueDicts[0].numeric.value); |
| }); |
| |
| test('pessimalEfficiency', function() { |
| var model = createModel(); |
| model.userModel.expectations[0].associatedEvents[0].cpuSelfTime = 100; |
| var valueList = new tr.metrics.ValueList(); |
| tr.metrics.sh.EfficiencyMetric(valueList, model); |
| assert.equal(0, valueList.valueDicts[0].numeric.value); |
| }); |
| }); |
| </script> |