3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
8 <link rel="import" href="/tracing/tracks/multi_row_track.html">
9 <link rel="import" href="/tracing/tracks/slice_track.html">
10 <link rel="import" href="/base/ui.html">
15 tv.exportTo('tracing.tracks', function() {
17 * A track that displays a AsyncSliceGroup.
19 * @extends {MultiRowTrack}
21 var AsyncSliceGroupTrack = tv.ui.define(
22 'async-slice-group-track',
23 tracing.tracks.MultiRowTrack);
25 AsyncSliceGroupTrack.prototype = {
27 __proto__: tracing.tracks.MultiRowTrack.prototype,
29 decorate: function(viewport) {
30 tracing.tracks.MultiRowTrack.prototype.decorate.call(this, viewport);
31 this.classList.add('async-slice-group-track');
32 this.group_ = undefined;
35 addSubTrack_: function(slices) {
36 var track = new tracing.tracks.SliceTrack(this.viewport);
37 track.slices = slices;
38 this.appendChild(track);
39 track.asyncStyle = true;
49 this.setItemsToGroup(this.group_.slices, this.group_);
53 * Breaks up the list of slices into N rows, each of which is a list of
54 * slices that are non overlapping.
56 * It uses a very simple approach: walk through the slices in sorted order
57 * by start time. For each slice, try to fit it in an existing subRow. If
58 * it doesn't fit in any subrow, make another subRow. It then fits nested
59 * subSlices recursively into rows below parent slice according to which
60 * nested level the child is in.
62 buildSubRows_: function(slices) {
63 slices.sort(function(x, y) {
64 return x.start - y.start;
67 // Helper function that returns true if it can put the slice on row n.
68 var findLevel = function(sliceToPut, rows, n) {
70 return true; // We always can make empty rows to put the slice.
72 var lastSliceInSubRow = subRow[subRow.length - 1];
73 if (sliceToPut.start >= lastSliceInSubRow.end) {
74 if (sliceToPut.subSlices === undefined ||
75 sliceToPut.subSlices.length === 0) {
78 // Make sure nested sub slices can be fitted in as well.
79 for (var i = 0; i < sliceToPut.subSlices.length; i++) {
80 if (!findLevel(sliceToPut.subSlices[i], rows, n + 1))
89 for (var i = 0; i < slices.length; i++) {
90 var slice = slices[i];
91 slice.isTopLevel = true;
94 var index = subRows.length;
95 for (var j = 0; j < subRows.length; j++) {
96 if (findLevel(slice, subRows, j)) {
104 subRows[index].push(slice);
106 // Fit subSlices recursively into rows below parent.
107 var fitSubSlicesRecursively = function(subSlices, level, rows) {
108 if (subSlices === undefined || subSlices.length === 0)
110 if (level === rows.length)
112 for (var h = 0; h < subSlices.length; h++) {
113 rows[level].push(subSlices[h]);
114 fitSubSlicesRecursively(subSlices[h].subSlices, level + 1, rows);
117 fitSubSlicesRecursively(slice.subSlices, index + 1, subRows);
124 AsyncSliceGroupTrack: AsyncSliceGroupTrack