OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 /** | 6 /** |
7 * @constructor | 7 * @constructor |
8 * @param {!ProfilerAgent.CPUProfile} profile | 8 * @param {!ProfilerAgent.CPUProfile} profile |
9 */ | 9 */ |
10 WebInspector.CPUProfileDataModel = function(profile) | 10 WebInspector.CPUProfileDataModel = function(profile) |
11 { | 11 { |
12 this.profileHead = profile.head; | 12 this.profileHead = profile.head; |
13 this.samples = profile.samples; | 13 this.samples = profile.samples; |
14 this.timestamps = profile.timestamps; | 14 this.timestamps = profile.timestamps; |
15 this.profileStartTime = profile.startTime * 1000; | 15 this.profileStartTime = profile.startTime * 1000; |
16 this.profileEndTime = profile.endTime * 1000; | 16 this.profileEndTime = profile.endTime * 1000; |
17 this._assignParentsInProfile(); | 17 this._assignParentsInProfile(); |
18 if (this.samples) { | 18 if (this.samples) { |
| 19 this._sortSamples(); |
19 this._normalizeTimestamps(); | 20 this._normalizeTimestamps(); |
20 this._buildIdToNodeMap(); | 21 this._buildIdToNodeMap(); |
21 this._fixMissingSamples(); | 22 this._fixMissingSamples(); |
22 } | 23 } |
23 if (!WebInspector.moduleSetting("showNativeFunctionsInJSProfile").get()) | 24 if (!WebInspector.moduleSetting("showNativeFunctionsInJSProfile").get()) |
24 this._filterNativeFrames(); | 25 this._filterNativeFrames(); |
25 this._assignDepthsInProfile(); | 26 this._assignDepthsInProfile(); |
26 this._calculateTimes(profile); | 27 this._calculateTimes(profile); |
27 } | 28 } |
28 | 29 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 var length = children.length; | 150 var length = children.length; |
150 for (var i = 0; i < length; ++i) { | 151 for (var i = 0; i < length; ++i) { |
151 var child = children[i]; | 152 var child = children[i]; |
152 child.depth = depth; | 153 child.depth = depth; |
153 if (child.children.length) | 154 if (child.children.length) |
154 nodesToTraverse.push(child); | 155 nodesToTraverse.push(child); |
155 } | 156 } |
156 } | 157 } |
157 }, | 158 }, |
158 | 159 |
| 160 _sortSamples: function() |
| 161 { |
| 162 var timestamps = this.timestamps; |
| 163 var samples = this.samples; |
| 164 var indices = timestamps.map((x, index) => index); |
| 165 indices.sort((a, b) => timestamps[a] - timestamps[b]); |
| 166 for (var i = 0; i < timestamps.length; ++i) { |
| 167 var index = indices[i]; |
| 168 if (index === i) |
| 169 continue; |
| 170 // Move items in a cycle. |
| 171 var savedTimestamp = timestamps[i]; |
| 172 var savedSample = samples[i]; |
| 173 var currentIndex = i; |
| 174 while (index !== i) { |
| 175 samples[currentIndex] = samples[index]; |
| 176 timestamps[currentIndex] = timestamps[index]; |
| 177 currentIndex = index; |
| 178 index = indices[index]; |
| 179 indices[currentIndex] = currentIndex; |
| 180 } |
| 181 samples[currentIndex] = savedSample; |
| 182 timestamps[currentIndex] = savedTimestamp; |
| 183 } |
| 184 }, |
| 185 |
159 _normalizeTimestamps: function() | 186 _normalizeTimestamps: function() |
160 { | 187 { |
161 var timestamps = this.timestamps; | 188 var timestamps = this.timestamps; |
162 if (!timestamps) { | 189 if (!timestamps) { |
163 // Support loading old CPU profiles that are missing timestamps. | 190 // Support loading old CPU profiles that are missing timestamps. |
164 // Derive timestamps from profile start and stop times. | 191 // Derive timestamps from profile start and stop times. |
165 var profileStartTime = this.profileStartTime; | 192 var profileStartTime = this.profileStartTime; |
166 var interval = (this.profileEndTime - profileStartTime) / this.sampl
es.length; | 193 var interval = (this.profileEndTime - profileStartTime) / this.sampl
es.length; |
167 timestamps = new Float64Array(this.samples.length + 1); | 194 timestamps = new Float64Array(this.samples.length + 1); |
168 for (var i = 0; i < timestamps.length; ++i) | 195 for (var i = 0; i < timestamps.length; ++i) |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 /** | 395 /** |
369 * @param {number} index | 396 * @param {number} index |
370 * @return {!ProfilerAgent.CPUProfileNode} | 397 * @return {!ProfilerAgent.CPUProfileNode} |
371 */ | 398 */ |
372 nodeByIndex: function(index) | 399 nodeByIndex: function(index) |
373 { | 400 { |
374 return this._idToNode[this.samples[index]]; | 401 return this._idToNode[this.samples[index]]; |
375 } | 402 } |
376 | 403 |
377 } | 404 } |
OLD | NEW |