| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2013 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/async_slice.html"> |
| <link rel="import" href="/base/guid.html"> |
| <link rel="import" href="/base/range.html"> |
| |
| <script> |
| 'use strict'; |
| |
| /** |
| * @fileoverview Provides the AsyncSliceGroup class. |
| */ |
| tv.exportTo('tv.c.trace_model', function() { |
| /** |
| * A group of AsyncSlices associated with a thread. |
| * @constructor |
| * @extends {tv.c.trace_model.EventContainer} |
| */ |
| function AsyncSliceGroup(parentThread, opt_name) { |
| this.parentThread_ = parentThread; |
| this.guid_ = tv.b.GUID.allocate(); |
| this.slices = []; |
| this.bounds = new tv.b.Range(); |
| this.name_ = opt_name; |
| this.viewSubGroups_ = undefined; |
| } |
| |
| AsyncSliceGroup.prototype = { |
| __proto__: tv.c.trace_model.EventContainer.prototype, |
| |
| get guid() { |
| return this.guid_; |
| }, |
| |
| get parentThread() { |
| return this.parentThread_; |
| }, |
| |
| get model() { |
| return this.parentThread_.parent.model; |
| }, |
| |
| get stableId() { |
| return this.parentThread_.stableId + '.AsyncSliceGroup'; |
| }, |
| |
| getSettingsKey: function() { |
| if (!this.name_) |
| return undefined; |
| var parentKey = this.parentThread_.getSettingsKey(); |
| if (!parentKey) |
| return undefined; |
| return parentKey + '.' + this.name_; |
| }, |
| |
| /** |
| * Helper function that pushes the provided slice onto the slices array. |
| */ |
| push: function(slice) { |
| this.slices.push(slice); |
| }, |
| |
| /** |
| * @return {Number} The number of slices in this group. |
| */ |
| get length() { |
| return this.slices.length; |
| }, |
| |
| /** |
| * Shifts all the timestamps inside this group forward by the amount |
| * specified, including all nested subSlices if there are any. |
| */ |
| shiftTimestampsForward: function(amount) { |
| for (var sI = 0; sI < this.slices.length; sI++) { |
| var slice = this.slices[sI]; |
| slice.start = (slice.start + amount); |
| // Shift all nested subSlices recursively. |
| var shiftSubSlices = function(subSlices) { |
| if (subSlices === undefined || subSlices.length === 0) |
| return; |
| for (var sJ = 0; sJ < subSlices.length; sJ++) { |
| subSlices[sJ].start += amount; |
| shiftSubSlices(subSlices[sJ].subSlices); |
| } |
| }; |
| shiftSubSlices(slice.subSlices); |
| } |
| }, |
| |
| /** |
| * Updates the bounds for this group based on the slices it contains. |
| */ |
| updateBounds: function() { |
| this.bounds.reset(); |
| for (var i = 0; i < this.slices.length; i++) { |
| this.bounds.addValue(this.slices[i].start); |
| this.bounds.addValue(this.slices[i].end); |
| } |
| }, |
| |
| /** |
| * Gets the sub-groups in this A-S-G defined by the group titles. |
| * |
| * @return {Array} An array of AsyncSliceGroups where each group has |
| * slices that started on the same thread. |
| */ |
| get viewSubGroups() { |
| if (this.viewSubGroups_ === undefined) { |
| var prefix = ''; |
| if (this.name !== undefined) |
| prefix = this.name + '.'; |
| else |
| prefix = ''; |
| |
| var subGroupsByTitle = {}; |
| for (var i = 0; i < this.slices.length; ++i) { |
| var slice = this.slices[i]; |
| var subGroupTitle = slice.viewSubGroupTitle; |
| if (!subGroupsByTitle[subGroupTitle]) { |
| subGroupsByTitle[subGroupTitle] = new AsyncSliceGroup( |
| this.parentThread_, prefix + subGroupTitle); |
| } |
| subGroupsByTitle[subGroupTitle].slices.push(slice); |
| } |
| this.viewSubGroups_ = tv.b.dictionaryValues(subGroupsByTitle); |
| this.viewSubGroups_.sort(function(a, b) { |
| return a.slices[0].compareTo(b.slices[0]); |
| }); |
| } |
| return this.viewSubGroups_; |
| }, |
| |
| iterateAllEventsInThisContainer: function(eventTypePredicate, |
| callback, opt_this) { |
| if (eventTypePredicate.call(opt_this, tv.c.trace_model.AsyncSlice)) { |
| for (var i = 0; i < this.slices.length; i++) { |
| var slice = this.slices[i]; |
| callback.call(opt_this, slice); |
| if (slice.subSlices) |
| slice.subSlices.forEach(callback, opt_this); |
| } |
| } |
| }, |
| |
| iterateAllChildEventContainers: function(callback, opt_this) { |
| } |
| }; |
| |
| return { |
| AsyncSliceGroup: AsyncSliceGroup |
| }; |
| }); |
| </script> |