blob: 47c1889cf5fe2ce65d7605315ec04bdd159b8d44 [file] [log] [blame]
<!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="/core/test_utils.html">
<link rel="import" href="/model/event_set.html">
<link rel="import" href="/model/model.html">
<link rel="import" href="/ui/extras/analysis/sampling_summary.html">
<script>
'use strict';
tr.b.unittest.testSuite(function() {
var StackFrame = tr.model.StackFrame;
var Sample = tr.model.Sample;
var newSliceEx = tr.c.test_utils.newSliceEx;
function createSelection() {
var selection = new tr.model.EventSet();
var model = new tr.Model();
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 = tr.ui.e.analysis.createSunburstData(s, 'cycles');
assert.equal(JSON.stringify(sunburstData), JSON.stringify(expect));
});
test('processOnlySamples', function() {
var selection = new tr.model.EventSet();
var model = new tr.Model();
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: tr.model.ThreadSlice,
title: 'a', start: 1, duration: 2
}));
selection.push(newSliceEx({
type: tr.model.ThreadSlice,
title: 'f', start: 9, duration: 7
}));
var sunburstData = tr.ui.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 = tr.ui.e.analysis.createSunburstData(s, 'page_misses');
assert.equal(JSON.stringify(sunburstData), JSON.stringify(expect));
});
test('instantiate', function() {
var s = createSelection();
var panel = new tr.ui.e.analysis.SamplingSummaryPanel();
this.addHTMLOutput(panel);
panel.style.border = '1px solid black';
panel.selection = s;
});
});
</script>