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

Side by Side Diff: tools/profile_view.js

Issue 99181: Enhancing profiling data processing code with functionality needed for the Dev Tools Profiler. (Closed)
Patch Set: Created 11 years, 7 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
« no previous file with comments | « tools/profile.js ('k') | tools/splaytree.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 /** 70 /**
71 * Creates a Profile View object. It allows to perform sorting 71 * Creates a Profile View object. It allows to perform sorting
72 * and filtering actions on the profile. Profile View mimicks 72 * and filtering actions on the profile. Profile View mimicks
73 * the Profile object from WebKit's JSC profiler. 73 * the Profile object from WebKit's JSC profiler.
74 * 74 *
75 * @param {devtools.profiler.ProfileView.Node} head Head (root) node. 75 * @param {devtools.profiler.ProfileView.Node} head Head (root) node.
76 * @constructor 76 * @constructor
77 */ 77 */
78 devtools.profiler.ProfileView = function(head) { 78 devtools.profiler.ProfileView = function(head) {
79 this.head = head; 79 this.head = head;
Søren Thygesen Gjesse 2009/04/29 21:46:22 Trailing underscores?
Mikhail Naganov 2009/04/30 08:06:02 No. This is for compatibility with WebInspector or
80 this.title = '';
81 this.uid = '';
82 this.heavyProfile = null;
83 this.treeProfile = null;
84 this.flatProfile = null;
80 }; 85 };
81 86
82 87
88 /**
89 * Updates references between profiles. This is needed for WebKit
90 * ProfileView.
91 */
92 devtools.profiler.ProfileView.prototype.updateProfilesRefs = function() {
93 var profileNames = ["treeProfile", "heavyProfile", "flatProfile"];
94 for (var i = 0; i < profileNames.length; ++i) {
95 var destProfile = this[profileNames[i]];
96 for (var j = 0; j < profileNames.length; ++j) {
97 destProfile[profileNames[j]] = this[profileNames[j]];
Søren Thygesen Gjesse 2009/04/29 21:46:22 This means that each profile references itself as
Mikhail Naganov 2009/04/30 08:06:02 Well, it is needed in the version of WebInspector
98 }
99 }
100 };
101
102
83 /** 103 /**
84 * Sorts the profile view using the specified sort function. 104 * Sorts the profile view using the specified sort function.
85 * 105 *
86 * @param {function(devtools.profiler.ProfileView.Node, 106 * @param {function(devtools.profiler.ProfileView.Node,
87 * devtools.profiler.ProfileView.Node):number} sortFunc A sorting 107 * devtools.profiler.ProfileView.Node):number} sortFunc A sorting
88 * functions. Must comply with Array.sort sorting function requirements. 108 * functions. Must comply with Array.sort sorting function requirements.
89 */ 109 */
90 devtools.profiler.ProfileView.prototype.sort = function(sortFunc) { 110 devtools.profiler.ProfileView.prototype.sort = function(sortFunc) {
91 this.traverse(function (node) { 111 this.traverse(function (node) {
92 node.sortChildren(sortFunc); 112 node.sortChildren(sortFunc);
93 }); 113 });
94 }; 114 };
95 115
96 116
97 /** 117 /**
118 * Sorts the profile view by self time, ascending.
119 */
120 devtools.profiler.ProfileView.prototype.sortSelfTimeAscending = function() {
121 this.sort(function (node1, node2) {
122 return node1.selfTime - node2.selfTime; });
123 };
124
125
126 /**
127 * Sorts the profile view by self time, descending.
128 */
129 devtools.profiler.ProfileView.prototype.sortSelfTimeDescending = function() {
130 this.sort(function (node1, node2) {
131 return node2.selfTime - node1.selfTime; });
132 };
133
134
135 /**
136 * Sorts the profile view by total time, ascending.
137 */
138 devtools.profiler.ProfileView.prototype.sortTotalTimeAscending = function() {
139 this.sort(function (node1, node2) {
140 return node1.totalTime - node2.totalTime; });
141 };
142
143
144 /**
145 * Sorts the profile view by total time, descending.
146 */
147 devtools.profiler.ProfileView.prototype.sortTotalTimeDescending = function() {
148 this.sort(function (node1, node2) {
149 return node2.totalTime - node1.totalTime; });
150 };
151
152
153 /**
154 * String comparator compatible with Array.sort requirements.
155 *
156 * @param {string} s1 First string.
157 * @param {string} s2 Second string.
158 */
159 devtools.profiler.ProfileView.compareStrings = function(s1, s2) {
160 return s1 < s2 ? -1 : (s1 > s2 ? 1 : 0);
161 };
162
163
164 /**
165 * Sorts the profile view by function name, ascending.
166 */
167 devtools.profiler.ProfileView.prototype.sortFunctionNameAscending = function() {
168 this.sort(function (node1, node2) {
169 return devtools.profiler.ProfileView.compareStrings(
170 node1.functionName, node2.functionName); });
171 };
172
173
174 /**
175 * Sorts the profile view by function name, descending.
176 */
177 devtools.profiler.ProfileView.prototype.sortFunctionNameDescending = function() {
178 this.sort(function (node1, node2) {
179 return devtools.profiler.ProfileView.compareStrings(
180 node2.functionName, node1.functionName); });
181 };
182
183
184 /**
98 * Traverses profile view nodes in preorder. 185 * Traverses profile view nodes in preorder.
99 * 186 *
100 * @param {function(devtools.profiler.ProfileView.Node)} f Visitor function. 187 * @param {function(devtools.profiler.ProfileView.Node)} f Visitor function.
101 */ 188 */
102 devtools.profiler.ProfileView.prototype.traverse = function(f) { 189 devtools.profiler.ProfileView.prototype.traverse = function(f) {
103 var nodesToTraverse = new ConsArray(); 190 var nodesToTraverse = new ConsArray();
104 nodesToTraverse.concat([this.head]); 191 nodesToTraverse.concat([this.head]);
105 while (!nodesToTraverse.atEnd()) { 192 while (!nodesToTraverse.atEnd()) {
106 var node = nodesToTraverse.next(); 193 var node = nodesToTraverse.next();
107 f(node); 194 f(node);
(...skipping 10 matching lines...) Expand all
118 * @param {number} totalTime Amount of time that application spent in the 205 * @param {number} totalTime Amount of time that application spent in the
119 * corresponding function and its descendants (not that depending on 206 * corresponding function and its descendants (not that depending on
120 * profile they can be either callees or callers.) 207 * profile they can be either callees or callers.)
121 * @param {number} selfTime Amount of time that application spent in the 208 * @param {number} selfTime Amount of time that application spent in the
122 * corresponding function only. 209 * corresponding function only.
123 * @param {devtools.profiler.ProfileView.Node} head Profile view head. 210 * @param {devtools.profiler.ProfileView.Node} head Profile view head.
124 * @constructor 211 * @constructor
125 */ 212 */
126 devtools.profiler.ProfileView.Node = function( 213 devtools.profiler.ProfileView.Node = function(
127 internalFuncName, totalTime, selfTime, head) { 214 internalFuncName, totalTime, selfTime, head) {
215 this.callIdentifier = 0;
Søren Thygesen Gjesse 2009/04/29 21:46:22 Trailing underscores?
Mikhail Naganov 2009/04/30 08:06:02 No again. This is for compatibility with WebInspec
128 this.internalFuncName = internalFuncName; 216 this.internalFuncName = internalFuncName;
217 this.initFuncInfo();
129 this.totalTime = totalTime; 218 this.totalTime = totalTime;
130 this.selfTime = selfTime; 219 this.selfTime = selfTime;
131 this.head = head; 220 this.head = head;
132 this.parent = null; 221 this.parent = null;
133 this.children = []; 222 this.children = [];
223 this.visible = true;
134 }; 224 };
135 225
136 226
227 /**
228 * RegEx for stripping V8's prefixes of compiled functions.
229 */
230 devtools.profiler.ProfileView.Node.FUNC_NAME_STRIP_RE =
231 /^(?:LazyCompile|Function): (.*)$/;
Søren Thygesen Gjesse 2009/04/29 21:46:22 Maybe we should go and change the logged strings i
Mikhail Naganov 2009/04/30 08:06:02 I'm currently thinking on how to better transfer p
232
233
234 /**
235 * RegEx for extracting script source URL and line number.
236 */
237 devtools.profiler.ProfileView.Node.FUNC_NAME_PARSE_RE = /^([^ ]+) (.*):(\d+)$/;
238
239
240 /**
241 * RegEx for removing protocol name from URL.
242 */
243 devtools.profiler.ProfileView.Node.URL_PARSE_RE = /^(?:http:\/)?.*\/([^/]+)$/;
244
245
246 /**
247 * Inits 'functionName', 'url', and 'lineNumber' fields using 'internalFuncName'
248 * field.
249 */
250 devtools.profiler.ProfileView.Node.prototype.initFuncInfo = function() {
251 var nodeAlias = devtools.profiler.ProfileView.Node;
252 this.functionName = this.internalFuncName;
253
254 var strippedName = nodeAlias.FUNC_NAME_STRIP_RE.exec(this.functionName);
255 if (strippedName) {
256 this.functionName = strippedName[1];
257 }
258
259 var parsedName = nodeAlias.FUNC_NAME_PARSE_RE.exec(this.functionName);
260 if (parsedName) {
261 this.url = parsedName[2];
262 var parsedUrl = nodeAlias.URL_PARSE_RE.exec(this.url);
263 if (parsedUrl) {
264 this.url = parsedUrl[1];
265 }
266 this.functionName = parsedName[1];
267 this.lineNumber = parsedName[3];
268 } else {
269 this.url = '';
270 this.lineNumber = 0;
271 }
272 };
273
274
137 /** 275 /**
138 * Returns a share of the function's total time in application's total time. 276 * Returns a share of the function's total time in application's total time.
139 */ 277 */
140 devtools.profiler.ProfileView.Node.prototype.__defineGetter__( 278 devtools.profiler.ProfileView.Node.prototype.__defineGetter__(
141 'totalPercent', 279 'totalPercent',
142 function() { return this.totalTime / 280 function() { return this.totalTime /
143 (this.head ? this.head.totalTime : this.totalTime) * 100.0; }); 281 (this.head ? this.head.totalTime : this.totalTime) * 100.0; });
144 282
145 283
146 /** 284 /**
(...skipping 29 matching lines...) Expand all
176 * Sorts all the node's children recursively. 314 * Sorts all the node's children recursively.
177 * 315 *
178 * @param {function(devtools.profiler.ProfileView.Node, 316 * @param {function(devtools.profiler.ProfileView.Node,
179 * devtools.profiler.ProfileView.Node):number} sortFunc A sorting 317 * devtools.profiler.ProfileView.Node):number} sortFunc A sorting
180 * functions. Must comply with Array.sort sorting function requirements. 318 * functions. Must comply with Array.sort sorting function requirements.
181 */ 319 */
182 devtools.profiler.ProfileView.Node.prototype.sortChildren = function( 320 devtools.profiler.ProfileView.Node.prototype.sortChildren = function(
183 sortFunc) { 321 sortFunc) {
184 this.children.sort(sortFunc); 322 this.children.sort(sortFunc);
185 }; 323 };
OLDNEW
« no previous file with comments | « tools/profile.js ('k') | tools/splaytree.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698