blob: a6e11b73241df4c2d0223011dc52ed8c19759408 [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright 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/base/base64.html">
<link rel="import" href="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/extras/importer/linux_perf/ftrace_importer.html">
<link rel="import" href="/tracing/extras/importer/trace_event_importer.html">
<link rel="import" href="/tracing/extras/importer/zip_importer.html">
<link rel="import" href="/tracing/extras/importer/v8/v8_log_importer.html">
<link rel="import" href="/tracing/model/model.html">
<script>
'use strict';
tr.b.unittest.testSuite(function() {
var Base64 = tr.b.Base64;
test('canImportEmpty', function() {
var m = tr.c.TestUtils.newModelWithEvents([]);
assert.isDefined(m.modelIndices);
m = new tr.Model('');
});
test('canImportSubtraces', function() {
var systraceLines = [
'SurfaceFlinger-2 [001] ...1 1000.0: 0: B|1|taskA',
'SurfaceFlinger-2 [001] ...1 2000.0: 0: E',
' chrome-3 [001] ...1 2000.0: 0: trace_event_clock_sync: ' +
'parent_ts=0'
];
var traceEvents = [
{ts: 1000, pid: 1, tid: 3, ph: 'B', cat: 'c', name: 'taskB', args: {
my_object: {id_ref: '0x1000'}
}},
{ts: 2000, pid: 1, tid: 3, ph: 'E', cat: 'c', name: 'taskB', args: {}}
];
var combined = JSON.stringify({
traceEvents: traceEvents,
systemTraceEvents: systraceLines.join('\n')
});
var m = tr.c.TestUtils.newModelWithEvents([combined]);
assert.equal(tr.b.dictionaryValues(m.processes).length, 1);
var p1 = m.processes[1];
assert.isDefined(p1);
var t2 = p1.threads[2];
var t3 = p1.threads[3];
assert.isDefined(t2);
assert.isDefined(t3);
assert.equal(1, 1, t2.sliceGroup.length);
assert.equal(t2.sliceGroup.slices[0].title, 'taskA');
assert.equal(t3.sliceGroup.length, 1);
assert.equal(t3.sliceGroup.slices[0].title, 'taskB');
});
test('canImportCompressedSingleSubtrace', function() {
var compressedTrace = Base64.atob(
'H4sIACKfFVUC/wsuLUpLTE51y8nMS08t0jVSUIg2MDCMV' +
'dDT0zNUMDQwMNAzsFIAIqcaw5qSxOJsR65gfDqMEDpcATiC61ZbAAAA');
var m = tr.c.TestUtils.newModelWithEvents([compressedTrace]);
assert.equal(1, tr.b.dictionaryValues(m.processes).length);
var p1 = m.processes[1];
assert.isDefined(p1);
var t2 = p1.threads[2];
assert.isDefined(t2);
assert.equal(1, t2.sliceGroup.length, 1);
assert.equal('taskA', t2.sliceGroup.slices[0].title);
});
test('canImportSubtracesRecursively', function() {
var systraceLines = [
'SurfaceFlinger-2 [001] ...1 1000.0: 0: B|1|taskA',
'SurfaceFlinger-2 [001] ...1 2000.0: 0: E',
' chrome-3 [001] ...1 2000.0: 0: trace_event_clock_sync: ' +
'parent_ts=0'
];
var outerTraceEvents = [
{ts: 1000, pid: 1, tid: 3, ph: 'B', cat: 'c', name: 'taskB', args: {
my_object: {id_ref: '0x1000'}
}}
];
var innerTraceEvents = [
{ts: 2000, pid: 1, tid: 3, ph: 'E', cat: 'c', name: 'taskB', args: {}}
];
var innerTrace = JSON.stringify({
traceEvents: innerTraceEvents,
systemTraceEvents: systraceLines.join('\n')
});
var outerTrace = JSON.stringify({
traceEvents: outerTraceEvents,
systemTraceEvents: innerTrace
});
var m = tr.c.TestUtils.newModelWithEvents([outerTrace]);
assert.equal(tr.b.dictionaryValues(m.processes).length, 1);
var p1 = m.processes[1];
assert.isDefined(p1);
var t2 = p1.threads[2];
var t3 = p1.threads[3];
assert.isDefined(t2);
assert.isDefined(t3);
assert.equal(1, 1, t2.sliceGroup.length);
assert.equal(t2.sliceGroup.slices[0].title, 'taskA');
assert.equal(t3.sliceGroup.length, 1);
assert.equal(t3.sliceGroup.slices[0].title, 'taskB');
});
test('withImportFailure', function() {
assert.throw(function() {
tr.c.TestUtils.newModelWithEvents([malformed]);
});
});
test('customizeCallback', function() {
var m = tr.c.TestUtils.newModelWithEvents([], {
shiftWorldToZero: false,
pruneContainers: false,
customizeModelCallback: function(m) {
var browserProcess = m.getOrCreateProcess(1);
var browserMain = browserProcess.getOrCreateThread(2);
browserMain.sliceGroup.beginSlice('cat', 'Task', 0);
browserMain.sliceGroup.beginSlice('cat', 'SubTask', 1);
browserMain.sliceGroup.endSlice(9);
browserMain.sliceGroup.endSlice(10);
browserMain.sliceGroup.beginSlice('cat', 'Task', 20);
browserMain.sliceGroup.endSlice(30);
}
});
var t2 = m.processes[1].threads[2];
assert.equal(t2.sliceGroup.length, 3);
assert.equal(t2.sliceGroup.topLevelSlices.length, 2);
});
test('sortsSamples', function() {
// The 184, 0 and 185 are the tick-times
// and irrespective of the order
// in which the lines appear in the trace,
// the samples should always be sorted by sampling time.
var m = tr.c.TestUtils.newModelWithEvents([
'tick,0x9a,184,0,0x0,5',
'tick,0x9b,0,0,0x0,5',
'tick,0x9c,185,0,0x0,5']);
assert.equal(m.samples[0].start, 0);
assert.equal(m.samples[1].start, 0.184);
assert.equal(m.samples[2].start, 0.185);
});
test('sortsGlobalMemoryDumps', function() {
var m = tr.c.TestUtils.newModelWithEvents([], {
pruneContainers: false,
customizeModelCallback: function(m) {
m.globalMemoryDumps.push(new tr.model.GlobalMemoryDump(m, 1));
m.globalMemoryDumps.push(new tr.model.GlobalMemoryDump(m, 5));
m.globalMemoryDumps.push(new tr.model.GlobalMemoryDump(m, 3));
}
});
assert.equal(m.globalMemoryDumps[0].start, 0);
assert.equal(m.globalMemoryDumps[1].start, 2);
assert.equal(m.globalMemoryDumps[2].start, 4);
});
test('finalizesProcessMemoryDumps', function() {
var p;
var m = tr.c.TestUtils.newModelWithEvents([], {
pruneContainers: false,
customizeModelCallback: function(m) {
p = m.getOrCreateProcess(1);
var g = new tr.model.GlobalMemoryDump(m, -1);
m.globalMemoryDumps.push(g);
var pmd1 = new tr.model.ProcessMemoryDump(g, p, 1);
p.memoryDumps.push(pmd1);
var pmd2 = new tr.model.ProcessMemoryDump(g, p, 5);
p.memoryDumps.push(pmd2);
var pmd3 = new tr.model.ProcessMemoryDump(g, p, 3);
p.memoryDumps.push(pmd3);
pmd3.vmRegions = [];
}
});
// Check the sort order.
assert.equal(p.memoryDumps[0].start, 2);
assert.equal(p.memoryDumps[1].start, 4);
assert.equal(p.memoryDumps[2].start, 6);
// Check that the most recent VM regions are linked correctly.
assert.isUndefined(p.memoryDumps[0].mostRecentVmRegions);
assert.lengthOf(p.memoryDumps[1].mostRecentVmRegions, 0);
assert.strictEqual(
p.memoryDumps[1].mostRecentVmRegions,
p.memoryDumps[2].mostRecentVmRegions);
});
});
</script>