blob: 8e5fda99c6a3fadf228237bb5f1520816ef15594 [file] [log] [blame]
<
<!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/test_utils.html">
<link rel="import" href="/extras/importer/trace_event_importer.html">
<script>
'use strict';
tr.b.unittest.testSuite(function() { // @suppress longLineCheck
var findSliceNamed = tr.c.test_utils.findSliceNamed;
test('canImportEmpty', function() {
assert.isFalse(tr.e.importer.TraceEventImporter.canImport([]));
assert.isFalse(tr.e.importer.TraceEventImporter.canImport(''));
});
test('basicSingleThreadNonnestedParsing', function() {
var events = [
{name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'},
{name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'},
{name: 'b', args: {}, pid: 52, ts: 629, cat: 'bar', tid: 53, ph: 'B'},
{name: 'b', args: {}, pid: 52, ts: 631, cat: 'bar', tid: 53, ph: 'E'}
];
var m = new tr.Model(events);
assert.equal(m.numProcesses, 1);
var p = m.processes[52];
assert.isDefined(p);
assert.equal(p.numThreads, 1);
var t = p.threads[53];
assert.isDefined(t);
assert.equal(t.sliceGroup.length, 2);
assert.equal(t.tid, 53);
var slice = t.sliceGroup.slices[0];
assert.equal(slice.title, 'a');
assert.equal(slice.category, 'foo');
assert.equal(slice.start, 0);
assert.closeTo((560 - 520) / 1000, slice.duration, 1e-5);
assert.equal(slice.subSlices.length, 0);
slice = t.sliceGroup.slices[1];
assert.equal(slice.title, 'b');
assert.equal(slice.category, 'bar');
assert.closeTo((629 - 520) / 1000, slice.start, 1e-5);
assert.closeTo((631 - 629) / 1000, slice.duration, 1e-5);
assert.equal(slice.subSlices.length, 0);
});
test('basicSingleThreadNonnestedParsingWithCpuDuration', function() {
var events = [
{name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B', tts: 221}, // @suppress longLineCheck
{name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E', tts: 259}, // @suppress longLineCheck
{name: 'b', args: {}, pid: 52, ts: 629, cat: 'bar', tid: 53, ph: 'B', tts: 329}, // @suppress longLineCheck
{name: 'b', args: {}, pid: 52, ts: 631, cat: 'bar', tid: 53, ph: 'E', tts: 331} // @suppress longLineCheck
];
var m = new tr.Model(events);
assert.equal(m.numProcesses, 1);
var p = m.processes[52];
assert.isDefined(p);
assert.equal(p.numThreads, 1);
var t = p.threads[53];
assert.isDefined(t);
assert.equal(t.sliceGroup.length, 2);
assert.equal(t.tid, 53);
var slice = t.sliceGroup.slices[0];
assert.equal(slice.title, 'a');
assert.equal(slice.category, 'foo');
assert.equal(slice.start, 0);
assert.closeTo((560 - 520) / 1000, slice.duration, 1e-5);
assert.closeTo((259 - 221) / 1000, slice.cpuDuration, 1e-5);
assert.equal(slice.subSlices.length, 0);
slice = t.sliceGroup.slices[1];
assert.equal(slice.title, 'b');
assert.equal(slice.category, 'bar');
assert.closeTo((629 - 520) / 1000, slice.start, 1e-5);
assert.closeTo((631 - 629) / 1000, slice.duration, 1e-5);
assert.closeTo((331 - 329) / 1000, slice.cpuDuration, 1e-5);
assert.equal(slice.subSlices.length, 0);
});
test('argumentDupeCreatesNonFailingImportError', function() {
var events = [
{name: 'a',
args: {'x': 1},
pid: 1,
ts: 520,
cat: 'foo',
tid: 1,
ph: 'B'},
{name: 'a',
args: {'x': 2},
pid: 1,
ts: 560,
cat: 'foo',
tid: 1,
ph: 'E'}
];
var m = new tr.Model(events);
var t = m.processes[1].threads[1];
var sA = findSliceNamed(t.sliceGroup, 'a');
assert.equal(sA.args.x, 2);
assert.isTrue(m.hasImportWarnings);
assert.equal(1, m.importWarnings.length);
});
test('importMissingArgs', function() {
var events = [
{name: 'a', pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'},
{name: 'a', pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'},
{name: 'b', pid: 52, ts: 629, cat: 'bar', tid: 53, ph: 'I'}
];
// This should not throw an exception.
new tr.Model(events);
});
test('importDoesNotChokeOnNulls', function() {
var events = [
{name: 'a', args: { foo: null }, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'}, // @suppress longLineCheck
{name: 'a', pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'}
];
// This should not throw an exception.
new tr.Model(events);
});
test('categoryBeginEndMismatchPrefersBegin', function() {
var events = [
{name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'},
{name: 'a', args: {}, pid: 52, ts: 560, cat: 'bar', tid: 53, ph: 'E'}
];
var m = new tr.Model(events);
assert.equal(m.numProcesses, 1);
var p = m.processes[52];
assert.isDefined(p);
assert.equal(p.numThreads, 1);
var t = p.threads[53];
assert.isDefined(t);
assert.equal(t.sliceGroup.length, 1);
assert.equal(t.tid, 53);
var slice = t.sliceGroup.slices[0];
assert.equal(slice.title, 'a');
assert.equal(slice.category, 'foo');
});
test('beginEndNameMismatch', function() {
var events = [
{name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'},
{name: 'b', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'}
];
var m = new tr.Model(events);
assert.isTrue(m.hasImportWarnings);
assert.equal(m.importWarnings.length, 1);
});
test('nestedParsing', function() {
var events = [
{name: 'a', args: {}, pid: 1, ts: 1, tts: 1, cat: 'foo', tid: 1, ph: 'B'},
{name: 'b', args: {}, pid: 1, ts: 2, tts: 2, cat: 'bar', tid: 1, ph: 'B'},
{name: 'b', args: {}, pid: 1, ts: 3, tts: 3, cat: 'bar', tid: 1, ph: 'E'},
{name: 'a', args: {}, pid: 1, ts: 4, tts: 3, cat: 'foo', tid: 1, ph: 'E'}
];
var m = new tr.Model(events, false);
var t = m.processes[1].threads[1];
var sA = findSliceNamed(t.sliceGroup, 'a');
var sB = findSliceNamed(t.sliceGroup, 'b');
assert.equal(sA.title, 'a');
assert.equal(sA.category, 'foo');
assert.equal(sA.start, 0.001);
assert.equal(sA.duration, 0.003);
assert.equal(sA.selfTime, 0.002);
assert.equal(sA.cpuSelfTime, 0.001);
assert.equal(sB.title, 'b');
assert.equal(sB.category, 'bar');
assert.equal(sB.start, 0.002);
assert.equal(sB.duration, 0.001);
assert.equal(1, sA.subSlices.length);
assert.equal(sB, sA.subSlices[0]);
assert.equal(sA, sB.parentSlice);
});
test('nestedParsingWithTwoSubSlices', function() {
var events = [
{name: 'a', args: {}, pid: 1, ts: 1, tts: 1, cat: 'foo', tid: 1, ph: 'B'},
{name: 'b', args: {}, pid: 1, ts: 2, tts: 2, cat: 'bar', tid: 1, ph: 'B'},
{name: 'b', args: {}, pid: 1, ts: 3, tts: 3, cat: 'bar', tid: 1, ph: 'E'},
{name: 'c', args: {}, pid: 1, ts: 5, tts: 5, cat: 'baz', tid: 1, ph: 'B'},
{name: 'c', args: {}, pid: 1, ts: 7, tts: 6, cat: 'baz', tid: 1, ph: 'E'},
{name: 'a', args: {}, pid: 1, ts: 8, tts: 8, cat: 'foo', tid: 1, ph: 'E'}
];
var m = new tr.Model(events, false);
var t = m.processes[1].threads[1];
var sA = findSliceNamed(t.sliceGroup, 'a');
var sB = findSliceNamed(t.sliceGroup, 'b');
var sC = findSliceNamed(t.sliceGroup, 'c');
assert.equal(sA.title, 'a');
assert.equal(sA.category, 'foo');
assert.equal(sA.start, 0.001);
assert.equal(sA.duration, 0.007);
assert.equal(sA.selfTime, 0.004);
assert.equal(sA.cpuSelfTime, 0.005);
assert.equal(sB.title, 'b');
assert.equal(sB.category, 'bar');
assert.equal(sB.start, 0.002);
assert.equal(sB.duration, 0.001);
assert.equal(sC.title, 'c');
assert.equal(sC.category, 'baz');
assert.equal(sC.start, 0.005);
assert.equal(sC.duration, 0.002);
assert.equal(sA.subSlices.length, 2);
assert.equal(sA.subSlices[0], sB);
assert.equal(sA.subSlices[1], sC);
assert.equal(sB.parentSlice, sA);
assert.equal(sC.parentSlice, sA);
});
test('nestedParsingWithDoubleNesting', function() {
var events = [
{name: 'a', args: {}, pid: 1, ts: 1, cat: 'foo', tid: 1, ph: 'B'},
{name: 'b', args: {}, pid: 1, ts: 2, cat: 'bar', tid: 1, ph: 'B'},
{name: 'c', args: {}, pid: 1, ts: 3, cat: 'baz', tid: 1, ph: 'B'},
{name: 'c', args: {}, pid: 1, ts: 5, cat: 'baz', tid: 1, ph: 'E'},
{name: 'b', args: {}, pid: 1, ts: 7, cat: 'bar', tid: 1, ph: 'E'},
{name: 'a', args: {}, pid: 1, ts: 8, cat: 'foo', tid: 1, ph: 'E'}
];
var m = new tr.Model(events, false);
var t = m.processes[1].threads[1];
var sA = findSliceNamed(t.sliceGroup, 'a');
var sB = findSliceNamed(t.sliceGroup, 'b');
var sC = findSliceNamed(t.sliceGroup, 'c');
assert.equal(sA.title, 'a');
assert.equal(sA.category, 'foo');
assert.equal(sA.start, 0.001);
assert.equal(sA.duration, 0.007);
assert.equal(sA.selfTime, 0.002);
assert.equal(sB.title, 'b');
assert.equal(sB.category, 'bar');
assert.equal(sB.start, 0.002);
assert.equal(sB.duration, 0.005);
assert.equal(sA.selfTime, 0.002);
assert.equal(sC.title, 'c');
assert.equal(sC.category, 'baz');
assert.equal(sC.start, 0.003);
assert.equal(sC.duration, 0.002);
assert.equal(sA.subSlices.length, 1);
assert.equal(sA.subSlices[0], sB);
assert.equal(sB.parentSlice, sA);
assert.equal(sB.subSlices.length, 1);
assert.equal(sB.subSlices[0], sC);
assert.equal(sC.parentSlice, sB);
});
test('autoclosing', function() {
var events = [
// Slice that doesn't finish.
{name: 'a', args: {}, pid: 1, ts: 1, cat: 'foo', tid: 1, ph: 'B'},
// Slice that does finish to give an 'end time' to make autoclosing work.
{name: 'b', args: {}, pid: 1, ts: 1, cat: 'bar', tid: 2, ph: 'B'},
{name: 'b', args: {}, pid: 1, ts: 2, cat: 'bar', tid: 2, ph: 'E'}
];
var m = new tr.Model(events);
var p = m.processes[1];
var t = p.threads[1];
var slice = t.sliceGroup.slices[0];
assert.equal(slice.title, 'a');
assert.equal(slice.category, 'foo');
assert.isTrue(slice.didNotFinish);
assert.equal(slice.start, 0);
assert.equal(slice.duration, (2 - 1) / 1000);
});
test('autoclosingLoneBegin', function() {
var events = [
// Slice that doesn't finish.
{name: 'a', args: {}, pid: 1, ts: 1, cat: 'foo', tid: 1, ph: 'B'}
];
var m = new tr.Model(events);
var p = m.processes[1];
var t = p.threads[1];
var slice = t.sliceGroup.slices[0];
assert.equal(slice.title, 'a');
assert.equal(slice.category, 'foo');
assert.isTrue(slice.didNotFinish);
assert.equal(slice.start, 0);
assert.equal(slice.duration, 0);
});
test('autoclosingWithSubTasks', function() {
var events = [
{name: 'a', args: {}, pid: 1, ts: 1, cat: 'foo', tid: 1, ph: 'B'},
{name: 'b1', args: {}, pid: 1, ts: 2, cat: 'foo', tid: 1, ph: 'B'},
{name: 'b1', args: {}, pid: 1, ts: 3, cat: 'foo', tid: 1, ph: 'E'},
{name: 'b2', args: {}, pid: 1, ts: 3, cat: 'foo', tid: 1, ph: 'B'}
];
var m = new tr.Model(events, false);
var t = m.processes[1].threads[1];
var sA = findSliceNamed(t.sliceGroup, 'a');
var sB1 = findSliceNamed(t.sliceGroup, 'b1');
var sB2 = findSliceNamed(t.sliceGroup, 'b2');
assert.equal(sA.end, 0.003);
assert.equal(sB1.end, 0.003);
assert.equal(sB2.end, 0.003);
});
test('autoclosingWithEventsOutsideBounds', function() {
var events = [
// Slice that begins before min and ends after max of the other threads.
{name: 'a', args: {}, pid: 1, ts: 0, cat: 'foo', tid: 1, ph: 'B'},
{name: 'b', args: {}, pid: 1, ts: 3, cat: 'foo', tid: 1, ph: 'B'},
// Slice that does finish to give an 'end time' to establish a basis
{name: 'c', args: {}, pid: 1, ts: 1, cat: 'bar', tid: 2, ph: 'B'},
{name: 'c', args: {}, pid: 1, ts: 2, cat: 'bar', tid: 2, ph: 'E'}
];
var m = new tr.Model(events, false);
var p = m.processes[1];
var t = p.threads[1];
assert.equal(t.sliceGroup.length, 2);
var slice = findSliceNamed(t.sliceGroup, 'a');
assert.equal(slice.title, 'a');
assert.equal(slice.category, 'foo');
assert.equal(slice.start, 0);
assert.equal(slice.duration, 0.003);
var t2 = p.threads[2];
var slice2 = findSliceNamed(t2.sliceGroup, 'c');
assert.equal(slice2.title, 'c');
assert.equal(slice2.category, 'bar');
assert.equal(slice2.start, 0.001);
assert.equal(slice2.duration, 0.001);
assert.equal(m.bounds.min, 0.000);
assert.equal(m.bounds.max, 0.003);
});
test('nestedAutoclosing', function() {
var events = [
// Tasks that don't finish.
{name: 'a1', args: {}, pid: 1, ts: 1, cat: 'foo', tid: 1, ph: 'B'},
{name: 'a2', args: {}, pid: 1, ts: 1.5, cat: 'foo', tid: 1, ph: 'B'},
// Slice that does finish to give an 'end time' to make autoclosing work.
{name: 'b', args: {}, pid: 1, ts: 1, cat: 'foo', tid: 2, ph: 'B'},
{name: 'b', args: {}, pid: 1, ts: 2, cat: 'foo', tid: 2, ph: 'E'}
];
var m = new tr.Model(events, false);
var t1 = m.processes[1].threads[1];
var t2 = m.processes[1].threads[2];
var sA1 = findSliceNamed(t1.sliceGroup, 'a1');
var sA2 = findSliceNamed(t1.sliceGroup, 'a2');
var sB = findSliceNamed(t2.sliceGroup, 'b');
assert.equal(sA1.end, 0.002);
assert.equal(sA2.end, 0.002);
});
test('taskColoring', function() {
// The test below depends on hashing of 'a' != 'b'. Fail early if that
// assumption is incorrect.
assert.notEqual(tr.b.ui.getStringHash('a'), tr.b.ui.getStringHash('b'));
var events = [
{name: 'a', args: {}, pid: 1, ts: 1, cat: 'foo', tid: 1, ph: 'B'},
{name: 'a', args: {}, pid: 1, ts: 2, cat: 'foo', tid: 1, ph: 'E'},
{name: 'b', args: {}, pid: 1, ts: 3, cat: 'bar', tid: 1, ph: 'B'},
{name: 'b', args: {}, pid: 1, ts: 4, cat: 'bar', tid: 1, ph: 'E'},
{name: 'a', args: {}, pid: 1, ts: 5, cat: 'baz', tid: 1, ph: 'B'},
{name: 'a', args: {}, pid: 1, ts: 6, cat: 'baz', tid: 1, ph: 'E'}
];
var m = new tr.Model(events);
var p = m.processes[1];
var t = p.threads[1];
var a1 = t.sliceGroup.slices[0];
assert.equal(a1.title, 'a');
assert.equal(a1.category, 'foo');
var b = t.sliceGroup.slices[1];
assert.equal(b.title, 'b');
assert.equal(b.category, 'bar');
assert.notEqual(b.colorId, a1.colorId);
var a2 = t.sliceGroup.slices[2];
assert.equal(a2.title, 'a');
assert.equal(a2.category, 'baz');
assert.equal(a1.colorId, a2.colorId);
});
test('multipleThreadParsing', function() {
var events = [
{name: 'a', args: {}, pid: 1, ts: 1, cat: 'foo', tid: 1, ph: 'B'},
{name: 'a', args: {}, pid: 1, ts: 2, cat: 'foo', tid: 1, ph: 'E'},
{name: 'b', args: {}, pid: 1, ts: 3, cat: 'bar', tid: 2, ph: 'B'},
{name: 'b', args: {}, pid: 1, ts: 4, cat: 'bar', tid: 2, ph: 'E'}
];
var m = new tr.Model(events);
assert.equal(m.numProcesses, 1);
var p = m.processes[1];
assert.isDefined(p);
assert.equal(p.numThreads, 2);
// Check thread 1.
var t = p.threads[1];
assert.isDefined(t);
assert.equal(t.sliceGroup.length, 1);
assert.equal(t.tid, 1);
var slice = t.sliceGroup.slices[0];
assert.equal(slice.title, 'a');
assert.equal(slice.category, 'foo');
assert.equal(slice.start, 0);
assert.equal(slice.duration, (2 - 1) / 1000);
assert.equal(slice.subSlices.length, 0);
// Check thread 2.
var t = p.threads[2];
assert.isDefined(t);
assert.equal(t.sliceGroup.length, 1);
assert.equal(t.tid, 2);
slice = t.sliceGroup.slices[0];
assert.equal(slice.title, 'b');
assert.equal(slice.category, 'bar');
assert.equal(slice.start, (3 - 1) / 1000);
assert.equal(slice.duration, (4 - 3) / 1000);
assert.equal(slice.subSlices.length, 0);
});
test('multiplePidParsing', function() {
var events = [
{name: 'a', args: {}, pid: 1, ts: 1, cat: 'foo', tid: 1, ph: 'B'},
{name: 'a', args: {}, pid: 1, ts: 2, cat: 'foo', tid: 1, ph: 'E'},
{name: 'b', args: {}, pid: 2, ts: 3, cat: 'bar', tid: 2, ph: 'B'},
{name: 'b', args: {}, pid: 2, ts: 4, cat: 'bar', tid: 2, ph: 'E'}
];
var m = new tr.Model(events);
assert.equal(m.numProcesses, 2);
var p = m.processes[1];
assert.isDefined(p);
assert.equal(p.numThreads, 1);
// Check process 1 thread 1.
var t = p.threads[1];
assert.isDefined(t);
assert.equal(t.sliceGroup.length, 1);
assert.equal(t.tid, 1);
var slice = t.sliceGroup.slices[0];
assert.equal(slice.title, 'a');
assert.equal(slice.category, 'foo');
assert.equal(slice.start, 0);
assert.equal(slice.duration, (2 - 1) / 1000);
assert.equal(slice.subSlices.length, 0);
// Check process 2 thread 2.
var p = m.processes[2];
assert.isDefined(p);
assert.equal(p.numThreads, 1);
var t = p.threads[2];
assert.isDefined(t);
assert.equal(t.sliceGroup.length, 1);
assert.equal(t.tid, 2);
slice = t.sliceGroup.slices[0];
assert.equal(slice.title, 'b');
assert.equal(slice.category, 'bar');
assert.equal(slice.start, (3 - 1) / 1000);
assert.equal(slice.duration, (4 - 3) / 1000);
assert.equal(slice.subSlices.length, 0);
// Check getAllThreads.
assert.deepEqual(m.getAllThreads(),
[m.processes[1].threads[1], m.processes[2].threads[2]]);
});
// Process names.
test('processNames', function() {
var events = [
{name: 'process_name', args: {name: 'SomeProcessName'},
pid: 1, ts: 0, tid: 1, ph: 'M'},
{name: 'process_name', args: {name: 'SomeProcessName'},
pid: 2, ts: 0, tid: 1, ph: 'M'}
];
var m = new tr.Model();
m.importTraces([events], false, false);
assert.equal(m.processes[1].name, 'SomeProcessName');
});
// Process labels.
test('processLabels', function() {
var events = [
{name: 'process_labels', args: {labels: 'foo,bar,bar,foo,baz'},
pid: 1, ts: 0, tid: 1, ph: 'M'},
{name: 'process_labels', args: {labels: 'baz'},
pid: 2, ts: 0, tid: 1, ph: 'M'}
];
var m = new tr.Model();
m.importTraces([events], false, false);
assert.deepEqual(m.processes[1].labels, ['foo', 'bar', 'baz']);
assert.deepEqual(m.processes[2].labels, ['baz']);
});
// Process sort index.
test('processSortIndex', function() {
var events = [
{name: 'process_name', args: {name: 'First'},
pid: 2, ts: 0, tid: 1, ph: 'M'},
{name: 'process_name', args: {name: 'Second'},
pid: 2, ts: 0, tid: 1, ph: 'M'},
{name: 'process_sort_index', args: {sort_index: 1},
pid: 1, ts: 0, tid: 1, ph: 'M'}
];
var m = new tr.Model();
m.importTraces([events], false, false);
// By name, p1 is before p2. But, its sort index overrides that.
assert.isAbove(m.processes[1].compareTo(m.processes[2]), 0);
});
// Thread names.
test('threadNames', function() {
var events = [
{name: 'thread_name', args: {name: 'Thread 1'},
pid: 1, ts: 0, tid: 1, ph: 'M'},
{name: 'thread_name', args: {name: 'Thread 2'},
pid: 2, ts: 0, tid: 2, ph: 'M'}
];
var m = new tr.Model(events);
m.importTraces([events], false, false);
assert.equal(m.processes[1].threads[1].name, 'Thread 1');
assert.equal(m.processes[2].threads[2].name, 'Thread 2');
});
// Thread sort index.
test('threadSortIndex', function() {
var events = [
{name: 'thread_name', args: {name: 'Thread 1'},
pid: 1, ts: 0, tid: 1, ph: 'M'},
{name: 'thread_name', args: {name: 'Thread 2'},
pid: 1, ts: 0, tid: 2, ph: 'M'},
{name: 'thread_sort_index', args: {sort_index: 1},
pid: 1, ts: 0, tid: 1, ph: 'M'}
];
var m = new tr.Model();
m.importTraces([events], false, false);
// By name, t1 is before t2. But, its sort index overrides that.
var t1 = m.processes[1].threads[1];
var t2 = m.processes[1].threads[2];
assert.isAbove(t1.compareTo(t2), 0);
});
// CPU counts.
test('cpuCounts', function() {
var events = [
{name: 'num_cpus', args: {number: 4},
pid: 7, ts: 0, tid: 0, ph: 'M'},
{name: 'num_cpus', args: {number: 4},
pid: 14, ts: 0, tid: 0, ph: 'M'}
];
var m = new tr.Model();
m.importTraces([events], false, false);
assert.equal(m.kernel.softwareMeasuredCpuCount, 4);
assert.equal(m.kernel.bestGuessAtCpuCount, 4);
});
test('cpuCountsWithSandboxBeingConfused', function() {
var events = [
{name: 'num_cpus', args: {number: 4},
pid: 7, ts: 0, tid: 0, ph: 'M'},
{name: 'num_cpus', args: {number: 1},
pid: 14, ts: 0, tid: 0, ph: 'M'}
];
var m = new tr.Model();
m.importTraces([events], false, false);
assert.equal(m.kernel.softwareMeasuredCpuCount, 4);
assert.equal(m.kernel.bestGuessAtCpuCount, 4);
});
test('parsingWhenEndComesFirst', function() {
var events = [
{name: 'a', args: {}, pid: 1, ts: 1, cat: 'foo', tid: 1, ph: 'E'},
{name: 'a', args: {}, pid: 1, ts: 4, cat: 'foo', tid: 1, ph: 'B'},
{name: 'a', args: {}, pid: 1, ts: 5, cat: 'foo', tid: 1, ph: 'E'}
];
var m = new tr.Model(events, false);
var p = m.processes[1];
var t = p.threads[1];
assert.equal(t.sliceGroup.length, 1);
assert.equal(t.sliceGroup.slices[0].title, 'a');
assert.equal(t.sliceGroup.slices[0].category, 'foo');
assert.equal(t.sliceGroup.slices[0].start, 0.004);
assert.equal(t.sliceGroup.slices[0].duration, 0.001);
assert.isTrue(m.hasImportWarnings);
assert.equal(m.importWarnings.length, 1);
});
test('immediateParsing', function() {
var events = [
// Need to include immediates inside a task so the timeline
// recentering/zeroing doesn't clobber their timestamp.
{name: 'a', args: {}, pid: 1, ts: 1, cat: 'foo', tid: 1, ph: 'B'},
{name: 'immediate', args: {}, pid: 1, ts: 2, cat: 'bar', tid: 1, ph: 'I'},
{name: 'slower', args: {}, pid: 1, ts: 4, cat: 'baz', tid: 1, ph: 'i'},
{name: 'a', args: {}, pid: 1, ts: 4, cat: 'foo', tid: 1, ph: 'E'}
];
var m = new tr.Model(events, false);
var p = m.processes[1];
var t = p.threads[1];
assert.equal(t.sliceGroup.length, 3);
assert.equal(t.sliceGroup.slices[0].start, 0.001);
assert.equal(t.sliceGroup.slices[0].duration, 0.003);
assert.equal(t.sliceGroup.slices[1].start, 0.002);
assert.equal(t.sliceGroup.slices[1].duration, 0);
assert.equal(t.sliceGroup.slices[2].start, 0.004);
var slice = findSliceNamed(t.sliceGroup, 'a');
assert.equal(slice.title, 'a');
assert.equal(slice.category, 'foo');
assert.equal(slice.duration, 0.003);
var immed = findSliceNamed(t.sliceGroup, 'immediate');
assert.equal(immed.title, 'immediate');
assert.equal(immed.category, 'bar');
assert.equal(immed.start, 0.002);
assert.equal(immed.duration, 0);
var slower = findSliceNamed(t.sliceGroup, 'slower');
assert.equal(slower.title, 'slower');
assert.equal(slower.category, 'baz');
assert.equal(slower.start, 0.004);
assert.equal(slower.duration, 0);
});
test('simpleCounter', function() {
var events = [
{name: 'ctr', args: {'value': 0}, pid: 1, ts: 0, cat: 'foo', tid: 1,
ph: 'C'},
{name: 'ctr', args: {'value': 10}, pid: 1, ts: 10, cat: 'foo', tid: 1,
ph: 'C'},
{name: 'ctr', args: {'value': 0}, pid: 1, ts: 20, cat: 'foo', tid: 1,
ph: 'C'}
];
var m = new tr.Model(events);
var p = m.processes[1];
var ctr = m.processes[1].counters['foo.ctr'];
assert.equal(ctr.name, 'ctr');
assert.equal(ctr.category, 'foo');
assert.equal(ctr.numSamples, 3);
assert.equal(ctr.numSeries, 1);
assert.equal(ctr.series[0].name, 'value');
assert.equal(ctr.series[0].color,
tr.b.ui.getColorIdForGeneralPurposeString('ctr.value'));
assert.deepEqual(ctr.timestamps, [0, 0.01, 0.02]);
var samples = [];
ctr.series[0].samples.forEach(function(sample) {
samples.push(sample.value);
});
assert.deepEqual(samples, [0, 10, 0]);
assert.deepEqual(ctr.totals, [0, 10, 0]);
assert.equal(ctr.maxTotal, 10);
});
test('instanceCounter', function() {
var events = [
{name: 'ctr', args: {'value': 0}, pid: 1, ts: 0, cat: 'foo', tid: 1,
ph: 'C', id: 0},
{name: 'ctr', args: {'value': 10}, pid: 1, ts: 10, cat: 'foo', tid: 1,
ph: 'C', id: 0},
{name: 'ctr', args: {'value': 10}, pid: 1, ts: 10, cat: 'foo', tid: 1,
ph: 'C', id: 1},
{name: 'ctr', args: {'value': 20}, pid: 1, ts: 15, cat: 'foo', tid: 1,
ph: 'C', id: 1},
{name: 'ctr', args: {'value': 30}, pid: 1, ts: 18, cat: 'foo', tid: 1,
ph: 'C', id: 1},
{name: 'ctr', args: {'value': 40}, pid: 1, ts: 20, cat: 'bar', tid: 1,
ph: 'C', id: 2}
];
var m = new tr.Model(events);
var p = m.processes[1];
var ctr = m.processes[1].counters['foo.ctr[0]'];
assert.equal(ctr.name, 'ctr[0]');
assert.equal(ctr.category, 'foo');
assert.equal(ctr.numSamples, 2);
assert.equal(ctr.numSeries, 1);
assert.deepEqual(ctr.timestamps, [0, 0.01]);
var samples = [];
ctr.series[0].samples.forEach(function(sample) {
samples.push(sample.value);
});
assert.deepEqual(samples, [0, 10]);
ctr = m.processes[1].counters['foo.ctr[1]'];
assert.equal(ctr.name, 'ctr[1]');
assert.equal(ctr.category, 'foo');
assert.equal(ctr.numSamples, 3);
assert.equal(ctr.numSeries, 1);
assert.deepEqual(ctr.timestamps, [0.01, 0.015, 0.018]);
samples = [];
ctr.series[0].samples.forEach(function(sample) {
samples.push(sample.value);
});
assert.deepEqual(samples, [10, 20, 30]);
ctr = m.processes[1].counters['bar.ctr[2]'];
assert.equal(ctr.name, 'ctr[2]');
assert.equal(ctr.category, 'bar');
assert.equal(ctr.numSamples, 1);
assert.equal(ctr.numSeries, 1);
assert.deepEqual(ctr.timestamps, [0.02]);
var samples = [];
ctr.series[0].samples.forEach(function(sample) {
samples.push(sample.value);
});
assert.deepEqual(samples, [40]);
});
test('multiCounterUpdateBounds', function() {
var ctr = new tr.model.Counter(undefined, 'testBasicCounter',
'', 'testBasicCounter');
var value1Series = new tr.model.CounterSeries(
'value1', 'testBasicCounter.value1');
var value2Series = new tr.model.CounterSeries(
'value2', 'testBasicCounter.value2');
ctr.addSeries(value1Series);
ctr.addSeries(value2Series);
value1Series.addCounterSample(0, 0);
value1Series.addCounterSample(1, 1);
value1Series.addCounterSample(2, 1);
value1Series.addCounterSample(3, 2);
value1Series.addCounterSample(4, 3);
value1Series.addCounterSample(5, 1);
value1Series.addCounterSample(6, 3);
value1Series.addCounterSample(7, 3.1);
value2Series.addCounterSample(0, 0);
value2Series.addCounterSample(1, 0);
value2Series.addCounterSample(2, 1);
value2Series.addCounterSample(3, 1.1);
value2Series.addCounterSample(4, 0);
value2Series.addCounterSample(5, 7);
value2Series.addCounterSample(6, 0);
value2Series.addCounterSample(7, 0.5);
ctr.updateBounds();
assert.equal(ctr.bounds.min, 0);
assert.equal(ctr.bounds.max, 7);
assert.equal(ctr.maxTotal, 8);
assert.deepEqual([0, 0,
1, 1,
1, 2,
2, 3.1,
3, 3,
1, 8,
3, 3,
3.1, 3.6], ctr.totals);
});
test('multiCounter', function() {
var events = [
{name: 'ctr', args: {'value1': 0, 'value2': 7}, pid: 1, ts: 0, cat: 'foo', tid: 1, ph: 'C'}, // @suppress longLineCheck
{name: 'ctr', args: {'value1': 10, 'value2': 4}, pid: 1, ts: 10, cat: 'foo', tid: 1, ph: 'C'}, // @suppress longLineCheck
{name: 'ctr', args: {'value1': 0, 'value2': 1 }, pid: 1, ts: 20, cat: 'foo', tid: 1, ph: 'C'} // @suppress longLineCheck
];
var m = new tr.Model(events);
var p = m.processes[1];
var ctr = m.processes[1].counters['foo.ctr'];
assert.equal(ctr.name, 'ctr');
assert.equal(ctr.name, 'ctr');
assert.equal(ctr.category, 'foo');
assert.equal(ctr.numSamples, 3);
assert.equal(ctr.numSeries, 2);
assert.equal(ctr.series[0].name, 'value1');
assert.equal(ctr.series[1].name, 'value2');
assert.equal(ctr.series[0].color,
tr.b.ui.getColorIdForGeneralPurposeString('ctr.value1'));
assert.equal(ctr.series[1].color,
tr.b.ui.getColorIdForGeneralPurposeString('ctr.value2'));
assert.deepEqual(ctr.timestamps, [0, 0.01, 0.02]);
var samples = [];
ctr.series[0].samples.forEach(function(sample) {
samples.push(sample.value);
});
assert.deepEqual(samples, [0, 10, 0]);
var samples1 = [];
ctr.series[1].samples.forEach(function(sample) {
samples1.push(sample.value);
});
assert.deepEqual(samples1, [7, 4, 1]);
assert.deepEqual([0, 7,
10, 14,
0, 1], ctr.totals);
assert.equal(ctr.maxTotal, 14);
});
test('importObjectInsteadOfArray', function() {
var events = { traceEvents: [
{name: 'a', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53, ph: 'B'},
{name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'}
] };
var m = new tr.Model(events);
assert.equal(m.numProcesses, 1);
});
test('importString', function() {
var events = [
{name: 'a', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53, ph: 'B'},
{name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'}
];
var m = new tr.Model(JSON.stringify(events));
assert.equal(m.numProcesses, 1);
});
test('importStringWithLeadingSpaces', function() {
var events = [
{name: 'a', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53, ph: 'B'},
{name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'}
];
var m = new tr.Model(' ' + JSON.stringify(events));
assert.equal(m.numProcesses, 1);
});
test('importStringWithTrailingNewLine', function() {
var events = [
{name: 'a', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53, ph: 'B'},
{name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'}
];
var m = new tr.Model(JSON.stringify(events) + '\n');
assert.equal(m.numProcesses, 1);
});
test('importStringWithMissingCloseSquareBracket', function() {
var events = [
{name: 'a', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53, ph: 'B'},
{name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'}
];
var tmp = JSON.stringify(events);
assert.equal(tmp[tmp.length - 1], ']');
// Drop off the trailing ]
var dropped = tmp.substring(0, tmp.length - 1);
var m = new tr.Model(dropped);
assert.equal(m.numProcesses, 1);
});
test('importStringWithEndingCommaButMissingCloseSquareBracket', function() {
var lines = [
'[',
'{"name": "a", "args": {}, "pid": 52, "ts": 524, "cat": "foo", "tid": 53, "ph": "B"},', // @suppress longLineCheck
'{"name": "a", "args": {}, "pid": 52, "ts": 560, "cat": "foo", "tid": 53, "ph": "E"},' // @suppress longLineCheck
];
var text = lines.join('\n');
var m = new tr.Model(text);
assert.equal(m.numProcesses, 1);
assert.equal(m.processes[52].threads[53].sliceGroup.length, 1);
});
test('importStringWithMissingCloseSquareBracketAndNewline', function() {
var events = [
{name: 'a', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53, ph: 'B'},
{name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'}
];
var tmp = JSON.stringify(events);
assert.equal(tmp[tmp.length - 1], ']');
// Drop off the trailing ] and add a newline
var dropped = tmp.substring(0, tmp.length - 1);
var m = new tr.Model(dropped + '\n');
assert.equal(m.numProcesses, 1);
});
test('ImportStringEndingCommaButMissingCloseSquareBracketCRLF', function() {
var lines = [
'[',
'{"name": "a", "args": {}, "pid": 52, "ts": 524, "cat": "foo", "tid": 53, "ph": "B"},', // @suppress longLineCheck
'{"name": "a", "args": {}, "pid": 52, "ts": 560, "cat": "foo", "tid": 53, "ph": "E"},' // @suppress longLineCheck
];
var text = lines.join('\r\n');
var m = new tr.Model(text);
assert.equal(m.numProcesses, 1);
assert.equal(m.processes[52].threads[53].sliceGroup.length, 1);
});
test('importOldFormat', function() {
var lines = [
'[',
'{"cat":"a","pid":9,"tid":8,"ts":194,"ph":"E","name":"I","args":{}},',
'{"cat":"b","pid":9,"tid":8,"ts":194,"ph":"B","name":"I","args":{}}',
']'
];
var text = lines.join('\n');
var m = new tr.Model(text);
assert.equal(m.numProcesses, 1);
assert.equal(m.processes[9].threads[8].sliceGroup.length, 1);
});
test('startFinishOneSliceOneThread', function() {
var events = [
// Time is intentionally out of order.
{name: 'a', args: {}, pid: 52, ts: 560, cat: 'cat', tid: 53,
ph: 'F', id: 72},
{name: 'a', pid: 52, ts: 524, cat: 'cat', tid: 53,
ph: 'S', id: 72, args: {'foo': 'bar'}}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
assert.equal(t.asyncSliceGroup.slices.length, 1);
assert.equal(t.asyncSliceGroup.slices[0].title, 'a');
assert.equal(t.asyncSliceGroup.slices[0].category, 'cat');
assert.isTrue(t.asyncSliceGroup.slices[0].isTopLevel);
assert.equal(t.asyncSliceGroup.slices[0].id, 72);
assert.equal(t.asyncSliceGroup.slices[0].args.foo, 'bar');
assert.equal(t.asyncSliceGroup.slices[0].start, 0);
assert.closeTo(
(60 - 24) / 1000, t.asyncSliceGroup.slices[0].duration, 1e-5);
assert.equal(t.asyncSliceGroup.slices[0].startThread, t);
assert.equal(t.asyncSliceGroup.slices[0].endThread, t);
});
test('endArgsAddedToSlice', function() {
var events = [
{name: 'a', args: {x: 1}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'},
{name: 'a', args: {y: 2}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'}
];
var m = new tr.Model(events);
assert.equal(m.numProcesses, 1);
var p = m.processes[52];
assert.isDefined(p);
assert.equal(p.numThreads, 1);
var t = p.threads[53];
assert.isDefined(t);
assert.equal(t.sliceGroup.length, 1);
assert.equal(t.tid, 53);
var slice = t.sliceGroup.slices[0];
assert.equal(slice.title, 'a');
assert.equal(slice.category, 'foo');
assert.equal(slice.start, 0);
assert.equal(slice.subSlices.length, 0);
assert.equal(slice.args['x'], 1);
assert.equal(slice.args['y'], 2);
});
test('endArgOverrwritesOriginalArgValueIfDuplicated', function() {
var events = [
{name: 'b', args: {z: 3}, pid: 52, ts: 629, cat: 'foo', tid: 53, ph: 'B'},
{name: 'b', args: {z: 4}, pid: 52, ts: 631, cat: 'foo', tid: 53, ph: 'E'}
];
var m = new tr.Model(events);
assert.equal(m.numProcesses, 1);
var p = m.processes[52];
assert.isDefined(p);
assert.equal(p.numThreads, 1);
var t = p.threads[53];
assert.isDefined(t);
var slice = t.sliceGroup.slices[0];
assert.equal(slice.title, 'b');
assert.equal(slice.category, 'foo');
assert.equal(slice.start, 0);
assert.equal(slice.subSlices.length, 0);
assert.equal(slice.args['z'], 4);
});
test('asyncEndArgsAddedToSlice', function() {
var events = [
// Time is intentionally out of order.
{name: 'c', args: {y: 2}, pid: 52, ts: 560, cat: 'foo', tid: 53,
ph: 'F', id: 72},
{name: 'c', args: {x: 1}, pid: 52, ts: 524, cat: 'foo', tid: 53,
ph: 'S', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
assert.equal(t.asyncSliceGroup.slices.length, 1);
var parentSlice = t.asyncSliceGroup.slices[0];
assert.equal(parentSlice.title, 'c');
assert.equal(parentSlice.category, 'foo');
assert.isTrue(parentSlice.isTopLevel);
assert.equal(parentSlice.args['x'], 1);
assert.equal(parentSlice.args['y'], 2);
assert.isDefined(parentSlice.subSlices);
assert.equal(parentSlice.subSlices.length, 0);
});
test('asyncEndArgOverwritesOriginalArgValueIfDuplicated', function() {
var events = [
// Time is intentionally out of order.
{name: 'd', args: {z: 4}, pid: 52, ts: 560, cat: 'foo', tid: 53,
ph: 'F', id: 72},
{name: 'd', args: {z: 3}, pid: 52, ts: 524, cat: 'foo', tid: 53,
ph: 'S', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
assert.equal(t.asyncSliceGroup.slices.length, 1);
var parentSlice = t.asyncSliceGroup.slices[0];
assert.equal(parentSlice.title, 'd');
assert.equal(parentSlice.category, 'foo');
assert.isTrue(parentSlice.isTopLevel);
assert.equal(parentSlice.args['z'], 4);
assert.isDefined(parentSlice.subSlices);
assert.equal(parentSlice.subSlices.length, 0);
});
test('asyncStepsInOneThread', function() {
var events = [
// Time is intentionally out of order.
{name: 'a', args: {z: 3}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'F', id: 72}, // @suppress longLineCheck
{name: 'a', args: {step: 's1', y: 2}, pid: 52, ts: 548, cat: 'foo', tid: 53, ph: 'T', id: 72}, // @suppress longLineCheck
{name: 'a', args: {x: 1}, pid: 52, ts: 524, cat: 'foo', tid: 53, ph: 'S', id: 72} // @suppress longLineCheck
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
assert.equal(t.asyncSliceGroup.slices.length, 1);
var parentSlice = t.asyncSliceGroup.slices[0];
assert.equal(parentSlice.title, 'a');
assert.equal(parentSlice.category, 'foo');
assert.isTrue(parentSlice.isTopLevel);
assert.equal(parentSlice.start, 0);
assert.equal(parentSlice.args['x'], 1);
assert.isUndefined(parentSlice.args['y']);
assert.equal(parentSlice.args['z'], 3);
assert.isDefined(parentSlice.subSlices);
assert.equal(parentSlice.subSlices.length, 1);
var subSlice = parentSlice.subSlices[0];
assert.equal(subSlice.title, 'a:s1');
assert.equal(subSlice.category, 'foo');
assert.isFalse(subSlice.isTopLevel);
assert.closeTo((548 - 524) / 1000, subSlice.start, 1e-5);
assert.closeTo((560 - 548) / 1000, subSlice.duration, 1e-5);
assert.isUndefined(subSlice.args['x']);
assert.equal(subSlice.args['y'], 2);
assert.isUndefined(subSlice.args['z']);
});
test('asyncStepsMissingStart', function() {
var events = [
// Time is intentionally out of order.
{name: 'a', args: {z: 3}, pid: 52, ts: 560, cat: 'foo', tid: 53,
ph: 'F', id: 72},
{name: 'a', args: {step: 's1', y: 2}, pid: 52, ts: 548, cat: 'foo',
tid: 53, ph: 'T', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isUndefined(t);
});
test('asyncStepsMissingFinish', function() {
var events = [
// Time is intentionally out of order.
{name: 'a', args: {step: 's1', y: 2}, pid: 52, ts: 548, cat: 'foo',
tid: 53, ph: 'T', id: 72},
{name: 'a', args: {z: 3}, pid: 52, ts: 560, cat: 'foo', tid: 53,
ph: 'S', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isUndefined(t);
});
test('asyncStepEndEvent', function() {
var events = [
// Time is intentionally out of order.
{name: 'a', args: {z: 3}, pid: 52, ts: 560, cat: 'foo', tid: 53,
ph: 'F', id: 72},
{name: 'a', args: {step: 's1', y: 2}, pid: 52, ts: 548, cat: 'foo',
tid: 53, ph: 'p', id: 72},
{name: 'a', args: {x: 1}, pid: 52, ts: 524, cat: 'foo', tid: 53,
ph: 'S', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
assert.equal(t.asyncSliceGroup.slices.length, 1);
var parentSlice = t.asyncSliceGroup.slices[0];
assert.equal(parentSlice.title, 'a');
assert.equal(parentSlice.category, 'foo');
assert.isTrue(parentSlice.isTopLevel);
assert.equal(parentSlice.start, 0);
assert.equal(parentSlice.args['x'], 1);
assert.isUndefined(parentSlice.args['y']);
assert.equal(parentSlice.args['z'], 3);
assert.isDefined(parentSlice.subSlices);
assert.equal(parentSlice.subSlices.length, 1);
var subSlice = parentSlice.subSlices[0];
assert.equal(subSlice.title, 'a:s1');
assert.equal(subSlice.category, 'foo');
assert.isFalse(subSlice.isTopLevel);
assert.equal(subSlice.start, 0);
assert.closeTo((548 - 524) / 1000, subSlice.duration, 1e-5);
assert.isUndefined(subSlice.args['x']);
assert.equal(subSlice.args['y'], 2);
assert.isUndefined(subSlice.args['z']);
});
test('asyncStepMismatch', function() {
var events = [
// Time is intentionally out of order.
{name: 'a', args: {z: 3}, pid: 52, ts: 560, cat: 'foo', tid: 53,
ph: 'F', id: 72},
{name: 'a', args: {step: 's2'}, pid: 52, ts: 548, cat: 'foo', tid: 53,
ph: 'T', id: 72},
{name: 'a', args: {step: 's1'}, pid: 52, ts: 548, cat: 'foo', tid: 53,
ph: 'p', id: 72},
{name: 'a', args: {x: 1}, pid: 52, ts: 524, cat: 'foo', tid: 53,
ph: 'S', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isUndefined(t);
assert.isTrue(m.hasImportWarnings);
});
test('asyncSliceWithoutCPUDuration', function() {
var events = [
// Async slice without tts field.
{name: 'a', args: {params: ''}, pid: 52, ts: 10, cat: 'foo', tid: 53,
id: 72, ph: 'b'},
{name: 'a', args: {params: ''}, pid: 52, ts: 20, cat: 'foo', tid: 53,
id: 72, ph: 'e'},
// Async slice with tts field but without use_async_tts marker field.
{name: 'b', args: {params: ''}, pid: 52, ts: 30, cat: 'foo', tid: 53,
id: 72, ph: 'b', tts: 30000},
{name: 'b', args: {params: ''}, pid: 52, ts: 40, cat: 'foo', tid: 53,
id: 72, ph: 'e', tts: 40000},
// Async slice with tts field but with use_async_tts marker set to 0.
{name: 'c', args: {params: ''}, pid: 52, ts: 50000, cat: 'foo', tid: 53,
id: 72, ph: 'b', tts: 50000, use_async_tts: 0},
{name: 'c', args: {params: ''}, pid: 52, ts: 60000, cat: 'foo', tid: 53,
id: 72, ph: 'e', tts: 60000, use_async_tts: 0}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
assert.equal(t.asyncSliceGroup.slices.length, 3);
var noTTSNoField = t.asyncSliceGroup.slices[0];
assert.isUndefined(noTTSNoField.cpuStart);
assert.isUndefined(noTTSNoField.cpuDuration);
var TTSNoField = t.asyncSliceGroup.slices[1];
assert.isUndefined(TTSNoField.cpuStart);
assert.isUndefined(TTSNoField.cpuDuration);
var TTSZeroField = t.asyncSliceGroup.slices[2];
assert.isUndefined(TTSZeroField.cpuStart);
assert.isUndefined(TTSZeroField.cpuDuration);
});
test('asyncSliceWithCPUDuration', function() {
var events = [
{name: 'a', args: {params: ''}, pid: 52, ts: 50000, cat: 'foo', tid: 53,
id: 72, ph: 'b', tts: 100000, use_async_tts: 1},
{name: 'a', args: {params: ''}, pid: 52, ts: 60000, cat: 'foo', tid: 53,
id: 72, ph: 'e', tts: 105000, use_async_tts: 1}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
assert.equal(t.asyncSliceGroup.slices.length, 1);
var asyncSlice = t.asyncSliceGroup.slices[0];
assert.isDefined(asyncSlice);
assert.equal(asyncSlice.duration, 10);
assert.equal(asyncSlice.cpuStart, 100);
assert.equal(asyncSlice.cpuDuration, 5);
});
test('nestableAsyncBasic', function() {
var events = [
{name: 'a', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'b', args: {x: 1}, pid: 52, ts: 525, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'b', args: {y: 2}, pid: 52, ts: 560, cat: 'foo', tid: 53,
ph: 'e', id: 72},
{name: 'a', args: {}, pid: 52, ts: 565, cat: 'foo', tid: 53,
ph: 'e', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
assert.equal(t.asyncSliceGroup.slices.length, 1);
var parentSlice = t.asyncSliceGroup.slices[0];
assert.equal(parentSlice.title, 'a');
assert.equal(parentSlice.category, 'foo');
assert.isTrue(parentSlice.isTopLevel);
assert.isDefined(parentSlice.subSlices);
assert.equal(parentSlice.subSlices.length, 1);
var subSlice = parentSlice.subSlices[0];
assert.isFalse(subSlice.isTopLevel);
// Arguments should include both BEGIN and END event.
assert.equal(subSlice.args['x'], 1);
assert.equal(subSlice.args['y'], 2);
assert.sameMembers(subSlice.subSlices, []);
});
test('nestableAsyncNoArgs', function() {
var events = [
{name: 'name', pid: 52, ts: 525, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'name', pid: 52, ts: 560, cat: 'foo', tid: 53,
ph: 'e', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
assert.equal(t.asyncSliceGroup.slices.length, 1);
var slice = t.asyncSliceGroup.slices[0];
assert.equal(slice.title, 'name');
assert.equal(slice.category, 'foo');
assert.isTrue(slice.isTopLevel);
assert.isDefined(slice.subSlices);
assert.equal(slice.subSlices.length, 0);
assert.deepEqual(slice.args, {});
});
test('nestableAsyncCombinedParams', function() {
var events = [
{name: 'a', args: {x: 1, params: {p1: 'hello', p2: 123}},
pid: 52, ts: 525, cat: 'foo', tid: 53, ph: 'b', id: 72},
{name: 'a', args: {y: 2, params: {p3: 'hi'}}, pid: 52, ts: 560,
cat: 'foo', tid: 53, ph: 'e', id: 72},
{name: 'b', args: {params: {p4: 'foo'}},
pid: 52, ts: 525, cat: 'foo', tid: 53, ph: 'b', id: 73},
{name: 'b', args: {params: ''}, pid: 52, ts: 560,
cat: 'foo', tid: 53, ph: 'e', id: 73},
{name: 'c', args: {params: {p5: 'bar'}},
pid: 52, ts: 525, cat: 'foo', tid: 53, ph: 'b', id: 74},
{name: 'c', args: {}, pid: 52, ts: 560,
cat: 'foo', tid: 53, ph: 'e', id: 74}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
assert.equal(t.asyncSliceGroup.slices.length, 3);
var sliceA = t.asyncSliceGroup.slices[0];
// Arguments should include both BEGIN and END event.
assert.equal(sliceA.args['x'], 1);
assert.equal(sliceA.args['y'], 2);
var paramsA = sliceA.args['params'];
assert.isDefined(paramsA);
assert.equal(paramsA.p1, 'hello');
assert.equal(paramsA.p2, 123);
assert.equal(paramsA.p3, 'hi');
assert.isTrue(sliceA.isTopLevel);
var sliceB = t.asyncSliceGroup.slices[1];
// Arguments should include both BEGIN and END event.
var paramsB = sliceB.args['params'];
assert.isDefined(paramsB);
assert.equal(paramsB.p4, 'foo');
assert.isTrue(sliceB.isTopLevel);
var sliceC = t.asyncSliceGroup.slices[2];
// Arguments should include both BEGIN and END event.
var paramsC = sliceC.args['params'];
assert.isDefined(paramsC);
assert.equal(paramsC.p5, 'bar');
assert.isTrue(sliceC.isTopLevel);
});
test('nestableAsyncManyLevels', function() {
// There are 5 nested levels.
var events = [
{name: 'l1', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'l2', args: {}, pid: 52, ts: 525, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'l3', args: {}, pid: 52, ts: 526, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'l4', args: {}, pid: 52, ts: 527, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'l5', args: {}, pid: 52, ts: 528, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'l5', args: {}, pid: 52, ts: 529, cat: 'foo', tid: 53,
ph: 'e', id: 72},
{name: 'l4', args: {}, pid: 52, ts: 530, cat: 'foo', tid: 53,
ph: 'e', id: 72},
{name: 'l3', args: {}, pid: 52, ts: 531, cat: 'foo', tid: 53,
ph: 'e', id: 72},
{name: 'l2', args: {}, pid: 52, ts: 532, cat: 'foo', tid: 53,
ph: 'e', id: 72},
{name: 'l1', args: {}, pid: 52, ts: 533, cat: 'foo', tid: 53,
ph: 'e', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
// Perfectly matched events should not produce a warning.
assert.isFalse(m.hasImportWarnings);
assert.equal(t.asyncSliceGroup.slices.length, 1);
var l1Slice = t.asyncSliceGroup.slices[0];
assert.equal(l1Slice.title, 'l1');
assert.closeTo(0, l1Slice.start, 1e-5);
assert.closeTo(9 / 1000, l1Slice.duration, 1e-5);
assert.isTrue(l1Slice.isTopLevel);
assert.isDefined(l1Slice.subSlices);
assert.equal(l1Slice.subSlices.length, 1);
var l2Slice = l1Slice.subSlices[0];
assert.equal(l2Slice.title, 'l2');
assert.closeTo(1 / 1000, l2Slice.start, 1e-5);
assert.closeTo(7 / 1000, l2Slice.duration, 1e-5);
assert.isFalse(l2Slice.isTopLevel);
assert.isDefined(l2Slice.subSlices);
assert.equal(l2Slice.subSlices.length, 1);
var l3Slice = l2Slice.subSlices[0];
assert.equal(l3Slice.title, 'l3');
assert.closeTo(2 / 1000, l3Slice.start, 1e-5);
assert.closeTo(5 / 1000, l3Slice.duration, 1e-5);
assert.isFalse(l3Slice.isTopLevel);
assert.isDefined(l3Slice.subSlices);
assert.equal(l3Slice.subSlices.length, 1);
var l4Slice = l3Slice.subSlices[0];
assert.equal(l4Slice.title, 'l4');
assert.closeTo(3 / 1000, l4Slice.start, 1e-5);
assert.closeTo(3 / 1000, l4Slice.duration, 1e-5);
assert.isFalse(l4Slice.isTopLevel);
assert.isDefined(l4Slice.subSlices);
assert.equal(l4Slice.subSlices.length, 1);
var l5Slice = l4Slice.subSlices[0];
assert.equal(l5Slice.title, 'l5');
assert.closeTo(4 / 1000, l5Slice.start, 1e-5);
assert.closeTo(1 / 1000, l5Slice.duration, 1e-5);
assert.isFalse(l5Slice.isTopLevel);
});
test('nestableAsyncInstantEvent', function() {
var events = [
{name: 'c', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53,
ph: 'n', id: 71},
{name: 'a', args: {}, pid: 52, ts: 524, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'd', args: {}, pid: 52, ts: 525, cat: 'foo', tid: 53,
ph: 'n', id: 72},
{name: 'a', args: {}, pid: 52, ts: 565, cat: 'foo', tid: 53,
ph: 'e', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
assert.equal(t.asyncSliceGroup.slices.length, 2);
var instantSlice = t.asyncSliceGroup.slices[0];
assert.equal(instantSlice.title, 'c');
assert.closeTo(0, instantSlice.start, 1e-5);
assert.closeTo(0, instantSlice.duration, 1e-5);
assert.sameMembers(instantSlice.subSlices, []);
assert.isTrue(instantSlice.isTopLevel);
var nestedSlice = t.asyncSliceGroup.slices[1];
assert.equal(nestedSlice.title, 'a');
assert.closeTo(0, nestedSlice.start, 1e-5);
assert.closeTo((565 - 524) / 1000, nestedSlice.duration, 1e-5);
assert.isTrue(nestedSlice.isTopLevel);
assert.isDefined(nestedSlice.subSlices);
assert.equal(nestedSlice.subSlices.length, 1);
var nestedInstantSlice = nestedSlice.subSlices[0];
assert.sameMembers(nestedInstantSlice.subSlices, []);
assert.equal(nestedInstantSlice.title, 'd');
assert.isFalse(nestedInstantSlice.isTopLevel);
});
test('nestableAsyncUnmatchedOuterBeginEvent', function() {
var events = [
{name: 'a', args: {x: 1}, pid: 52, ts: 524, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'b', args: {}, pid: 52, ts: 525, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'b', args: {y: 2}, pid: 52, ts: 560, cat: 'foo', tid: 53,
ph: 'e', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
// Unmatched BEGIN should produce a warning.
assert.isTrue(m.hasImportWarnings);
assert.equal(t.asyncSliceGroup.slices.length, 1);
var parentSlice = t.asyncSliceGroup.slices[0];
assert.equal(parentSlice.title, 'a');
assert.equal(parentSlice.category, 'foo');
assert.isTrue(parentSlice.isTopLevel);
assert.closeTo(0, parentSlice.start, 0.0001);
// Unmatched BEGIN event ends at the last event of that ID.
assert.closeTo(36 / 1000, parentSlice.duration, 0.0001);
// Arguments should include only include its arguments.
assert.isUndefined(parentSlice.args['y']);
assert.equal(parentSlice.args['x'], 1);
assert.isDefined(parentSlice.error);
assert.isDefined(parentSlice.subSlices);
assert.equal(parentSlice.subSlices.length, 1);
var subSlice = parentSlice.subSlices[0];
assert.isFalse(subSlice.isTopLevel);
assert.closeTo(1 / 1000, subSlice.start, 1e-5);
assert.closeTo(35 / 1000, subSlice.duration, 1e-5);
assert.sameMembers(subSlice.subSlices, []);
// Arguments should include those of the END event.
assert.equal(subSlice.args['y'], 2);
assert.sameMembers(subSlice.subSlices, []);
});
test('nestableAsyncUnmatchedInnerBeginEvent', function() {
var events = [
{name: 'a', args: {z: 3}, pid: 52, ts: 524, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'c', args: {}, pid: 52, ts: 525, cat: 'foo', tid: 53,
ph: 'n', id: 72},
{name: 'b', args: {x: 1}, pid: 52, ts: 525, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'a', args: {y: 2}, pid: 52, ts: 565, cat: 'foo', tid: 53,
ph: 'e', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
// Unmatched BEGIN should produce a warning.
assert.isTrue(m.hasImportWarnings);
assert.equal(t.asyncSliceGroup.slices.length, 1);
var parentSlice = t.asyncSliceGroup.slices[0];
assert.equal(parentSlice.title, 'a');
assert.equal(parentSlice.category, 'foo');
assert.isTrue(parentSlice.isTopLevel);
assert.closeTo(0, parentSlice.start, 1e-5);
assert.closeTo(41 / 1000, parentSlice.duration, 1e-5);
// Arguments should include both BEGIN and END event.
assert.equal(parentSlice.args['y'], 2);
assert.equal(parentSlice.args['z'], 3);
assert.isUndefined(parentSlice.args['x']);
assert.isDefined(parentSlice.subSlices);
assert.equal(parentSlice.subSlices.length, 2);
var subSliceInstant = parentSlice.subSlices[0];
var subSliceUnmatched = parentSlice.subSlices[1];
assert.equal(subSliceInstant.title, 'c');
assert.isFalse(subSliceInstant.isTopLevel);
assert.equal(subSliceUnmatched.title, 'b');
assert.isFalse(subSliceUnmatched.isTopLevel);
// Unmatched BEGIN ends at the last event of that ID.
assert.closeTo(1 / 1000, subSliceUnmatched.start, 1e-5);
assert.closeTo(40 / 1000, subSliceUnmatched.duration, 1e-5);
assert.sameMembers(subSliceUnmatched.subSlices, []);
assert.equal(subSliceUnmatched.args['x'], 1);
assert.isUndefined(subSliceUnmatched['y']);
assert.isDefined(subSliceUnmatched.error);
assert.closeTo(1 / 1000, subSliceInstant.start, 1e-5);
assert.closeTo(0, subSliceInstant.duration, 1e-5);
assert.sameMembers(subSliceInstant.subSlices, []);
});
test('nestableAsyncUnmatchedOuterEndEvent', function() {
// Events are intentionally out-of-order.
var events = [
{name: 'b', args: {x: 1}, pid: 52, ts: 525, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'b', args: {y: 2}, pid: 52, ts: 560, cat: 'foo', tid: 53,
ph: 'e', id: 72},
{name: 'a', args: {z: 3}, pid: 52, ts: 524, cat: 'foo', tid: 53,
ph: 'e', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
// Unmatched END should produce a warning.
assert.isTrue(m.hasImportWarnings);
assert.equal(t.asyncSliceGroup.slices.length, 2);
var unmatchedSlice = t.asyncSliceGroup.slices[0];
var slice = t.asyncSliceGroup.slices[1];
assert.equal(unmatchedSlice.title, 'a');
assert.closeTo(0, unmatchedSlice.start, 1e-5);
assert.isTrue(unmatchedSlice.isTopLevel);
// Unmatched END event begins at the first event of that ID. In this
// case, the first event happens to be the same unmatched event.
assert.closeTo(0 / 1000, unmatchedSlice.duration, 1e-5);
assert.isUndefined(unmatchedSlice.args['x']);
assert.isUndefined(unmatchedSlice.args['y']);
assert.equal(unmatchedSlice.args['z'], 3);
assert.isDefined(unmatchedSlice.error);
assert.sameMembers(unmatchedSlice.subSlices, []);
assert.equal(slice.title, 'b');
assert.isTrue(slice.isTopLevel);
assert.closeTo(1 / 1000, slice.start, 1e-5);
assert.closeTo(35 / 1000, slice.duration, 1e-5);
// Arguments should include both BEGIN and END event.
assert.equal(slice.args['x'], 1);
assert.equal(slice.args['y'], 2);
assert.sameMembers(slice.subSlices, []);
});
test('nestableAsyncUnmatchedInnerEndEvent', function() {
var events = [
{name: 'a', args: {x: 1}, pid: 52, ts: 524, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'c', args: {}, pid: 52, ts: 525, cat: 'foo', tid: 53,
ph: 'n', id: 72},
{name: 'b', args: {z: 3}, pid: 52, ts: 525, cat: 'foo', tid: 53,
ph: 'e', id: 72},
{name: 'a', args: {y: 2}, pid: 52, ts: 565, cat: 'foo', tid: 53,
ph: 'e', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
// Unmatched END should produce a warning.
assert.isTrue(m.hasImportWarnings);
assert.equal(t.asyncSliceGroup.slices.length, 1);
var parentSlice = t.asyncSliceGroup.slices[0];
assert.equal(parentSlice.title, 'a');
assert.isTrue(parentSlice.isTopLevel);
assert.closeTo(0, parentSlice.start, 1e-5);
assert.closeTo(41 / 1000, parentSlice.duration, 1e-5);
// Arguments should include both BEGIN and END event.
assert.equal(parentSlice.args['x'], 1);
assert.equal(parentSlice.args['y'], 2);
assert.isDefined(parentSlice.subSlices);
assert.equal(parentSlice.subSlices.length, 2);
var subSliceInstant = parentSlice.subSlices[0];
var subSliceUnmatched = parentSlice.subSlices[1];
assert.equal(subSliceInstant.title, 'c');
assert.isFalse(subSliceInstant.isTopLevel);
assert.equal(subSliceUnmatched.title, 'b');
assert.isFalse(subSliceUnmatched.isTopLevel);
// Unmatched END begins at the first event of that ID.
assert.closeTo(0 / 1000, subSliceUnmatched.start, 1e-5);
assert.closeTo(1 / 1000, subSliceUnmatched.duration, 1e-5);
// Arguments should include both BEGIN and END event.
assert.isUndefined(subSliceUnmatched.args['x']);
assert.isUndefined(subSliceUnmatched.args['y']);
assert.equal(subSliceUnmatched.args['z'], 3);
assert.isDefined(subSliceUnmatched.error);
assert.sameMembers(subSliceUnmatched.subSlices, []);
assert.closeTo(1 / 1000, subSliceInstant.start, 1e-5);
assert.closeTo(0, subSliceInstant.duration, 1e-5);
assert.sameMembers(subSliceInstant.subSlices, []);
});
test('nestableAsyncSameIDDifferentCategory', function() {
// Events with the same ID, but different categories should not be
// considered as nested.
var events = [
{name: 'EVENT_A', args: {}, pid: 52, ts: 500, cat: 'foo', tid: 53,
ph: 'b', id: 72},
{name: 'EVENT_B', args: {y: 2}, pid: 52, ts: 550, cat: 'bar', tid: 53,
ph: 'b', id: 72},
{name: 'EVENT_B', args: {}, pid: 52, ts: 600, cat: 'bar', tid: 53,
ph: 'e', id: 72},
{name: 'EVENT_A', args: {x: 1}, pid: 52, ts: 650, cat: 'foo', tid: 53,
ph: 'e', id: 72}
];
var m = new tr.Model(events);
var t = m.processes[52].threads[53];
assert.isDefined(t);
assert.equal(t.asyncSliceGroup.slices.length, 2);
var eventASlice = t.asyncSliceGroup.slices[0];
assert.equal(eventASlice.title, 'EVENT_A');
assert.equal(eventASlice.category, 'foo');
assert.equal(eventASlice.id, 'foo:72');
assert.isTrue(eventASlice.isTopLevel);
assert.equal(eventASlice.args['x'], 1);
assert.sameMembers(eventASlice.subSlices, []);
var eventBSlice = t.asyncSliceGroup.slices[1];
assert.equal(eventBSlice.title, 'EVENT_B');
assert.equal(eventBSlice.category, 'bar');
assert.equal(eventBSlice.id, 'bar:72');
assert.isTrue(eventBSlice.isTopLevel);
assert.equal(eventBSlice.args['y'], 2);
assert.sameMembers(eventBSlice.subSlices, []);
});
test('importSamples', function() {
var events = [
{name: 'a', args: {}, pid: 52, ts: 548, cat: 'test', tid: 53, ph: 'P'},
{name: 'b', args: {}, pid: 52, ts: 548, cat: 'test', tid: 53, ph: 'P'},
{name: 'c', args: {}, pid: 52, ts: 558, cat: 'test', tid: 53, ph: 'P'},
{name: 'a', args: {}, pid: 52, ts: 568, cat: 'test', tid: 53, ph: 'P'}
];
var m = new tr.Model(events);
var p = m.processes[52];
assert.isDefined(p);
var t = p.threads[53];
assert.isDefined(t);
assert.equal(t.samples_.length, 4);
assert.equal(t.samples_[0].start, 0.0);
assert.equal(t.samples_[1].start, 0.0);
assert.closeTo(0.01, t.samples_[2].start, 1e-5);
assert.equal(t.samples_[0].leafStackFrame.title, 'a');
assert.equal(t.samples_[1].leafStackFrame.title, 'b');
assert.equal(t.samples_[2].leafStackFrame.title, 'c');
assert.equal(t.samples_[3].leafStackFrame, t.samples[0].leafStackFrame);
assert.isFalse(m.hasImportWarnings);
});
test('importSamplesWithStackFrames', function() {
var eventData = {
traceEvents: [
{ name: 'a', args: {}, pid: 1, ts: 0, cat: 'test', tid: 2, ph: 'P', sf: 7 } // @suppress longLineCheck
],
stackFrames: {
'1': {
category: 'm1',
name: 'main'
},
'7': {
category: 'm2',
name: 'frame7',
parent: '1'
}
}
};
var options = new tr.ImportOptions();
options.shiftWorldToZero = false;
var m = new tr.Model(eventData, options);
var p = m.processes[1];
var t = p.threads[2];
assert.equal(t.samples.length, 1);
assert.equal(t.samples_[0].start, 0.0);
assert.equal(t.samples_[0].leafStackFrame.title, 'frame7');
assert.isFalse(m.hasImportWarnings);
});
test('importSamplesMissingArgs', function() {
var events = [
{name: 'a', pid: 52, ts: 548, cat: 'test', tid: 53, ph: 'P'},
{name: 'b', pid: 52, ts: 548, cat: 'test', tid: 53, ph: 'P'},
{name: 'c', pid: 52, ts: 549, cat: 'test', tid: 53, ph: 'P'}
];
var m = new tr.Model(events);
var p = m.processes[52];
assert.isDefined(p);
var t = p.threads[53];
assert.isDefined(t);
assert.isDefined(t);
assert.equal(t.samples_.length, 3);
assert.isFalse(m.hasImportWarnings);
});
test('importSimpleObject', function() {
var events = [
{ts: 10000, pid: 1, tid: 1, ph: 'N', cat: 'c', id: '0x1000', name: 'a', args: {}}, // @suppress longLineCheck
{ts: 15000, pid: 1, tid: 1, ph: 'O', cat: 'c', id: '0x1000', name: 'a', args: {snapshot: 15}}, // @suppress longLineCheck
{ts: 20000, pid: 1, tid: 1, ph: 'O', cat: 'c', id: '0x1000', name: 'a', args: {snapshot: 20}}, // @suppress longLineCheck
{ts: 50000, pid: 1, tid: 1, ph: 'D', cat: 'c', id: '0x1000', name: 'a', args: {}} // @suppress longLineCheck
];
var m = new tr.Model();
m.importTraces([events], false);
assert.equal(m.bounds.min, 10);
assert.equal(m.bounds.max, 50);
assert.isFalse(m.hasImportWarnings);
var p = m.processes[1];
assert.isDefined(p);
var i10 = p.objects.getObjectInstanceAt('0x1000', 10);
assert.equal(i10.category, 'c');
assert.equal(i10.creationTs, 10);
assert.equal(i10.deletionTs, 50);
assert.equal(i10.snapshots.length, 2);
var s15 = i10.snapshots[0];
assert.equal(s15.ts, 15);
assert.equal(s15.args, 15);
var s20 = i10.snapshots[1];
assert.equal(s20.ts, 20);
assert.equal(s20.args, 20);
});
test('importImplicitObjects', function() {
var events = [
{ts: 10000, pid: 1, tid: 1, ph: 'N', cat: 'c', id: '0x1000', name: 'a', args: {}}, // @suppress longLineCheck
{ts: 15000, pid: 1, tid: 1, ph: 'O', cat: 'c', id: '0x1000', name: 'a',
args: { snapshot: [
{ id: 'subObject/0x1',
foo: 1
}
]}},
{ts: 20000, pid: 1, tid: 1, ph: 'O', cat: 'c', id: '0x1000', name: 'a',
args: { snapshot: [
{ id: 'subObject/0x1',
foo: 2
},
{ id: 'subObject/0x2',
foo: 1
}
]}}
];
var m = new tr.Model();
m.importTraces([events], false);
var p1 = m.processes[1];
var iA = p1.objects.getObjectInstanceAt('0x1000', 10);
var subObjectInstances = p1.objects.getAllInstancesByTypeName()[
'subObject'];
assert.equal(subObjectInstances.length, 2);
var subObject1 = p1.objects.getObjectInstanceAt('0x1', 15);
assert.equal(subObject1.name, 'subObject');
assert.equal(subObject1.creationTs, 15);
assert.equal(subObject1.snapshots.length, 2);
assert.equal(subObject1.snapshots[0].ts, 15);
assert.equal(subObject1.snapshots[0].args.foo, 1);
assert.equal(subObject1.snapshots[1].ts, 20);
assert.equal(subObject1.snapshots[1].args.foo, 2);
var subObject2 = p1.objects.getObjectInstanceAt('0x2', 20);
assert.equal(subObject2.name, 'subObject');
assert.equal(subObject2.creationTs, 20);
assert.equal(subObject2.snapshots.length, 1);
assert.equal(subObject2.snapshots[0].ts, 20);
});
test('importImplicitObjectWithCategoryOverride', function() {
var events = [
{ts: 10000, pid: 1, tid: 1, ph: 'N', cat: 'cat', id: '0x1000', name: 'a', args: {}}, // @suppress longLineCheck
{ts: 15000, pid: 1, tid: 1, ph: 'O', cat: 'otherCat', id: '0x1000', name: 'a', // @suppress longLineCheck
args: { snapshot: [
{ id: 'subObject/0x1',
cat: 'cat',
foo: 1
}
]}}
];
var m = new tr.Model();
m.importTraces([events], false);
var p1 = m.processes[1];
var iA = p1.objects.getObjectInstanceAt('0x1000', 10);
var subObjectInstances = p1.objects.getAllInstancesByTypeName()[
'subObject'];
assert.equal(subObjectInstances.length, 1);
});
test('importImplicitObjectWithBaseTypeOverride', function() {
var events = [
{ts: 10000, pid: 1, tid: 1, ph: 'O', cat: 'c', id: '0x1000', name: 'PictureLayerImpl', args: { // @suppress longLineCheck
snapshot: {
base_type: 'LayerImpl'
}
}},
{ts: 50000, pid: 1, tid: 1, ph: 'D', cat: 'c', id: '0x1000', name: 'LayerImpl', args: {}} // @suppress longLineCheck
];
var m = new tr.Model();
m.importTraces([events], false);
var p1 = m.processes[1];
assert.equal(m.importWarnings.length, 0);
var iA = p1.objects.getObjectInstanceAt('0x1000', 10);
assert.equal(iA.snapshots.length, 1);
});
test('importIDRefs', function() {
var events = [
// An object with two snapshots.
{ts: 10000, pid: 1, tid: 1, ph: 'N', cat: 'c', id: '0x1000', name: 'a', args: {}}, // @suppress longLineCheck
{ts: 15000, pid: 1, tid: 1, ph: 'O', cat: 'c', id: '0x1000', name: 'a', args: {snapshot: 15}}, // @suppress longLineCheck
{ts: 20000, pid: 1, tid: 1, ph: 'O', cat: 'c', id: '0x1000', name: 'a', args: {snapshot: 20}}, // @suppress longLineCheck
{ts: 50000, pid: 1, tid: 1, ph: 'D', cat: 'c', id: '0x1000', name: 'a', args: {}}, // @suppress longLineCheck
// A slice that references the object.
{ts: 17000, pid: 1, tid: 1, ph: 'B', cat: 'c', name: 'taskSlice', args: {my_object: {id_ref: '0x1000'}}}, // @suppress longLineCheck
{ts: 17500, pid: 1, tid: 1, ph: 'E', cat: 'c', name: 'taskSlice', args: {}} // @suppress longLineCheck
];
var m = new tr.Model();
m.importTraces([events], false);
var p1 = m.processes[1];
var iA = p1.objects.getObjectInstanceAt('0x1000', 10);
var s15 = iA.getSnapshotAt(15);
var taskSlice = p1.threads[1].sliceGroup.slices[0];
assert.equal(taskSlice.args.my_object, s15);
});
test('importIDRefsThatPointAtEachOther', function() {
var events = [
// An object.
{ts: 10000, pid: 1, tid: 1, ph: 'N', cat: 'c', id: '0x1000', name: 'a', args: {}}, // @suppress longLineCheck
{ts: 15000, pid: 1, tid: 1, ph: 'O', cat: 'c', id: '0x1000', name: 'a', args: { // @suppress longLineCheck
snapshot: { x: {
id: 'foo/0x1001',
value: 'bar'
}}}},
{ts: 50000, pid: 1, tid: 1, ph: 'D', cat: 'c', id: '0x1000', name: 'a', args: {}}, // @suppress longLineCheck
// A slice that references the object.
{ts: 17000, pid: 1, tid: 1, ph: 'B', cat: 'c', name: 'taskSlice', args: {my_object: {id_ref: '0x1001'}}}, // @suppress longLineCheck
{ts: 17500, pid: 1, tid: 1, ph: 'E', cat: 'c', name: 'taskSlice', args: {}} // @suppress longLineCheck
];
var m = new tr.Model();
m.importTraces([events], false);
var p1 = m.processes[1];
var iA = p1.objects.getObjectInstanceAt('0x1000', 15);
var iFoo = p1.objects.getObjectInstanceAt('0x1001', 15);