blob: 026e1621c2ab1bfbf989879f274aa51a7656c2ec [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2012 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/trace_model/counter.html">
<link rel="import" href="/core/trace_model/slice.html">
<link rel="import" href="/core/trace_model/slice_group.html">
<link rel="import" href="/core/trace_model/stack_frame.html">
<script>
'use strict';
/**
* @fileoverview Helper functions for use in tracing tests.
*/
tv.exportTo('tv.c.test_utils', function() {
function newAsyncSlice(start, duration, startThread, endThread) {
return newAsyncSliceNamed('a', start, duration, startThread, endThread);
}
function newAsyncSliceNamed(name, start, duration, startThread, endThread) {
var asyncSliceConstructor =
tv.c.trace_model.AsyncSlice.getConstructor('', name);
var s = new asyncSliceConstructor('', name, 0, start);
s.duration = duration;
s.startThread = startThread;
s.endThread = endThread;
return s;
}
function newCounter(parent) {
return newCounterNamed(parent, 'a');
}
function newCounterNamed(parent, name) {
var s = new tv.c.trace_model.Counter(parent, name, null, name);
return s;
}
function newCounterCategory(parent, category, name) {
var s = new tv.c.trace_model.Counter(parent, name, category, name);
return s;
}
function newCounterSeries() {
var s = new tv.c.trace_model.CounterSeries('a', 0);
return s;
}
function newSlice(start, duration) {
return newSliceNamed('a', start, duration);
}
function newSliceNamed(name, start, duration) {
var s = new tv.c.trace_model.Slice('', name, 0, start, {}, duration);
return s;
}
function newSampleNamed(thread, sampleName, category, frameNames, start) {
var model;
if (thread.parent)
model = thread.parent.model;
else
model = undefined;
var sf = newStackTrace(model, category, frameNames);
var s = new tv.c.trace_model.Sample(undefined, thread,
sampleName, start,
sf,
1);
return s;
}
function newSliceCategory(category, name, start, duration) {
var s = new tv.c.trace_model.Slice(
category, name, 0, start, {}, duration);
return s;
}
function newSliceEx(options) {
if (options.start === undefined)
throw new Error('Too little info');
var title = options.title ? options.title : 'a';
var colorId = options.colorId ? options.colorId : 0;
var duration;
if (options.duration !== undefined) {
if (options.end !== undefined) throw new Error('TMI');
duration = options.duration;
} else if (options.end !== undefined) {
if (options.duration !== undefined) throw new Error('TMI');
duration = options.end - options.start;
} else {
throw new Error('Too little info');
}
var cpuStart = options.cpuStart;
var cpuDuration;
if (options.cpuDuration !== undefined) {
if (cpuStart !== undefined) throw new Error('Too little info');
if (options.cpuEnd !== undefined) throw new Error('TMI');
cpuDuration = options.cpuDuration;
} else if (options.cpuEnd !== undefined) {
if (cpuStart === undefined) throw new Error('Too little info');
if (options.cpuDuration !== undefined) throw new Error('TMI');
cpuDuration = options.cpuEnd - cpuStart;
}
var slice = new tv.c.trace_model.Slice(
options.cat ? options.cat : 'cat',
title,
colorId,
options.start,
options.args ? options.args : {},
duration,
cpuStart, cpuDuration);
return slice;
}
function newStackTrace(model, category, titles) {
var frame = undefined;
for (var i = 0; i < titles.length; i++) {
frame = new tv.c.trace_model.StackFrame(frame, tv.b.GUID.allocate(),
category, titles[i], 7);
if (model)
model.addStackFrame(frame);
}
return frame;
}
function findSliceNamed(slices, name) {
if (slices instanceof tv.c.trace_model.SliceGroup)
slices = slices.slices;
for (var i = 0; i < slices.length; i++)
if (slices[i].title == name)
return slices[i];
return undefined;
}
function newModel(customizeModelCallback) {
var io = new tv.c.ImportOptions();
io.customizeModelCallback = customizeModelCallback;
io.shiftWorldToZero = false;
return new tv.c.TraceModel([], io);
}
function newModelWithAuditor(customizeModelCallback, auditor) {
var io = new tv.c.ImportOptions();
io.customizeModelCallback = customizeModelCallback;
io.shiftWorldToZero = false;
io.auditorConstructors = [auditor];
return new tv.c.TraceModel([], io);
}
return {
newAsyncSlice: newAsyncSlice,
newAsyncSliceNamed: newAsyncSliceNamed,
newCounter: newCounter,
newCounterNamed: newCounterNamed,
newCounterCategory: newCounterCategory,
newCounterSeries: newCounterSeries,
newSlice: newSlice,
newSliceNamed: newSliceNamed,
newSliceEx: newSliceEx,
newSampleNamed: newSampleNamed,
newSliceCategory: newSliceCategory,
newStackTrace: newStackTrace,
newModel: newModel,
newModelWithAuditor: newModelWithAuditor,
findSliceNamed: findSliceNamed
};
});
</script>