blob: f4fb66f9d3bf6214238af78af00d9645128c5369 [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="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/extras/importer/v8/v8_log_importer.html">
<script>
'use strict';
tr.b.unittest.testSuite(function() {
var V8LogImporter = tr.e.importer.v8.V8LogImporter;
function newModel(events) {
return tr.c.TestUtils.newModelWithEvents([events], {
shiftWorldToZero: false
});
}
test('tickEventInSharedLibrary', function() {
var lines = [
'shared-library,"/usr/lib/libc++.1.dylib",0x99d8aae0,0x99dce729',
'tick,0x99d8aae4,12158,0,0x0,5'];
var m = newModel(lines.join('\n'));
var p = m.processes[-32];
var t = p.findAllThreadsNamed('V8')[0];
assert.equal(t.samples.length, 1);
assert.equal(t.samples[0].title, 'V8 PC');
assert.equal(t.samples[0].start, 12158 / 1000);
assert.equal(t.samples[0].leafStackFrame.title, '/usr/lib/libc++.1.dylib');
});
test('tickEventInGeneratedCode', function() {
var lines = [
'shared-library,"/usr/lib/libc++.1.dylib",0x99d8aae0,0x99dce729',
'code-creation,Stub,2,0x5b60ce80,1259,"StringAddStub"',
'tick,0x5b60ce84,12158,0,0x0,5'];
var m = newModel(lines.join('\n'));
var p = m.processes[-32];
var threads = p.findAllThreadsNamed('V8');
var t = threads[0];
assert.equal(t.samples.length, 1);
assert.equal(t.samples[0].leafStackFrame.title, 'StringAddStub');
});
test('tickEventInUknownCode', function() {
var lines = [
'shared-library,"/usr/lib/libc++.1.dylib",0x99d8aae0,0x99dce729',
'code-creation,Stub,2,0x5b60ce80,1259,"StringAddStub"',
'tick,0x4,0xbff02f08,12158,0,0x0,5'];
var m = newModel(lines.join('\n'));
var p = m.processes[-32];
var threads = p.findAllThreadsNamed('V8');
var t = threads[0];
assert.equal(t.samples.length, 1);
assert.equal(t.samples[0].leafStackFrame.title, 'Unknown');
});
test('tickEventWithStack', function() {
var lines = [
'code-creation,LazyCompile,0,0x2905d0c0,1800,"InstantiateFunction native apinatives.js:26:29",0x56b19124,', // @suppress longLineCheck
'tick,0x7fc6fe34,528674,0,0x3,0,0x2905d304'];
var m = newModel(lines.join('\n'));
var p = m.processes[-32];
var t = p.findAllThreadsNamed('V8')[0];
assert.equal(t.samples.length, 1);
assert.deepEqual(
['InstantiateFunction native apinatives.js:26:29'],
t.samples[0].getUserFriendlyStackTrace());
});
test('twoTickEventsWithStack', function() {
var lines = [
'code-creation,LazyCompile,0,0x2905d0c0,1800,"InstantiateFunction native apinatives.js:26:29",0x56b19124,', // @suppress longLineCheck
'tick,0x7fc6fe34,528674,0,0x3,0,0x2905d304',
'tick,0x7fd2a534,536213,0,0x81d8d080,0,0x2905d304'];
var m = newModel(lines.join('\n'));
var p = m.processes[-32];
var t = p.findAllThreadsNamed('V8')[0];
assert.equal(t.samples.length, 2);
assert.equal(t.samples[0].start, 528674 / 1000);
assert.equal(t.samples[1].start, 536213 / 1000);
assert.deepEqual(
['InstantiateFunction native apinatives.js:26:29'],
t.samples[0].getUserFriendlyStackTrace());
assert.deepEqual(
['InstantiateFunction native apinatives.js:26:29'],
t.samples[1].getUserFriendlyStackTrace());
assert.equal(t.samples[0].leafStackFrame,
t.samples[1].leafStackFrame);
});
test('twoTickEventsWithTwoStackFrames', function() {
var lines = [
'code-creation,LazyCompile,0,0x2904d560,876,"Instantiate native apinatives.js:9:21",0x56b190c8,~', // @suppress longLineCheck
'code-creation,LazyCompile,0,0x2905d0c0,1800,"InstantiateFunction native apinatives.js:26:29",0x56b19124,', // @suppress longLineCheck
'tick,0x7fc6fe34,528674,0,0x3,0,0x2905d304,0x2904d6e8',
'tick,0x7fd2a534,536213,0,0x81d8d080,0,0x2905d304,0x2904d6e8'];
var m = newModel(lines.join('\n'));
var p = m.processes[-32];
var t = p.findAllThreadsNamed('V8')[0];
assert.equal(t.samples.length, 2);
assert.equal(t.samples[0].start, 528674 / 1000);
assert.equal(t.samples[1].start, 536213 / 1000);
assert.deepEqual(
['InstantiateFunction native apinatives.js:26:29',
'~Instantiate native apinatives.js:9:21'],
t.samples[0].getUserFriendlyStackTrace());
assert.deepEqual(
['InstantiateFunction native apinatives.js:26:29',
'~Instantiate native apinatives.js:9:21'],
t.samples[1].getUserFriendlyStackTrace());
var childStackFrame = t.samples[0].leafStackFrame;
assert.equal(childStackFrame, t.samples[1].leafStackFrame);
assert.equal(childStackFrame.children.length, 0);
var parentStackFrame = childStackFrame.parentFrame;
assert.equal(parentStackFrame.children.length, 1);
assert.equal(childStackFrame, parentStackFrame.children[0]);
});
test('threeTickEventsWithTwoStackFrames', function() {
var lines = [
'code-creation,LazyCompile,0,0x2904d560,876,"Instantiate native apinatives.js:9:21",0x56b190c8,~', // @suppress longLineCheck
'code-creation,LazyCompile,0,0x2905d0c0,1800,"InstantiateFunction native apinatives.js:26:29",0x56b19124,', // @suppress longLineCheck
'tick,0x7fd7f75c,518328,0,0x81d86da8,2,0x2904d6e8',
'tick,0x7fc6fe34,528674,0,0x3,0,0x2905d304,0x2904d6e8',
'tick,0x7fd2a534,536213,0,0x81d8d080,0,0x2905d304,0x2904d6e8'];
var m = newModel(lines.join('\n'));
var p = m.processes[-32];
var threads = p.findAllThreadsNamed('V8');
var t = threads[0];
assert.equal(t.samples.length, 3);
assert.equal(t.samples[0].start, 518328 / 1000);
assert.equal(t.samples[1].start, 528674 / 1000);
assert.equal(t.samples[2].start, 536213 / 1000);
assert.deepEqual(
['~Instantiate native apinatives.js:9:21'],
t.samples[0].getUserFriendlyStackTrace());
assert.deepEqual(
['InstantiateFunction native apinatives.js:26:29',
'~Instantiate native apinatives.js:9:21'],
t.samples[1].getUserFriendlyStackTrace());
assert.deepEqual(
['InstantiateFunction native apinatives.js:26:29',
'~Instantiate native apinatives.js:9:21'],
t.samples[2].getUserFriendlyStackTrace());
var topLevelStackFrame = t.samples[0].leafStackFrame;
var childStackFrame = t.samples[1].leafStackFrame;
assert.equal(t.samples[2].leafStackFrame, childStackFrame);
assert.equal(topLevelStackFrame, childStackFrame.parentFrame);
assert.equal(topLevelStackFrame.children.length, 1);
assert.equal(childStackFrame.children.length, 0);
assert.equal(childStackFrame, topLevelStackFrame.children[0]);
});
test('twoSubStacks', function() {
var lines = [
'code-creation,LazyCompile,0,0x2904d560,876,"Instantiate native apinatives.js:9:21",0x56b190c8,~', // @suppress longLineCheck
'code-creation,LazyCompile,0,0x2905d0c0,1800,"InstantiateFunction native apinatives.js:26:29",0x56b19124,', // @suppress longLineCheck
'tick,0x7fd7f75c,518328,0,0x81d86da8,2,0x2904d6e8',
'tick,0x7fc6fe34,528674,0,0x3,0,0x2905d304,0x2904d6e8',
'tick,0x7fd2a534,536213,0,0x81d8d080,0,0x2905d304,0x2904d6e8',
'code-creation,Script,0,0x2906a7c0,792,"http://www.google.com/",0x5b12fe50,~', // @suppress longLineCheck
'tick,0xb6f51d30,794049,0,0xb6f7b368,2,0x2906a914',
'tick,0xb6f51d30,799145,0,0xb6f7b368,0,0x2906a914'
];
var m = newModel(lines.join('\n'));
var p = m.processes[-32];
var threads = p.findAllThreadsNamed('V8');
var t = threads[0];
assert.equal(t.samples.length, 5);
assert.equal(t.samples[0].start, 518328 / 1000);
assert.equal(t.samples[1].start, 528674 / 1000);
assert.equal(t.samples[2].start, 536213 / 1000);
assert.equal(t.samples[3].start, 794049 / 1000);
assert.equal(t.samples[4].start, 799145 / 1000);
assert.deepEqual(
['~Instantiate native apinatives.js:9:21'],
t.samples[0].getUserFriendlyStackTrace());
assert.deepEqual(
['InstantiateFunction native apinatives.js:26:29',
'~Instantiate native apinatives.js:9:21'],
t.samples[1].getUserFriendlyStackTrace());
assert.deepEqual(
['InstantiateFunction native apinatives.js:26:29',
'~Instantiate native apinatives.js:9:21'],
t.samples[2].getUserFriendlyStackTrace());
assert.deepEqual(['~http://www.google.com/'],
t.samples[3].getUserFriendlyStackTrace());
assert.deepEqual(['~http://www.google.com/'],
t.samples[4].getUserFriendlyStackTrace());
var firsStackTopLevelStackFrame = t.samples[0].leafStackFrame;
var firsStackChildStackFrame = t.samples[1].leafStackFrame;
assert.equal(firsStackChildStackFrame, t.samples[2].leafStackFrame);
assert.equal(firsStackTopLevelStackFrame,
firsStackChildStackFrame.parentFrame);
assert.equal(firsStackTopLevelStackFrame.children.length, 1);
assert.equal(firsStackChildStackFrame.children.length, 0);
assert.equal(firsStackChildStackFrame,
firsStackTopLevelStackFrame.children[0]);
var secondStackStackFrame = t.samples[3].leafStackFrame;
assert.equal(secondStackStackFrame, t.samples[4].leafStackFrame);
assert.equal(secondStackStackFrame.children.length, 0);
assert.isUndefined(secondStackStackFrame.parentFrame);
});
test('timerEventSliceCreation', function() {
var lines = ['timer-event,"V8.External",38189483,3'];
var m = newModel(lines.join('\n'));
var p = m.processes[-32];
var threads = p.findAllThreadsNamed('V8 Timers');
assert.isDefined(threads);
assert.equal(threads.length, 1);
var t = threads[0];
assert.equal(t.sliceGroup.length, 1);
});
test('processThreadCreation', function() {
var lines = ['timer-event,"V8.External",38189483,3'];
var m = newModel(lines.join('\n'));
assert.isDefined(m);
var p = m.processes[-32];
assert.isDefined(p);
var threads = p.findAllThreadsNamed('V8 Timers');
assert.isDefined(threads);
assert.equal(1, threads.length);
var t = threads[0];
assert.equal('V8 Timers', t.name);
});
test('canImport', function() {
assert.isTrue(V8LogImporter.canImport(
'timer-event,"V8.External",38189483,3'));
assert.isTrue(V8LogImporter.canImport('v8-version,4,3,66,0,0'));
assert.isFalse(V8LogImporter.canImport(''));
assert.isFalse(V8LogImporter.canImport([]));
});
test('CppSymbolsProcess', function() {
var lines = [
'shared-library,"/usr/loca/v8/out/native/d8",0x00400000, 0x01860000',
'cpp,0x00600000,100,"v8::internal::Heap::AllocateByteArray"',
'cpp,0x00700000,100,"v8::internal::Utf8StringKey::AsHandle"',
'tick,0x00600010,121,0,0x0,5',
'tick,0x00700010,122,0,0x0,5',
'tick,0x00800010,123,0,0x0,5'];
var m = newModel(lines.join('\n'));
var p = m.processes[-32];
var t = p.findAllThreadsNamed('V8')[0];
assert.equal(t.samples.length, 3);
assert.equal(t.samples[0].leafStackFrame.title,
'v8::internal::Heap::AllocateByteArray /usr/loca/v8/out/native/d8'); // @suppress longLineCheck
assert.equal(t.samples[1].leafStackFrame.title,
'v8::internal::Utf8StringKey::AsHandle /usr/loca/v8/out/native/d8'); // @suppress longLineCheck
assert.equal(t.samples[2].leafStackFrame.title,
'/usr/loca/v8/out/native/d8');
});
test('CppSymbolsWithJsStack', function() {
var lines = [
'shared-library,"/usr/loca/v8/out/native/d8",0x00400000, 0x01860000',
'cpp,0x00600000,100,"v8::internal::Heap::AllocateByteArray"',
'cpp,0x00700000,100,"v8::internal::Utf8StringKey::AsHandle"',
'code-creation,LazyCompile,0,0x2905d0c0,1800,"InstantiateFunction native apinatives.js:26:29",0x56b19124,', // @suppress longLineCheck
'tick,0x00700010,1,0,0x3,0,0x2905d304',
'tick,0x00600010,3,0,0x3,0,0x2905d306',
'tick,0x00800010,5,0,0x3,0,0x2905d306',
'tick,0x01860010,5,0,0x3,0,0x2905d306'];
var m = newModel(lines.join('\n'));
var p = m.processes[-32];
var t = p.findAllThreadsNamed('V8')[0];
assert.equal(t.samples.length, 4);
assert.deepEqual(t.samples[0].stackTrace.map(r => r.title), [
'v8::internal::Utf8StringKey::AsHandle /usr/loca/v8/out/native/d8',
'InstantiateFunction native apinatives.js:26:29'
]);
assert.deepEqual(t.samples[1].stackTrace.map(r => r.title), [
'v8::internal::Heap::AllocateByteArray /usr/loca/v8/out/native/d8',
'InstantiateFunction native apinatives.js:26:29'
]);
assert.deepEqual(t.samples[2].stackTrace.map(r => r.title), [
'/usr/loca/v8/out/native/d8',
'InstantiateFunction native apinatives.js:26:29'
]);
assert.deepEqual(t.samples[3].stackTrace.map(r => r.title), [
'InstantiateFunction native apinatives.js:26:29'
]);
});
});
</script>