| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright (c) 2015 The Chromium Authors. All rights reserved. | 3 Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
| 5 found in the LICENSE file. | 5 found in the LICENSE file. |
| 6 --> | 6 --> |
| 7 | 7 |
| 8 <link rel="import" href="/tracing/base/base.html"> | 8 <link rel="import" href="/tracing/base/base.html"> |
| 9 <link rel="import" href="/tracing/base/guid.html"> | 9 <link rel="import" href="/tracing/base/guid.html"> |
| 10 <link rel="import" href="/tracing/base/range.html"> | 10 <link rel="import" href="/tracing/base/range.html"> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * Returns the bounds of the event container, which describe the range | 48 * Returns the bounds of the event container, which describe the range |
| 49 * of timestamps for all ancestor events. | 49 * of timestamps for all ancestor events. |
| 50 */ | 50 */ |
| 51 get bounds() { | 51 get bounds() { |
| 52 return this.bounds_; | 52 return this.bounds_; |
| 53 }, | 53 }, |
| 54 | 54 |
| 55 // TODO(charliea): A default implementation of this method could likely be | 55 // TODO(charliea): A default implementation of this method could likely be |
| 56 // provided that uses 'iterateAllEvents'. | 56 // provided that iterates throuch getDescendantEvents. |
| 57 /** | 57 /** |
| 58 * Updates the bounds of the event container. After updating, this.bounds | 58 * Updates the bounds of the event container. After updating, this.bounds |
| 59 * will describe the range of timestamps of all ancestor events. | 59 * will describe the range of timestamps of all ancestor events. |
| 60 */ | 60 */ |
| 61 updateBounds: function() { | 61 updateBounds: function() { |
| 62 throw new Error('Not implemented'); | 62 throw new Error('Not implemented'); |
| 63 }, | 63 }, |
| 64 | 64 |
| 65 // TODO(charliea): A default implementation of this method could likely be | 65 // TODO(charliea): A default implementation of this method could likely be |
| 66 // provided that uses 'iterateAllEvents'. | 66 // provided that iterates through getDescendantEvents. |
| 67 /** | 67 /** |
| 68 * Shifts the timestamps for ancestor events by 'amount' milliseconds. | 68 * Shifts the timestamps for ancestor events by 'amount' milliseconds. |
| 69 */ | 69 */ |
| 70 shiftTimestampsForward: function(amount) { | 70 shiftTimestampsForward: function(amount) { |
| 71 throw new Error('Not implemented'); | 71 throw new Error('Not implemented'); |
| 72 }, | 72 }, |
| 73 | 73 |
| 74 |
| 74 /** | 75 /** |
| 75 * Iterates over all child events. | 76 * Returns an iterable of all child events. |
| 76 */ | 77 */ |
| 77 iterateAllEventsInThisContainer: function(eventTypePredicate, | 78 childEvents: function*() { |
| 78 callback, opt_this) { | |
| 79 // TODO(alexandermont): We need this.childEvents() to take an | |
| 80 // eventTypePredicate because it doesn't look possible to directly get the | |
| 81 // type object from an object, so we have to do the filtering before | |
| 82 // the iteration. Probably it would be better if we find a workaround | |
| 83 // for this. | |
| 84 for (var event of this.childEvents(eventTypePredicate, opt_this)) | |
| 85 callback.call(opt_this, event); | |
| 86 }, | 79 }, |
| 87 | 80 |
| 88 /** | 81 /** |
| 89 * Iterates over all child containers. | 82 * Returns an iterable of all events in this and descendant |
| 83 * event containers. |
| 90 */ | 84 */ |
| 91 iterateAllChildEventContainers: function(callback, opt_this) { | 85 getDescendantEvents: function*() { |
| 86 yield * this.childEvents(); |
| 92 for (var container of this.childEventContainers()) | 87 for (var container of this.childEventContainers()) |
| 93 callback.call(opt_this, container); | 88 yield * container.getDescendantEvents(); |
| 94 }, | 89 }, |
| 95 | 90 |
| 96 /** | 91 /** |
| 97 * Iterates over all events in this container and in descendant | 92 * Returns an iterable of all child event containers. |
| 98 * event containers. | |
| 99 */ | 93 */ |
| 100 iterateAllEvents: function(callback, opt_this) { | 94 childEventContainers: function*() { |
| 101 // If new-style iteration has been implemented for this container, use | |
| 102 // it for iterateAllEvents. | |
| 103 if (this.childEvents && this.childEventContainers) { | |
| 104 for (var event of this.childEvents(x => true, opt_this)) | |
| 105 callback.call(opt_this, event); | |
| 106 for (var container of this.childEventContainers()) | |
| 107 container.iterateAllEvents(callback, opt_this); | |
| 108 } else { | |
| 109 // Otherwise, just do it the old way. | |
| 110 this.iterateAllEventContainers(function(ec) { | |
| 111 ec.iterateAllEventsInThisContainer(x => true, callback, opt_this); | |
| 112 }); | |
| 113 } | |
| 114 }, | 95 }, |
| 115 | 96 |
| 116 /** | 97 /** |
| 117 * Iterates over this container and all descendant containers. | 98 * Returns an iterable containing this and all descendant event containers. |
| 118 */ | 99 */ |
| 119 iterateAllEventContainers: function(callback, opt_this) { | 100 getDescendantEventContainers: function*() { |
| 120 // If new-style iteration has been implemented for this container, use | 101 yield this; |
| 121 // it for iterateAllEventContainers. | 102 for (var container of this.childEventContainers()) |
| 122 if (this.childEvents && this.childEventContainers) { | 103 yield * container.getDescendantEventContainers(); |
| 123 callback.call(opt_this, this); | |
| 124 for (var container of this.childEventContainers()) | |
| 125 container.iterateAllEventContainers(callback, opt_this); | |
| 126 } else { | |
| 127 // Otherwise, just do it the old way. | |
| 128 function visit(ec) { | |
| 129 callback.call(opt_this, ec); | |
| 130 ec.iterateAllChildEventContainers(visit); | |
| 131 } | |
| 132 visit(this); | |
| 133 } | |
| 134 }, | 104 }, |
| 135 | 105 |
| 136 /** | 106 /** |
| 137 * Finds topmost slices in this container (see docstring for | 107 * Finds topmost slices in this container (see docstring for |
| 138 * findTopmostSlices). | 108 * findTopmostSlices). |
| 139 */ | 109 */ |
| 140 findTopmostSlicesInThisContainer: function(eventPredicate, callback, | 110 findTopmostSlicesInThisContainer: function*(eventPredicate, opt_this) { |
| 141 opt_this) { | |
| 142 throw new Error('Not implemented.'); | |
| 143 }, | 111 }, |
| 144 | 112 |
| 145 /** | 113 /** |
| 146 * The findTopmostSlices* series of helpers find all topmost slices | 114 * The findTopmostSlices* series of helpers find all topmost slices |
| 147 * satisfying the given predicates. | 115 * satisfying the given predicates. |
| 148 * | 116 * |
| 149 * As an example, suppose we are trying to find slices named 'C', with the | 117 * As an example, suppose we are trying to find slices named 'C', with the |
| 150 * following thread: | 118 * following thread: |
| 151 * | 119 * |
| 152 * -> |---C---| |-----D-----| | 120 * -> |---C---| |-----D-----| |
| 153 * |-C-| |---C---| <- | 121 * |-C-| |---C---| <- |
| 154 * | 122 * |
| 155 * findTopmostSlices would locate the pointed-to Cs, because the bottom C on | 123 * findTopmostSlices would locate the pointed-to Cs, because the bottom C on |
| 156 * the left is not the topmost C, and the right one is, even though it is | 124 * the left is not the topmost C, and the right one is, even though it is |
| 157 * not itself a top-level slice. | 125 * not itself a top-level slice. |
| 158 */ | 126 */ |
| 159 findTopmostSlices: function(eventPredicate, callback, opt_this) { | 127 findTopmostSlices: function*(eventPredicate) { |
| 160 this.iterateAllEventContainers(function(ec) { | 128 for (var ec of this.getDescendantEventContainers()) |
| 161 ec.findTopmostSlicesInThisContainer(eventPredicate, callback, opt_this); | 129 yield * ec.findTopmostSlicesInThisContainer(eventPredicate); |
| 162 }); | |
| 163 }, | 130 }, |
| 164 | 131 |
| 165 findTopmostSlicesNamed: function(name, callback, opt_this) { | 132 findTopmostSlicesNamed: function*(name) { |
| 166 this.findTopmostSlices(e => e.title === name, callback, opt_this); | 133 yield * this.findTopmostSlices(e => e.title === name); |
| 167 } | 134 } |
| 168 }; | 135 }; |
| 169 | 136 |
| 170 return { | 137 return { |
| 171 EventContainer: EventContainer | 138 EventContainer: EventContainer |
| 172 }; | 139 }; |
| 173 }); | 140 }); |
| 174 </script> | 141 </script> |
| OLD | NEW |