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 * @constructor | 6 * @constructor |
7 * @extends {WebInspector.ProfileNode} | 7 * @extends {WebInspector.ProfileNode} |
8 * @param {!ProfilerAgent.CPUProfileNode} node | 8 * @param {!ProfilerAgent.ProfileNode} node |
9 * @param {number} sampleTime | 9 * @param {number} sampleTime |
10 */ | 10 */ |
11 WebInspector.CPUProfileNode = function(node, sampleTime) | 11 WebInspector.CPUProfileNode = function(node, sampleTime) |
12 { | 12 { |
13 var callFrame = node.callFrame || /** @type {!RuntimeAgent.CallFrame} */ ({ | 13 var callFrame = node.callFrame || /** @type {!RuntimeAgent.CallFrame} */ ({ |
14 // Backward compatibility for old SamplingHeapProfileNode format. | 14 // Backward compatibility for old SamplingHeapProfileNode format. |
15 functionName: node["functionName"], | 15 functionName: node["functionName"], |
16 scriptId: node["scriptId"], | 16 scriptId: node["scriptId"], |
17 url: node["url"], | 17 url: node["url"], |
18 lineNumber: node["lineNumber"] - 1, | 18 lineNumber: node["lineNumber"] - 1, |
19 columnNumber: node["columnNumber"] - 1 | 19 columnNumber: node["columnNumber"] - 1 |
20 }); | 20 }); |
21 WebInspector.ProfileNode.call(this, callFrame); | 21 WebInspector.ProfileNode.call(this, callFrame); |
22 this.id = node.id; | 22 this.id = node.id; |
23 this.self = node.hitCount * sampleTime; | 23 this.self = node.hitCount * sampleTime; |
24 this.positionTicks = node.positionTicks; | 24 this.positionTicks = node.positionTicks; |
25 // Compatibility: legacy backends could provide "no reason" for optimized fu
nctions. | 25 // Compatibility: legacy backends could provide "no reason" for optimized fu
nctions. |
26 this.deoptReason = node.deoptReason && node.deoptReason !== "no reason" ? no
de.deoptReason : null; | 26 this.deoptReason = node.deoptReason && node.deoptReason !== "no reason" ? no
de.deoptReason : null; |
27 } | 27 } |
28 | 28 |
29 WebInspector.CPUProfileNode.prototype = { | 29 WebInspector.CPUProfileNode.prototype = { |
30 __proto__: WebInspector.ProfileNode.prototype | 30 __proto__: WebInspector.ProfileNode.prototype |
31 } | 31 } |
32 | 32 |
33 /** | 33 /** |
34 * @constructor | 34 * @constructor |
35 * @extends {WebInspector.ProfileTreeModel} | 35 * @extends {WebInspector.ProfileTreeModel} |
36 * @param {!ProfilerAgent.CPUProfile} profile | 36 * @param {!ProfilerAgent.Profile} profile |
37 */ | 37 */ |
38 WebInspector.CPUProfileDataModel = function(profile) | 38 WebInspector.CPUProfileDataModel = function(profile) |
39 { | 39 { |
40 var isLegacyFormat = !!profile["head"]; | 40 var isLegacyFormat = !!profile["head"]; |
41 if (isLegacyFormat) { | 41 if (isLegacyFormat) { |
42 // Legacy format contains raw timestamps and start/stop times are in sec
onds. | 42 // Legacy format contains raw timestamps and start/stop times are in sec
onds. |
43 this.profileStartTime = profile.startTime * 1000; | 43 this.profileStartTime = profile.startTime * 1000; |
44 this.profileEndTime = profile.endTime * 1000; | 44 this.profileEndTime = profile.endTime * 1000; |
45 this.timestamps = profile.timestamps; | 45 this.timestamps = profile.timestamps; |
46 this._compatibilityConversionHeadToNodes(profile); | 46 this._compatibilityConversionHeadToNodes(profile); |
47 } else { | 47 } else { |
48 // Current format encodes timestamps as deltas. Start/stop times are in
microseconds. | 48 // Current format encodes timestamps as deltas. Start/stop times are in
microseconds. |
49 this.profileStartTime = profile.startTime / 1000; | 49 this.profileStartTime = profile.startTime / 1000; |
50 this.profileEndTime = profile.endTime / 1000; | 50 this.profileEndTime = profile.endTime / 1000; |
51 this.timestamps = this._convertTimestampDeltas(profile); | 51 this.timestamps = this._convertTimeDeltas(profile); |
52 } | 52 } |
53 this.samples = profile.samples; | 53 this.samples = profile.samples; |
54 this.totalHitCount = 0; | 54 this.totalHitCount = 0; |
55 this.profileHead = this._translateProfileTree(profile.nodes); | 55 this.profileHead = this._translateProfileTree(profile.nodes); |
56 WebInspector.ProfileTreeModel.call(this, this.profileHead); | 56 WebInspector.ProfileTreeModel.call(this, this.profileHead); |
57 this._extractMetaNodes(); | 57 this._extractMetaNodes(); |
58 if (this.samples) { | 58 if (this.samples) { |
59 this._buildIdToNodeMap(); | 59 this._buildIdToNodeMap(); |
60 this._sortSamples(); | 60 this._sortSamples(); |
61 this._normalizeTimestamps(); | 61 this._normalizeTimestamps(); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 WebInspector.CPUProfileDataModel.prototype = { | 65 WebInspector.CPUProfileDataModel.prototype = { |
66 /** | 66 /** |
67 * @param {!ProfilerAgent.CPUProfile} profile | 67 * @param {!ProfilerAgent.Profile} profile |
68 */ | 68 */ |
69 _compatibilityConversionHeadToNodes: function(profile) | 69 _compatibilityConversionHeadToNodes: function(profile) |
70 { | 70 { |
71 if (!profile.head || profile.nodes) | 71 if (!profile.head || profile.nodes) |
72 return; | 72 return; |
73 /** @type {!Array<!ProfilerAgent.CPUProfileNode>} */ | 73 /** @type {!Array<!ProfilerAgent.ProfileNode>} */ |
74 var nodes = []; | 74 var nodes = []; |
75 convertNodesTree(profile.head); | 75 convertNodesTree(profile.head); |
76 profile.nodes = nodes; | 76 profile.nodes = nodes; |
77 delete profile.head; | 77 delete profile.head; |
78 /** | 78 /** |
79 * @param {!ProfilerAgent.CPUProfileNode} node | 79 * @param {!ProfilerAgent.ProfileNode} node |
80 * @return {number} | 80 * @return {number} |
81 */ | 81 */ |
82 function convertNodesTree(node) | 82 function convertNodesTree(node) |
83 { | 83 { |
84 nodes.push(node); | 84 nodes.push(node); |
85 node.children = (/** @type {!Array<!ProfilerAgent.CPUProfileNode>} *
/(node.children)).map(convertNodesTree); | 85 node.children = (/** @type {!Array<!ProfilerAgent.ProfileNode>} */(n
ode.children)).map(convertNodesTree); |
86 return node.id; | 86 return node.id; |
87 } | 87 } |
88 }, | 88 }, |
89 | 89 |
90 /** | 90 /** |
91 * @param {!ProfilerAgent.CPUProfile} profile | 91 * @param {!ProfilerAgent.Profile} profile |
92 * @return {?Array<number>} | 92 * @return {?Array<number>} |
93 */ | 93 */ |
94 _convertTimestampDeltas: function(profile) | 94 _convertTimeDeltas: function(profile) |
95 { | 95 { |
96 if (!profile.timestampDeltas) | 96 if (!profile.timeDeltas) |
97 return null; | 97 return null; |
98 var lastTimeUsec = profile.startTime; | 98 var lastTimeUsec = profile.startTime; |
99 var timestamps = new Array(profile.timestampDeltas.length); | 99 var timestamps = new Array(profile.timeDeltas.length); |
100 for (var i = 0; i < timestamps.length; ++i) { | 100 for (var i = 0; i < timestamps.length; ++i) { |
101 lastTimeUsec += profile.timestampDeltas[i]; | 101 lastTimeUsec += profile.timeDeltas[i]; |
102 timestamps[i] = lastTimeUsec; | 102 timestamps[i] = lastTimeUsec; |
103 } | 103 } |
104 return timestamps; | 104 return timestamps; |
105 }, | 105 }, |
106 | 106 |
107 /** | 107 /** |
108 * @param {!Array<!ProfilerAgent.CPUProfileNode>} nodes | 108 * @param {!Array<!ProfilerAgent.ProfileNode>} nodes |
109 * @return {!WebInspector.CPUProfileNode} | 109 * @return {!WebInspector.CPUProfileNode} |
110 */ | 110 */ |
111 _translateProfileTree: function(nodes) | 111 _translateProfileTree: function(nodes) |
112 { | 112 { |
113 /** | 113 /** |
114 * @param {!ProfilerAgent.CPUProfileNode} node | 114 * @param {!ProfilerAgent.ProfileNode} node |
115 * @return {boolean} | 115 * @return {boolean} |
116 */ | 116 */ |
117 function isNativeNode(node) | 117 function isNativeNode(node) |
118 { | 118 { |
119 if (node.callFrame) | 119 if (node.callFrame) |
120 return !!node.callFrame.url && node.callFrame.url.startsWith("na
tive "); | 120 return !!node.callFrame.url && node.callFrame.url.startsWith("na
tive "); |
121 return !!node.url && node.url.startsWith("native "); | 121 return !!node.url && node.url.startsWith("native "); |
122 } | 122 } |
123 /** @type {!Map<number, !ProfilerAgent.CPUProfileNode>} */ | 123 /** @type {!Map<number, !ProfilerAgent.ProfileNode>} */ |
124 var nodeByIdMap = new Map(); | 124 var nodeByIdMap = new Map(); |
125 for (var i = 0; i < nodes.length; ++i) { | 125 for (var i = 0; i < nodes.length; ++i) { |
126 var node = nodes[i]; | 126 var node = nodes[i]; |
127 nodeByIdMap.set(node.id, node); | 127 nodeByIdMap.set(node.id, node); |
128 } | 128 } |
129 this.totalHitCount = nodes.reduce((acc, node) => acc + node.hitCount, 0)
; | 129 this.totalHitCount = nodes.reduce((acc, node) => acc + node.hitCount, 0)
; |
130 var sampleTime = (this.profileEndTime - this.profileStartTime) / this.to
talHitCount; | 130 var sampleTime = (this.profileEndTime - this.profileStartTime) / this.to
talHitCount; |
131 var keepNatives = !!WebInspector.moduleSetting("showNativeFunctionsInJSP
rofile").get(); | 131 var keepNatives = !!WebInspector.moduleSetting("showNativeFunctionsInJSP
rofile").get(); |
132 var root = nodes[0]; | 132 var root = nodes[0]; |
133 /** @type {!Map<number, number>} */ | 133 /** @type {!Map<number, number>} */ |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 * @param {number} index | 350 * @param {number} index |
351 * @return {?WebInspector.CPUProfileNode} | 351 * @return {?WebInspector.CPUProfileNode} |
352 */ | 352 */ |
353 nodeByIndex: function(index) | 353 nodeByIndex: function(index) |
354 { | 354 { |
355 return this._idToNode.get(this.samples[index]) || null; | 355 return this._idToNode.get(this.samples[index]) || null; |
356 }, | 356 }, |
357 | 357 |
358 __proto__: WebInspector.ProfileTreeModel.prototype | 358 __proto__: WebInspector.ProfileTreeModel.prototype |
359 } | 359 } |
OLD | NEW |