1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5'use strict'; 6 7/** 8 * @fileoverview Helper functions for use in tracing tests. 9 */ 10'use strict'; 11 12base.require('tracing.trace_model.counter'); 13base.require('tracing.trace_model.slice'); 14base.require('tracing.trace_model.slice_group'); 15 16base.exportTo('tracing.test_utils', function() { 17 function newAsyncSlice(start, duration, startThread, endThread) { 18 return newAsyncSliceNamed('a', start, duration, startThread, endThread); 19 } 20 21 function newAsyncSliceNamed(name, start, duration, startThread, endThread) { 22 var s = new tracing.trace_model.AsyncSlice('', name, 0, start); 23 s.duration = duration; 24 s.startThread = startThread; 25 s.endThread = endThread; 26 var subSlice = new tracing.trace_model.AsyncSlice('', name, 0, start); 27 subSlice.duration = duration; 28 subSlice.startThread = startThread; 29 subSlice.endThread = endThread; 30 s.subSlices = [subSlice]; 31 return s; 32 } 33 34 function newCounter(parent) { 35 return newCounterNamed(parent, 'a'); 36 } 37 38 function newCounterNamed(parent, name) { 39 var s = new tracing.trace_model.Counter(parent, name, null, name); 40 return s; 41 } 42 43 function newCounterCategory(parent, category, name) { 44 var s = new tracing.trace_model.Counter(parent, name, category, name); 45 return s; 46 } 47 48 function newSlice(start, duration) { 49 return newSliceNamed('a', start, duration); 50 } 51 52 function newSliceNamed(name, start, duration) { 53 var s = new tracing.trace_model.Slice('', name, 0, start, {}, duration); 54 return s; 55 } 56 57 function newSliceCategory(category, name, start, duration) { 58 var s = new tracing.trace_model.Slice( 59 category, name, 0, start, {}, duration); 60 return s; 61 } 62 63 function findSliceNamed(slices, name) { 64 if (slices instanceof tracing.trace_model.SliceGroup) 65 slices = slices.slices; 66 for (var i = 0; i < slices.length; i++) 67 if (slices[i].title == name) 68 return slices[i]; 69 return undefined; 70 } 71 72 return { 73 newAsyncSlice: newAsyncSlice, 74 newAsyncSliceNamed: newAsyncSliceNamed, 75 newCounter: newCounter, 76 newCounterNamed: newCounterNamed, 77 newCounterCategory: newCounterCategory, 78 newSlice: newSlice, 79 newSliceNamed: newSliceNamed, 80 newSliceCategory: newSliceCategory, 81 findSliceNamed: findSliceNamed 82 }; 83}); 84