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

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

Issue 2262543002: DevTools: Profiler domain refactoring: encode timestamps as deltas. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 * @constructor 6 * @constructor
7 * @extends {WebInspector.ProfileNode} 7 * @extends {WebInspector.ProfileNode}
8 * @param {!ProfilerAgent.CPUProfileNode} node 8 * @param {!ProfilerAgent.CPUProfileNode} node
9 * @param {number} sampleTime 9 * @param {number} sampleTime
10 */ 10 */
(...skipping 18 matching lines...) Expand all
29 __proto__: WebInspector.ProfileNode.prototype 29 __proto__: WebInspector.ProfileNode.prototype
30 } 30 }
31 31
32 /** 32 /**
33 * @constructor 33 * @constructor
34 * @extends {WebInspector.ProfileTreeModel} 34 * @extends {WebInspector.ProfileTreeModel}
35 * @param {!ProfilerAgent.CPUProfile} profile 35 * @param {!ProfilerAgent.CPUProfile} profile
36 */ 36 */
37 WebInspector.CPUProfileDataModel = function(profile) 37 WebInspector.CPUProfileDataModel = function(profile)
38 { 38 {
39 var isLegacyFormat = !!profile.head;
40 if (isLegacyFormat) {
41 // Legacy format contains raw timestamps and start/stop times are in sec onds.
42 this.profileStartTime = profile.startTime * 1000;
43 this.profileEndTime = profile.endTime * 1000;
44 this.timestamps = profile.timestamps;
45 } else {
46 // Current format encodes timestamps as deltas. Start/stop times are in microseconds.
47 this.profileStartTime = profile.startTime / 1000;
48 this.profileEndTime = profile.endTime / 1000;
49 this.timestamps = this._convertTimestampDeltas(profile);
50 }
39 this.samples = profile.samples; 51 this.samples = profile.samples;
40 this.timestamps = profile.timestamps;
41 // Convert times from sec to msec.
42 this.profileStartTime = profile.startTime * 1000;
43 this.profileEndTime = profile.endTime * 1000;
44 this.totalHitCount = 0; 52 this.totalHitCount = 0;
45 this._compatibilityConversionHeadToNodes(profile); 53 this._compatibilityConversionHeadToNodes(profile);
dgozman 2016/08/19 00:45:12 Let's call this in |isLegacyFormat| block?
alph 2016/08/20 01:51:10 Done.
46 this.profileHead = this._translateProfileTree(profile.nodes); 54 this.profileHead = this._translateProfileTree(profile.nodes);
47 WebInspector.ProfileTreeModel.call(this, this.profileHead); 55 WebInspector.ProfileTreeModel.call(this, this.profileHead);
48 this._extractMetaNodes(); 56 this._extractMetaNodes();
49 if (this.samples) { 57 if (this.samples) {
50 this._buildIdToNodeMap(); 58 this._buildIdToNodeMap();
51 this._sortSamples(); 59 this._sortSamples();
52 this._normalizeTimestamps(); 60 this._normalizeTimestamps();
53 } 61 }
54 } 62 }
55 63
(...skipping 16 matching lines...) Expand all
72 */ 80 */
73 function convertNodesTree(node) 81 function convertNodesTree(node)
74 { 82 {
75 nodes.push(node); 83 nodes.push(node);
76 node.children = (/** @type {!Array<!ProfilerAgent.CPUProfileNode>} * /(node.children)).map(convertNodesTree); 84 node.children = (/** @type {!Array<!ProfilerAgent.CPUProfileNode>} * /(node.children)).map(convertNodesTree);
77 return node.id; 85 return node.id;
78 } 86 }
79 }, 87 },
80 88
81 /** 89 /**
90 * @param {!ProfilerAgent.CPUProfile} profile
91 * @return {?Array<number>}
92 */
93 _convertTimestampDeltas: function(profile)
94 {
95 if (!profile.timestampDeltas)
96 return null;
97 var lastTimeUsec = profile.startTime;
98 var timestamps = new Array(profile.timestampDeltas.length);
99 for (var i = 0; i < timestamps.length; ++i) {
100 lastTimeUsec += profile.timestampDeltas[i];
101 timestamps[i] = lastTimeUsec;
102 }
103 return timestamps;
104 },
105
106 /**
82 * @param {!Array<!ProfilerAgent.CPUProfileNode>} nodes 107 * @param {!Array<!ProfilerAgent.CPUProfileNode>} nodes
83 * @return {!WebInspector.CPUProfileNode} 108 * @return {!WebInspector.CPUProfileNode}
84 */ 109 */
85 _translateProfileTree: function(nodes) 110 _translateProfileTree: function(nodes)
86 { 111 {
87 /** 112 /**
88 * @param {!ProfilerAgent.CPUProfileNode} node 113 * @param {!ProfilerAgent.CPUProfileNode} node
89 * @return {boolean} 114 * @return {boolean}
90 */ 115 */
91 function isNativeNode(node) 116 function isNativeNode(node)
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 * @param {number} index 347 * @param {number} index
323 * @return {?WebInspector.CPUProfileNode} 348 * @return {?WebInspector.CPUProfileNode}
324 */ 349 */
325 nodeByIndex: function(index) 350 nodeByIndex: function(index)
326 { 351 {
327 return this._idToNode.get(this.samples[index]) || null; 352 return this._idToNode.get(this.samples[index]) || null;
328 }, 353 },
329 354
330 __proto__: WebInspector.ProfileTreeModel.prototype 355 __proto__: WebInspector.ProfileTreeModel.prototype
331 } 356 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698