| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2013 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/analysis/analysis_view.html"> |
| <link rel="import" href="/core/analysis/stub_analysis_results.html"> |
| <link rel="import" href="/core/test_utils.html"> |
| <link rel="import" href="/core/selection.html"> |
| <link rel="import" href="/core/trace_model/trace_model.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tv.b.unittest.testSuite(function() { |
| var Model = tv.c.TraceModel; |
| var Thread = tv.c.trace_model.Thread; |
| var Selection = tv.c.Selection; |
| var StubAnalysisResults = tv.c.analysis.StubAnalysisResults; |
| var newSliceNamed = tv.c.test_utils.newSliceNamed; |
| var newSliceCategory = tv.c.test_utils.newSliceCategory; |
| var Slice = tv.c.trace_model.Slice; |
| |
| var createSelectionWithTwoSlices = function() { |
| var model = new Model(); |
| var t53 = model.getOrCreateProcess(52).getOrCreateThread(53); |
| t53.sliceGroup.pushSlice(newSliceNamed('a', 0.0, 0.04)); |
| t53.sliceGroup.pushSlice(newSliceNamed('aa', 0.120, 0.06)); |
| |
| var t53track = {}; |
| t53track.thread = t53; |
| |
| var selection = new Selection(); |
| selection.push(t53.sliceGroup.slices[0]); |
| selection.push(t53.sliceGroup.slices[1]); |
| |
| return selection; |
| }; |
| |
| var createSelectionWithTwoSlicesSameTitle = function() { |
| var model = new Model(); |
| var t53 = model.getOrCreateProcess(52).getOrCreateThread(53); |
| t53.sliceGroup.pushSlice(newSliceNamed('c', 0.0, 0.04)); |
| t53.sliceGroup.pushSlice(newSliceNamed('c', 0.12, 0.06)); |
| |
| var t53track = {}; |
| t53track.thread = t53; |
| |
| var selection = new Selection(); |
| selection.push(t53.sliceGroup.slices[0]); |
| selection.push(t53.sliceGroup.slices[1]); |
| |
| return selection; |
| }; |
| |
| var createSelectionWithOneArg = function() { |
| var model = new Model(); |
| var t53 = model.getOrCreateProcess(52).getOrCreateThread(53); |
| t53.sliceGroup.pushSlice(new Slice('', 'c', 0, 0.0, {'arg1': 3.14}, 0.04)); |
| t53.sliceGroup.pushSlice(new Slice('', 'c', 0, 0.12, {'arg1': 6.28}, 0.06)); |
| |
| var t53track = {}; |
| t53track.thread = t53; |
| |
| var selection = new Selection(); |
| selection.push(t53.sliceGroup.slices[0]); |
| selection.push(t53.sliceGroup.slices[1]); |
| |
| return selection; |
| }; |
| |
| var createSelectionWithOneNumberOneTextArg = function() { |
| var model = new Model(); |
| var t53 = model.getOrCreateProcess(52).getOrCreateThread(53); |
| t53.sliceGroup.pushSlice(new Slice('', 'c', 0, 0.0, |
| {'arg1': 3.14, 'arg2': 'text1'}, 0.04)); |
| t53.sliceGroup.pushSlice(new Slice('', 'c', 0, 0.12, |
| {'arg1': 6.28, 'arg2': 'text2'}, 0.06)); |
| |
| var t53track = {}; |
| t53track.thread = t53; |
| |
| var selection = new Selection(); |
| selection.push(t53.sliceGroup.slices[0]); |
| selection.push(t53.sliceGroup.slices[1]); |
| |
| return selection; |
| }; |
| |
| var createSelectionWithTwoNumberArgs = function() { |
| var model = new Model(); |
| var t53 = model.getOrCreateProcess(52).getOrCreateThread(53); |
| t53.sliceGroup.pushSlice(new Slice('', 'c', 0, 0.0, |
| {'arg1': 3.14, 'arg2': 200.0}, 0.04)); |
| t53.sliceGroup.pushSlice(new Slice('', 'c', 0, 0.12, |
| {'arg1': 6.28, 'arg2': 100.0}, 0.06)); |
| |
| var t53track = {}; |
| t53track.thread = t53; |
| |
| var selection = new Selection(); |
| selection.push(t53.sliceGroup.slices[0]); |
| selection.push(t53.sliceGroup.slices[1]); |
| |
| return selection; |
| }; |
| |
| var createSelectionWithMismatchedArgs = function() { |
| var model = new Model(); |
| var t53 = model.getOrCreateProcess(52).getOrCreateThread(53); |
| // Two numbers |
| t53.sliceGroup.pushSlice(new Slice('', 'c', 0, 0.0, |
| {'arg1': 3.14, 'arg2': 200.0}, 0.04)); |
| t53.sliceGroup.pushSlice(new Slice('', 'c', 0, 0.12, |
| {'arg1': 6.28, 'arg2': 100.0}, 0.06)); |
| // One number, missing arg1. |
| t53.sliceGroup.pushSlice(new Slice('', 'c', 0, 0.14, |
| {'arg2': 50.0}, 0.08)); |
| // One number, arg2 is not numeric. |
| t53.sliceGroup.pushSlice(new Slice('', 'c', 0, 0.17, |
| {'arg1': 1.0, 'arg2': 'text'}, 0.1)); |
| // Missing both args. |
| t53.sliceGroup.pushSlice(new Slice('', 'c', 0, 0.19, |
| {}, 0.12)); |
| |
| var t53track = {}; |
| t53track.thread = t53; |
| |
| var selection = new Selection(); |
| selection.push(t53.sliceGroup.slices[0]); |
| selection.push(t53.sliceGroup.slices[1]); |
| selection.push(t53.sliceGroup.slices[2]); |
| selection.push(t53.sliceGroup.slices[3]); |
| selection.push(t53.sliceGroup.slices[4]); |
| |
| return selection; |
| }; |
| |
| test('instantiate_withMultipleSlices', function() { |
| var selection = createSelectionWithTwoSlices(); |
| |
| var analysisEl = new TracingAnalysisView(); |
| analysisEl.selection = selection; |
| this.addHTMLOutput(analysisEl); |
| }); |
| |
| test('instantiate_withMultipleSlicesSameTitle', function() { |
| var selection = createSelectionWithTwoSlicesSameTitle(); |
| |
| var analysisEl = new TracingAnalysisView(); |
| analysisEl.selection = selection; |
| this.addHTMLOutput(analysisEl); |
| }); |
| |
| test('instantiate_withMultipleSlicesOneArg', function() { |
| var selection = createSelectionWithOneArg(); |
| |
| var analysisEl = new TracingAnalysisView(); |
| analysisEl.selection = selection; |
| this.addHTMLOutput(analysisEl); |
| }); |
| |
| test('instantiate_withMultipleSlicesOneNumberOneTextArg', function() { |
| var selection = createSelectionWithOneNumberOneTextArg(); |
| |
| var analysisEl = new TracingAnalysisView(); |
| analysisEl.selection = selection; |
| this.addHTMLOutput(analysisEl); |
| }); |
| |
| test('instantiate_withMultipleSlicesTwoNumberArgs', function() { |
| var selection = createSelectionWithTwoNumberArgs(); |
| |
| var analysisEl = new TracingAnalysisView(); |
| analysisEl.selection = selection; |
| this.addHTMLOutput(analysisEl); |
| }); |
| |
| test('instantiate_withMultipleSlicesMismatchedArgs', function() { |
| var selection = createSelectionWithMismatchedArgs(); |
| |
| var analysisEl = new TracingAnalysisView(); |
| analysisEl.selection = selection; |
| this.addHTMLOutput(analysisEl); |
| }); |
| |
| test('analyzeSelectionWithTwoSlices', function() { |
| var selection = createSelectionWithTwoSlices(); |
| |
| var sliceView = document.createElement('tv-c-multi-slice-sub-view'); |
| var results = new StubAnalysisResults(); |
| |
| sliceView.analyze_(results, selection); |
| assert.equal(results.tables.length, 1); |
| var table = results.tables[0]; |
| assert.equal(table.rows.length, 6); |
| |
| assert.equal(table.rows[0].label, 'a'); |
| assert.equal(table.rows[0].occurrences, 1); |
| assert.closeTo(0.04, table.rows[0].duration, 1e-5); |
| assert.closeTo(0.04, table.rows[0].selfTime, 1e-5); |
| assert.isNull(table.rows[0].cpuDuration); |
| assert.equal(table.rows[1].label, 'aa'); |
| assert.equal(table.rows[1].occurrences, 1); |
| assert.closeTo(0.06, table.rows[1].duration, 1e-5); |
| assert.closeTo(0.06, table.rows[1].selfTime, 1e-5); |
| assert.isNull(table.rows[1].cpuDuration); |
| assert.equal(table.rows[2].label, 'Totals'); |
| assert.equal(table.rows[2].occurrences, 2); |
| assert.closeTo(0.1, table.rows[2].duration, 1e-5); |
| assert.closeTo(0.1, table.rows[2].selfTime, 1e-5); |
| assert.isNull(table.rows[2].cpuDuration); |
| |
| assert.equal(table.rows[4].label, 'Selection start'); |
| assert.closeTo(0, table.rows[4].time, 1e-5); |
| |
| assert.equal(table.rows[5].label, 'Selection extent'); |
| assert.closeTo(0.18, table.rows[5].time, 1e-5); |
| }); |
| |
| test('analyzeSelectionWithTwoSlicesSameTitle', function() { |
| var selection = createSelectionWithTwoSlicesSameTitle(); |
| |
| var sliceView = document.createElement('tv-c-multi-slice-sub-view'); |
| var results = new StubAnalysisResults(); |
| sliceView.analyze_(results, selection); |
| assert.equal(results.tables.length, 2); |
| |
| var t; |
| // Table 1. |
| t = results.tables[0]; |
| assert.equal(t.rows[0].label, 'c'); |
| assert.equal(t.rows[0].duration, 0.1); |
| assert.isNull(t.rows[0].cpuDuration); |
| assert.equal(t.rows[0].selfTime, 0.1); |
| assert.isNull(t.rows[0].cpuSelfTime); |
| assert.equal(t.rows[0].occurrences, 2); |
| assert.isNull(t.rows[0].percentage); |
| assert.deepEqual({ |
| min: 0.04, max: 0.06, avg: 0.05, |
| avg_stddev: 0.014142135623730947, |
| frequency: undefined, frequency_stddev: undefined |
| }, t.rows[0].details); |
| |
| assert.deepEqual(t.rows[1], {label: 'Selection start', time: 0}); |
| assert.deepEqual(t.rows[2], {label: 'Selection extent', time: 0.18}); |
| |
| assert.deepEqual(results.info[0], {label: 'Title: ', value: 'c'}); |
| assert.deepEqual(results.info[1], {label: 'Category: ', value: ''}); |
| |
| // Table 2. |
| var t = results.tables[1]; |
| console.log('table 2', t); |
| assert.equal(t.rows.length, 3); |
| assert.equal(t.rows[0].start, 0); |
| assert.equal(t.rows[0].duration, 0.04); |
| assert.equal(t.rows[0].selfTime, 0.04); |
| assert.deepEqual(t.rows[0].args, {}); |
| assert.equal(t.rows[1].start, 0.12); |
| assert.equal(t.rows[1].duration, 0.06); |
| assert.equal(t.rows[1].selfTime, 0.06); |
| assert.deepEqual(t.rows[2].args, {}); |
| assert.equal(t.rows[2].duration, 0.1); |
| assert.equal(t.rows[2].selfTime, 0.1); |
| assert.deepEqual(t.rows[2].args, {}); |
| }); |
| |
| test('analyzeSelectionTotalWithOneArg', function() { |
| var selection = createSelectionWithOneArg(); |
| |
| var sliceView = document.createElement('tv-c-multi-slice-sub-view'); |
| var results = new StubAnalysisResults(); |
| sliceView.analyze_(results, selection); |
| assert.equal(results.tables.length, 2); |
| |
| var t = results.tables[1]; |
| |
| assert.equal(t.rows[2].duration, 0.1); |
| assert.equal(t.rows[2].selfTime, 0.1); |
| assert.deepEqual(t.rows[2].args, { 'arg1': 9.42 }); |
| }); |
| |
| test('analyzeSelectionTotalWithOneNumberOneTextArg', function() { |
| var selection = createSelectionWithOneNumberOneTextArg(); |
| |
| var sliceView = document.createElement('tv-c-multi-slice-sub-view'); |
| var results = new StubAnalysisResults(); |
| sliceView.analyze_(results, selection); |
| assert.equal(results.tables.length, 2); |
| |
| var t = results.tables[1]; |
| |
| assert.equal(t.rows[2].duration, 0.1); |
| assert.equal(t.rows[2].selfTime, 0.1); |
| assert.deepEqual(t.rows[2].args, { 'arg1': 9.42 }); |
| }); |
| |
| test('analyzeSelectionTotalWithTwoNumberArgs', function() { |
| var selection = createSelectionWithTwoNumberArgs(); |
| |
| var sliceView = document.createElement('tv-c-multi-slice-sub-view'); |
| var results = new StubAnalysisResults(); |
| sliceView.analyze_(results, selection); |
| assert.equal(results.tables.length, 2); |
| |
| var t = results.tables[1]; |
| |
| assert.equal(t.rows[2].duration, 0.1); |
| assert.equal(t.rows[2].selfTime, 0.1); |
| assert.deepEqual(t.rows[2].args, { 'arg1': 9.42, 'arg2': 300.0 }); |
| }); |
| |
| test('analyzeSelectionTotalWithMismatchedArgs', function() { |
| var selection = createSelectionWithMismatchedArgs(); |
| |
| var sliceView = document.createElement('tv-c-multi-slice-sub-view'); |
| var results = new StubAnalysisResults(); |
| sliceView.analyze_(results, selection); |
| assert.equal(results.tables.length, 2); |
| |
| var t = results.tables[1]; |
| |
| assert.equal(t.rows[5].duration, 0.4); |
| assert.equal(t.rows[5].selfTime, 0.4); |
| assert.deepEqual(t.rows[5].args, { 'arg1': 10.42, 'arg2': 350.0 }); |
| }); |
| }); |
| </script> |