1 // Copyright (c) 2013 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.
8 * @fileoverview Provides the AsyncSliceGroup class.
10 tvcm.require('tvcm.range');
11 tvcm.require('tracing.trace_model.async_slice');
13 tvcm.exportTo('tracing.trace_model', function() {
15 * A group of AsyncSlices.
18 function AsyncSliceGroup() {
20 this.bounds = new tvcm.Range();
23 AsyncSliceGroup.prototype = {
24 __proto__: Object.prototype,
27 * Helper function that pushes the provided slice onto the slices array.
29 push: function(slice) {
30 this.slices.push(slice);
34 * @return {Number} The number of slices in this group.
37 return this.slices.length;
41 * Shifts all the timestamps inside this group forward by the amount
44 shiftTimestampsForward: function(amount) {
45 for (var sI = 0; sI < this.slices.length; sI++) {
46 var slice = this.slices[sI];
47 slice.start = (slice.start + amount);
48 for (var sJ = 0; sJ < slice.subSlices.length; sJ++)
49 slice.subSlices[sJ].start += amount;
54 * Updates the bounds for this group based on the slices it contains.
56 updateBounds: function() {
58 for (var i = 0; i < this.slices.length; i++) {
59 this.bounds.addValue(this.slices[i].start);
60 this.bounds.addValue(this.slices[i].end);
65 * Breaks up this group into slices based on start thread.
67 * @return {Array} An array of AsyncSliceGroups where each group has
68 * slices that started on the same thread.
70 computeSubGroups: function() {
71 var subGroupsByGUID = {};
72 for (var i = 0; i < this.slices.length; ++i) {
73 var slice = this.slices[i];
74 var sliceGUID = slice.startThread.guid;
75 if (!subGroupsByGUID[sliceGUID])
76 subGroupsByGUID[sliceGUID] = new AsyncSliceGroup();
77 subGroupsByGUID[sliceGUID].slices.push(slice);
80 for (var guid in subGroupsByGUID) {
81 var group = subGroupsByGUID[guid];
88 iterateAllEvents: function(callback, opt_this) {
89 for (var i = 0; i < this.slices.length; i++) {
90 var slice = this.slices[i];
91 callback.call(opt_this, slice);
93 slice.subSlices.forEach(callback, opt_this);
99 AsyncSliceGroup: AsyncSliceGroup