| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2014 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="/extras/analysis/sampling_summary.html"> |
| <link rel="import" href="/core/test_utils.html"> |
| <link rel="import" href="/core/trace_model/trace_model.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tv.b.unittest.testSuite(function() { |
| var StackFrame = tv.c.trace_model.StackFrame; |
| var Sample = tv.c.trace_model.Sample; |
| |
| var newSliceEx = tv.c.test_utils.newSliceEx; |
| |
| function createSelection() { |
| var selection = new tv.c.Selection(); |
| var model = new tv.c.TraceModel(); |
| var thread = model.getOrCreateProcess(1).getOrCreateThread(2); |
| thread.name = 'The Thread'; |
| |
| var fA = new StackFrame(undefined, 0, 'Chrome', 'a', 7); |
| var fAB = new StackFrame(fA, 1, 'Chrome', 'b', 7); |
| var fABC = new StackFrame(fAB, 2, 'Chrome', 'c', 7); |
| var fAD = new StackFrame(fA, 3, 'GPU Driver', 'd', 7); |
| |
| selection.push(new Sample(undefined, thread, 'cycles', |
| 10, fABC, 10)); |
| selection.push(new Sample(undefined, thread, 'cycles', |
| 20, fAB, 10)); |
| selection.push(new Sample(undefined, thread, 'cycles', |
| 25, fAB, 10)); |
| selection.push(new Sample(undefined, thread, 'cycles', |
| 30, fAB, 10)); |
| selection.push(new Sample(undefined, thread, 'cycles', |
| 35, fAD, 10)); |
| selection.push(new Sample(undefined, thread, 'cycles', |
| 35, fAD, 5)); |
| selection.push(new Sample(undefined, thread, 'cycles', |
| 40, fAD, 5)); |
| selection.push(new Sample(undefined, thread, 'page_misses', |
| 35, fAD, 7)); |
| selection.push(new Sample(undefined, thread, 'page_misses', |
| 40, fAD, 9)); |
| return selection; |
| } |
| |
| test('createSunburstDataBasic', function() { |
| var s = createSelection(); |
| |
| var expect = { |
| name: '<All Threads>', |
| category: 'root', |
| children: [ |
| { |
| name: 'Thread 2: The Thread', |
| category: 'Thread', |
| children: [ |
| { |
| category: 'Chrome', |
| name: 'Chrome', |
| children: [ |
| { |
| category: 'Chrome', |
| name: 'a', |
| children: [ |
| { |
| category: 'Chrome', |
| name: 'b', |
| children: [ |
| { |
| category: 'Chrome', |
| name: 'c', |
| leaf_node_id: 2, |
| size: 10 |
| }, |
| { |
| name: '<self>', |
| category: 'Chrome', |
| size: 30, |
| leaf_node_id: 1 |
| } |
| ] |
| }, |
| { |
| category: 'GPU Driver', |
| name: 'd', |
| leaf_node_id: 3, |
| size: 20 |
| } |
| ] |
| } |
| ] |
| } |
| ] |
| } |
| ] |
| }; |
| |
| var sunburstData = tv.e.analysis.createSunburstData(s, 'cycles'); |
| assert.equal(JSON.stringify(sunburstData), JSON.stringify(expect)); |
| }); |
| |
| test('processOnlySamples', function() { |
| var selection = new tv.c.Selection(); |
| var model = new tv.c.TraceModel(); |
| var thread = model.getOrCreateProcess(1).getOrCreateThread(2); |
| thread.name = 'The Thread'; |
| |
| var fA = new StackFrame(undefined, 1, 'Chrome', 'a', 7); |
| var fAB = new StackFrame(fA, 2, 'Chrome', 'b', 7); |
| var fABC = new StackFrame(fAB, 3, 'Chrome', 'c', 7); |
| var fAD = new StackFrame(fA, 4, 'GPU Driver', 'd', 7); |
| |
| selection.push(new Sample(undefined, thread, 'cycles', |
| 10, fABC, 10)); |
| selection.push(new Sample(undefined, thread, 'cycles', |
| 20, fAB, 10)); |
| selection.push(new Sample(undefined, thread, 'page_misses', |
| 40, fAD, 9)); |
| var expect = { |
| name: '<All Threads>', |
| category: 'root', |
| children: [ |
| { |
| name: 'Thread 2: The Thread', |
| category: 'Thread', |
| children: [ |
| { |
| category: 'Chrome', |
| name: 'Chrome', |
| children: [ |
| { |
| category: 'Chrome', |
| name: 'a', |
| children: [ |
| { |
| category: 'GPU Driver', |
| name: 'd', |
| leaf_node_id: 4, |
| size: 9 |
| } |
| ] |
| } |
| ] |
| } |
| ] |
| } |
| ] |
| }; |
| |
| // Along with the samples, push some slices too. |
| // The panel should completely ignore these. |
| selection.push(newSliceEx({ |
| type: tv.c.trace_model.ThreadSlice, |
| title: 'a', start: 1, duration: 2 |
| })); |
| selection.push(newSliceEx({ |
| type: tv.c.trace_model.ThreadSlice, |
| title: 'f', start: 9, duration: 7 |
| })); |
| |
| var sunburstData = tv.e.analysis.createSunburstData( |
| selection, 'page_misses'); |
| assert.equal(JSON.stringify(sunburstData), JSON.stringify(expect)); |
| }); |
| |
| test('createSunburstDataSampleType', function() { |
| var s = createSelection(); |
| |
| var expect = { |
| name: '<All Threads>', |
| category: 'root', |
| children: [ |
| { |
| name: 'Thread 2: The Thread', |
| category: 'Thread', |
| children: [ |
| { |
| category: 'Chrome', |
| name: 'Chrome', |
| children: [ |
| { |
| category: 'Chrome', |
| name: 'a', |
| children: [ |
| { |
| category: 'GPU Driver', |
| name: 'd', |
| leaf_node_id: 3, |
| size: 16 |
| } |
| ] |
| } |
| ] |
| } |
| ] |
| } |
| ] |
| }; |
| |
| var sunburstData = tv.e.analysis.createSunburstData(s, 'page_misses'); |
| assert.equal(JSON.stringify(sunburstData), JSON.stringify(expect)); |
| }); |
| |
| test('instantiate', function() { |
| var s = createSelection(); |
| |
| var panel = new tv.e.analysis.SamplingSummaryPanel(); |
| this.addHTMLOutput(panel); |
| panel.style.border = '1px solid black'; |
| panel.selection = s; |
| }); |
| }); |
| </script> |