OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright 2017 The Chromium Authors. All rights reserved. | 3 Copyright 2017 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/multi_dimensional_view.html"> | 8 <link rel="import" href="/tracing/base/multi_dimensional_view.html"> |
9 <link rel="import" href="/tracing/extras/chrome/chrome_processes.html"> | |
9 <link rel="import" href="/tracing/model/helpers/chrome_model_helper.html"> | 10 <link rel="import" href="/tracing/model/helpers/chrome_model_helper.html"> |
10 <link rel="import" href="/tracing/model/helpers/chrome_renderer_helper.html"> | 11 <link rel="import" href="/tracing/model/helpers/chrome_renderer_helper.html"> |
11 | 12 |
12 <script> | 13 <script> |
13 'use strict'; | 14 'use strict'; |
14 | 15 |
15 tr.exportTo('tr.e.chrome.cpuTime', function() { | 16 tr.exportTo('tr.e.chrome.cpuTime', function() { |
16 /** | 17 /** |
17 * Returns the total cpu time consumed within |range| by |thread|. | 18 * Returns the total cpu time consumed within |range| by |thread|. |
18 */ | 19 */ |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 initiatorToSegments.set(initiatorType, new Set()); | 102 initiatorToSegments.set(initiatorType, new Set()); |
102 } | 103 } |
103 initiatorToSegments.get(initiatorType).add(segment); | 104 initiatorToSegments.get(initiatorType).add(segment); |
104 } | 105 } |
105 } | 106 } |
106 } | 107 } |
107 return stageToInitiatorToSegments; | 108 return stageToInitiatorToSegments; |
108 } | 109 } |
109 | 110 |
110 /** | 111 /** |
112 * Returns a map of range in |ranges| to total cpu time used by |thread| | |
113 * during that range. | |
tdresser
2017/04/10 20:48:29
Use jsdoc.
dproy
2017/05/11 00:50:46
Done.
| |
114 */ | |
115 function computeCpuTimesForRanges_(ranges, thread) { | |
116 const rangeToCpuTime = new Map(); | |
117 for (const range of ranges) { | |
118 rangeToCpuTime.set(range, getCpuTimeForThread(thread, range)); | |
119 } | |
120 return rangeToCpuTime; | |
121 } | |
122 | |
123 /** | |
111 * Returns a map of segment in |segments| to intersection of bounds of that | 124 * Returns a map of segment in |segments| to intersection of bounds of that |
112 * segment and |rangeOfInterest|. | 125 * segment and |rangeOfInterest|. |
113 * | 126 * |
114 * We create this map so that we have a unique intersected range for each | 127 * We create this map so that we have a unique intersected range for each |
115 * segment. This saves memory, and the unique range can be used as a key in | 128 * segment. This saves memory, and the unique range can be used as a key in |
116 * other maps. | 129 * other maps. |
117 * | 130 * |
118 * The returned map will have a range for each segment in |segments|, even if | 131 * The returned map will have a range for each segment in |segments|, even if |
119 * the intersection is empty. If empty ranges are not intended to be included, | 132 * the intersection is empty. If empty ranges are not intended to be included, |
120 * |segments| should be filtered before calling this function. | 133 * |segments| should be filtered before calling this function. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 const segmentBounds = | 168 const segmentBounds = |
156 [...segments].map( | 169 [...segments].map( |
157 segment => segmentToBounds.get(segment)); | 170 segment => segmentToBounds.get(segment)); |
158 initiatorToRanges.set(initiator, segmentBounds); | 171 initiatorToRanges.set(initiator, segmentBounds); |
159 } | 172 } |
160 } | 173 } |
161 | 174 |
162 return stageToInitiatorToRanges; | 175 return stageToInitiatorToRanges; |
163 } | 176 } |
164 | 177 |
178 /** | |
179 * Returns the root node of a MultiDimensionalView in TopDownTreeView for cpu | |
180 * time. | |
181 * | |
182 * The returned tree view is three dimensional (processType, threadType, and | |
183 * railStage + initiator). Rail stage and initiator are not separate | |
184 * dimensions because they are not independent - there is no such thing as CSS | |
185 * Response or Scroll Load. | |
186 * | |
187 * Each node in the tree view contains two values - cpuUsage and cpuTotal. | |
188 * | |
189 * See cpu_time_multidimensinoal_view.md for more details about the returned | |
190 * multidimensional view. | |
191 */ | |
192 function constructMultiDimensionalView(model, rangeOfInterest) { | |
193 const mdvBuilder = new tr.b.MultiDimensionalViewBuilder( | |
194 3 /* dimensions (process, thread and rail stage / initiator) */, | |
195 2 /* valueCount (cpuUsage and cpuTotal) */); | |
196 | |
197 const stageToInitiatorToRanges = | |
198 getStageToInitiatorToSegmentBounds( | |
199 model.userModel.segments, rangeOfInterest); | |
200 | |
201 const allSegmentBoundsInRange = | |
202 stageToInitiatorToRanges.get('all_stages').get('all_initiators'); | |
203 | |
204 for (const pid in model.processes) { | |
205 const process = model.processes[pid]; | |
206 const processType = | |
207 tr.e.chrome.chrome_processes.canonicalizeProcessName(process.name); | |
208 for (const tid in process.threads) { | |
209 const thread = process.threads[tid]; | |
210 const threadType = thread.type; | |
211 | |
212 // Cache cpuTime for each segment bound. | |
213 const rangeToCpuTime = computeCpuTimesForRanges_( | |
214 allSegmentBoundsInRange, thread); | |
215 | |
216 for (const [stage, initiatorToRanges] of stageToInitiatorToRanges) { | |
217 for (const [initiator, ranges] of initiatorToRanges) { | |
218 const cpuTime = tr.b.math.Statistics.sum(ranges, | |
219 range => rangeToCpuTime.get(range)); | |
220 const duration = tr.b.math.Statistics.sum(ranges, | |
221 range => range.duration); | |
222 const cpuTimePerSecond = cpuTime / duration; | |
223 mdvBuilder.addPath( | |
224 [[processType], [threadType], [stage, initiator]], | |
225 [cpuTimePerSecond, cpuTime], | |
226 tr.b.MultiDimensionalViewBuilder.ValueKind.TOTAL); | |
227 } | |
228 } | |
229 } | |
230 } | |
231 | |
232 return mdvBuilder.buildTopDownTreeView(); | |
233 } | |
234 | |
165 return { | 235 return { |
166 getCpuTimeForThread, | 236 getCpuTimeForThread, |
167 getStageToInitiatorToSegments, | 237 getStageToInitiatorToSegments, |
168 getStageToInitiatorToSegmentBounds, | 238 getStageToInitiatorToSegmentBounds, |
239 constructMultiDimensionalView, | |
169 }; | 240 }; |
170 }); | 241 }); |
171 </script> | 242 </script> |
OLD | NEW |