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

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: update profiler tests Created 4 years, 10 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 if (!timestamps)
164 return;
165 var samples = this.samples;
166 var indices = timestamps.map((x, index) => index);
167 indices.sort((a, b) => timestamps[a] - timestamps[b]);
168 for (var i = 0; i < timestamps.length; ++i) {
169 var index = indices[i];
170 if (index === i)
171 continue;
172 // Move items in a cycle.
173 var savedTimestamp = timestamps[i];
174 var savedSample = samples[i];
175 var currentIndex = i;
176 while (index !== i) {
177 samples[currentIndex] = samples[index];
178 timestamps[currentIndex] = timestamps[index];
179 currentIndex = index;
180 index = indices[index];
181 indices[currentIndex] = currentIndex;
182 }
183 samples[currentIndex] = savedSample;
184 timestamps[currentIndex] = savedTimestamp;
185 }
186 },
187
159 _normalizeTimestamps: function() 188 _normalizeTimestamps: function()
160 { 189 {
161 var timestamps = this.timestamps; 190 var timestamps = this.timestamps;
162 if (!timestamps) { 191 if (!timestamps) {
163 // Support loading old CPU profiles that are missing timestamps. 192 // Support loading old CPU profiles that are missing timestamps.
164 // Derive timestamps from profile start and stop times. 193 // Derive timestamps from profile start and stop times.
165 var profileStartTime = this.profileStartTime; 194 var profileStartTime = this.profileStartTime;
166 var interval = (this.profileEndTime - profileStartTime) / this.sampl es.length; 195 var interval = (this.profileEndTime - profileStartTime) / this.sampl es.length;
167 timestamps = new Float64Array(this.samples.length + 1); 196 timestamps = new Float64Array(this.samples.length + 1);
168 for (var i = 0; i < timestamps.length; ++i) 197 for (var i = 0; i < timestamps.length; ++i)
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 /** 397 /**
369 * @param {number} index 398 * @param {number} index
370 * @return {!ProfilerAgent.CPUProfileNode} 399 * @return {!ProfilerAgent.CPUProfileNode}
371 */ 400 */
372 nodeByIndex: function(index) 401 nodeByIndex: function(index)
373 { 402 {
374 return this._idToNode[this.samples[index]]; 403 return this._idToNode[this.samples[index]];
375 } 404 }
376 405
377 } 406 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698