Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/CPUProfileDataModel.js

Issue 1624783002: DevTools: Switch to using fast stack iterator to collect stacks during timeline recording. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing more caseq@ comments. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698