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. 4 5 'use strict'; 6 7 base.require('tracing.tracks.slice_group_track'); 8 base.require('ui'); 9 base.exportTo('tracing.tracks', function() { 10 11 /** 12 * A track that displays a AsyncSliceGroup. 13 * @constructor 14 * @extends {SliceGroup} 15 */ 16 17 var AsyncSliceGroupTrack = ui.define( 18 'async-slice-group-track', 19 tracing.tracks.SliceGroupTrack); 20 21 AsyncSliceGroupTrack.prototype = { 22 23 __proto__: tracing.tracks.SliceGroupTrack.prototype, 24 25 decorate: function(viewport) { 26 tracing.tracks.SliceGroupTrack.prototype.decorate.call(this, viewport); 27 this.classList.add('async-slice-group-track'); 28 }, 29 30 addSliceTrack_: function(slices) { 31 var track = 32 tracing.tracks.SliceGroupTrack.prototype.addSliceTrack_.call( 33 this, slices); 34 track.asyncStyle = true; 35 return track; 36 }, 37 38 /** 39 * Breaks up the list of slices into N rows, each of which is a list of 40 * slices that are non overlapping. 41 * 42 * It uses a very simple approach: walk through the slices in sorted order 43 * by start time. For each slice, try to fit it in an existing subRow. If it 44 * doesn't fit in any subrow, make another subRow. 45 */ 46 buildSubRows_: function() { 47 var slices = tracing.filterSliceArray(this.categoryFilter, 48 this.group_.slices); 49 slices.sort(function(x, y) { 50 return x.start - y.start; 51 }); 52 53 var subRows = []; 54 for (var i = 0; i < slices.length; i++) { 55 var slice = slices[i]; 56 57 var found = false; 58 for (var j = 0; j < subRows.length; j++) { 59 var subRow = subRows[j]; 60 var lastSliceInSubRow = subRow[subRow.length - 1]; 61 if (slice.start >= lastSliceInSubRow.end) { 62 found = true; 63 // Instead of plotting one big slice for the entire 64 // AsyncEvent, we plot each of the subSlices. 65 if (slice.subSlices === undefined || slice.subSlices.length < 1) 66 throw new Error('AsyncEvent missing subSlices: ') + 67 slice.name; 68 for (var k = 0; k < slice.subSlices.length; k++) 69 subRow.push(slice.subSlices[k]); 70 break; 71 } 72 } 73 if (!found) { 74 var subRow = []; 75 if (slice.subSlices !== undefined) { 76 for (var k = 0; k < slice.subSlices.length; k++) 77 subRow.push(slice.subSlices[k]); 78 subRows.push(subRow); 79 } 80 } 81 } 82 return subRows; 83 } 84 }; 85 86 return { 87 AsyncSliceGroupTrack: AsyncSliceGroupTrack 88 }; 89 }); 90