| <!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="/perf_insights/value/value.html"> |
| <link rel="import" href="/perf_insights/value/run_info.html"> |
| <link rel="import" href="/perf_insights/results/results.html"> |
| <link rel="import" href="/perf_insights/mappers/task_info_map_function.html"> |
| <link rel="import" href="/tracing/base/units/histogram.html"> |
| <link rel="import" href="/tracing/core/test_utils.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| var test_utils = tr.c.TestUtils; |
| |
| test('taskInfoMapFunctionTest', function() { |
| var m = test_utils.newModel(function(m) { |
| var p1 = m.getOrCreateProcess(1); |
| p1.name = 'Process'; |
| var t2 = p1.getOrCreateThread(2); |
| t2.name = 'CrBrowserMain'; // To identify as browser process. |
| // t2_s0 is not a top-level, no incoming flow. |
| var t2_s0 = test_utils.newSliceEx( |
| { start: 0, duration: 9.7, cpuStart: 0, cpuDuration: 5.3}); |
| // t2_s1 is not a top-level, no incoming flow. |
| var t2_s1 = test_utils.newSliceEx( |
| { start: 11, duration: 20.1, cpuStart: 11, cpuDuration: 8.9 }); |
| // t2_s2 is a top-level slice: f2 flows into it. |
| var t2_s2 = test_utils.newSliceEx( |
| { start: 15, duration: 10.4, cpuStart: 15, cpuDuration: 3.0 }); |
| // t2_s3 is not a top-level slice because it's a child of t2_s2. |
| var t2_s3 = test_utils.newSliceEx( |
| { start: 17, duration: 2.4, cpuStart: 17, cpuDuration: 1.1 }); |
| t2.sliceGroup.pushSlice(t2_s0); |
| t2.sliceGroup.pushSlice(t2_s1); |
| t2.sliceGroup.pushSlice(t2_s2); |
| t2.sliceGroup.pushSlice(t2_s3); |
| var f1 = test_utils.newFlowEventEx({ |
| start: 0, duration: 18.1, startSlice: t2_s0, endSlice: t2_s3 |
| }); |
| var f2 = test_utils.newFlowEventEx({ |
| start: 9, duration: 7.2, startSlice: t2_s0, endSlice: t2_s2 |
| }); |
| m.flowEvents.push(f1); |
| m.flowEvents.push(f2); |
| }); |
| |
| var results = new pi.r.Results(); |
| var runInfo = new pi.v.RunInfo('my_test.json'); |
| pi.m.taskInfoMapFunctionForTest(results, runInfo, m); |
| |
| assert.equal(results.allValues.length, 3); |
| var value = results.allValues[0]; |
| assert.equal(value.name, 'time_spent_in_queue'); |
| assert.equal(Object.keys(value.value['Browser']).length, 1); |
| var histogram = tr.b.u.Histogram.fromDict( |
| value.value['Browser']['CrBrowserMain']); |
| assert.equal(histogram.getBinForValue(7.2).count, 1); |
| assert.equal(histogram.getBinForValue(18.1).count, 1); |
| value = results.allValues[1]; |
| assert.equal(value.name, 'time_spent_in_top_level_task'); |
| assert.equal(Object.keys(value.value['Browser']).length, 1); |
| histogram = tr.b.u.Histogram.fromDict( |
| value.value['Browser']['CrBrowserMain']); |
| assert.equal(histogram.getBinForValue(10.4).count, 1); |
| value = results.allValues[2]; |
| assert.equal(value.name, 'cpu_time_spent_in_top_level_task'); |
| assert.equal(Object.keys(value.value['Browser']).length, 1); |
| histogram = tr.b.u.Histogram.fromDict( |
| value.value['Browser']['CrBrowserMain']); |
| assert.equal(histogram.getBinForValue(3.0).count, 1); |
| }); |
| }); |
| |
| </script> |