OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright (c) 2014 The Chromium Authors. All rights reserved. | 3 Copyright (c) 2014 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/iteration_helpers.html"> | 9 <link rel="import" href="/tracing/base/iteration_helpers.html"> |
10 | 10 |
11 <script> | 11 <script> |
12 'use strict'; | 12 'use strict'; |
13 | 13 |
14 /** | 14 /** |
15 * @fileoverview Provides event merging functionality for grouping/analysis. | 15 * @fileoverview Provides event merging functionality for grouping/analysis. |
16 */ | 16 */ |
17 tr.exportTo('tr.b', function() { | 17 tr.exportTo('tr.b.math', function() { |
18 function convertEventsToRanges(events) { | 18 function convertEventsToRanges(events) { |
19 return events.map(function(event) { | 19 return events.map(function(event) { |
20 return tr.b.Range.fromExplicitRange(event.start, event.end); | 20 return tr.b.math.Range.fromExplicitRange(event.start, event.end); |
21 }); | 21 }); |
22 } | 22 } |
23 | 23 |
24 function mergeRanges(inRanges, mergeThreshold, mergeFunction) { | 24 function mergeRanges(inRanges, mergeThreshold, mergeFunction) { |
25 var remainingEvents = inRanges.slice(); | 25 var remainingEvents = inRanges.slice(); |
26 remainingEvents.sort(function(x, y) { | 26 remainingEvents.sort(function(x, y) { |
27 return x.min - y.min; | 27 return x.min - y.min; |
28 }); | 28 }); |
29 | 29 |
30 if (remainingEvents.length <= 1) { | 30 if (remainingEvents.length <= 1) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 emptyRanges.push(opt_totalRange); | 90 emptyRanges.push(opt_totalRange); |
91 return emptyRanges; | 91 return emptyRanges; |
92 } | 92 } |
93 | 93 |
94 inRanges = inRanges.slice(); | 94 inRanges = inRanges.slice(); |
95 inRanges.sort(function(x, y) { | 95 inRanges.sort(function(x, y) { |
96 return x.min - y.min; | 96 return x.min - y.min; |
97 }); | 97 }); |
98 if (opt_totalRange && | 98 if (opt_totalRange && |
99 (opt_totalRange.min < inRanges[0].min)) { | 99 (opt_totalRange.min < inRanges[0].min)) { |
100 emptyRanges.push(tr.b.Range.fromExplicitRange( | 100 emptyRanges.push(tr.b.math.Range.fromExplicitRange( |
101 opt_totalRange.min, inRanges[0].min)); | 101 opt_totalRange.min, inRanges[0].min)); |
102 } | 102 } |
103 | 103 |
104 inRanges.forEach(function(range, index) { | 104 inRanges.forEach(function(range, index) { |
105 for (var otherIndex = 0; otherIndex < inRanges.length; ++otherIndex) { | 105 for (var otherIndex = 0; otherIndex < inRanges.length; ++otherIndex) { |
106 if (index === otherIndex) | 106 if (index === otherIndex) |
107 continue; | 107 continue; |
108 var other = inRanges[otherIndex]; | 108 var other = inRanges[otherIndex]; |
109 | 109 |
110 if (other.min > range.max) { | 110 if (other.min > range.max) { |
111 // |inRanges| is sorted, so |other| is the first range after |range|, | 111 // |inRanges| is sorted, so |other| is the first range after |range|, |
112 // and there is an empty range between them. | 112 // and there is an empty range between them. |
113 emptyRanges.push(tr.b.Range.fromExplicitRange( | 113 emptyRanges.push(tr.b.math.Range.fromExplicitRange( |
114 range.max, other.min)); | 114 range.max, other.min)); |
115 return; | 115 return; |
116 } | 116 } |
117 // Otherwise, |other| starts before |range| ends, so |other| might | 117 // Otherwise, |other| starts before |range| ends, so |other| might |
118 // possibly contain the end of |range|. | 118 // possibly contain the end of |range|. |
119 | 119 |
120 if (other.max > range.max) { | 120 if (other.max > range.max) { |
121 // |other| does contain the end of |range|, so no empty range starts | 121 // |other| does contain the end of |range|, so no empty range starts |
122 // at the end of this |range|. | 122 // at the end of this |range|. |
123 return; | 123 return; |
124 } | 124 } |
125 } | 125 } |
126 if (opt_totalRange && (range.max < opt_totalRange.max)) { | 126 if (opt_totalRange && (range.max < opt_totalRange.max)) { |
127 emptyRanges.push(tr.b.Range.fromExplicitRange( | 127 emptyRanges.push(tr.b.math.Range.fromExplicitRange( |
128 range.max, opt_totalRange.max)); | 128 range.max, opt_totalRange.max)); |
129 } | 129 } |
130 }); | 130 }); |
131 return emptyRanges; | 131 return emptyRanges; |
132 } | 132 } |
133 | 133 |
134 return { | 134 return { |
135 convertEventsToRanges, | 135 convertEventsToRanges, |
136 findEmptyRangesBetweenRanges, | 136 findEmptyRangesBetweenRanges, |
137 mergeRanges, | 137 mergeRanges, |
138 }; | 138 }; |
139 }); | 139 }); |
140 </script> | 140 </script> |
OLD | NEW |