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

Side by Side Diff: chrome_frame/tools/test/reference_build/chrome/resources/inspector/ProfileView.js

Issue 218019: Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 WebInspector.ProfileView = function(profile)
27 {
28 WebInspector.View.call(this);
29
30 this.element.addStyleClass("profile-view");
31
32 this.showSelfTimeAsPercent = true;
33 this.showTotalTimeAsPercent = true;
34 this.showAverageTimeAsPercent = true;
35
36 var columns = { "self": { title: WebInspector.UIString("Self"), width: "72px ", sort: "descending", sortable: true },
37 "total": { title: WebInspector.UIString("Total"), width: "72 px", sortable: true },
38 "average": { title: WebInspector.UIString("Average"), width: "72px", sortable: true },
39 "calls": { title: WebInspector.UIString("Calls"), width: "54 px", sortable: true },
40 "function": { title: WebInspector.UIString("Function"), disc losure: true, sortable: true } };
41
42 if (Preferences.samplingCPUProfiler) {
43 delete columns.average;
44 delete columns.calls;
45 }
46
47 this.dataGrid = new WebInspector.DataGrid(columns);
48 this.dataGrid.addEventListener("sorting changed", this._sortData, this);
49 this.dataGrid.element.addEventListener("mousedown", this._mouseDownInDataGri d.bind(this), true);
50 this.element.appendChild(this.dataGrid.element);
51
52 this.viewSelectElement = document.createElement("select");
53 this.viewSelectElement.className = "status-bar-item";
54 this.viewSelectElement.addEventListener("change", this._changeView.bind(this ), false);
55 this.view = "Heavy";
56
57 var heavyViewOption = document.createElement("option");
58 heavyViewOption.label = WebInspector.UIString("Heavy (Bottom Up)");
59 var treeViewOption = document.createElement("option");
60 treeViewOption.label = WebInspector.UIString("Tree (Top Down)");
61 this.viewSelectElement.appendChild(heavyViewOption);
62 this.viewSelectElement.appendChild(treeViewOption);
63
64 this.percentButton = new WebInspector.StatusBarButton("", "percent-time-stat us-bar-item");
65 this.percentButton.addEventListener("click", this._percentClicked.bind(this) , false);
66
67 this.focusButton = new WebInspector.StatusBarButton(WebInspector.UIString("F ocus selected function."), "focus-profile-node-status-bar-item");
68 this.focusButton.disabled = true;
69 this.focusButton.addEventListener("click", this._focusClicked.bind(this), fa lse);
70
71 this.excludeButton = new WebInspector.StatusBarButton(WebInspector.UIString( "Exclude selected function."), "exclude-profile-node-status-bar-item");
72 this.excludeButton.disabled = true;
73 this.excludeButton.addEventListener("click", this._excludeClicked.bind(this) , false);
74
75 this.resetButton = new WebInspector.StatusBarButton(WebInspector.UIString("R estore all functions."), "reset-profile-status-bar-item");
76 this.resetButton.visible = false;
77 this.resetButton.addEventListener("click", this._resetClicked.bind(this), fa lse);
78
79 this.profile = profile;
80
81 this.profileDataGridTree = this.bottomUpProfileDataGridTree;
82 this.profileDataGridTree.sort(WebInspector.ProfileDataGridTree.propertyCompa rator("selfTime", false));
83
84 this.refresh();
85
86 this._updatePercentButton();
87 }
88
89 WebInspector.ProfileView.prototype = {
90 get statusBarItems()
91 {
92 return [this.viewSelectElement, this.percentButton.element, this.focusBu tton.element, this.excludeButton.element, this.resetButton.element];
93 },
94
95 get profile()
96 {
97 return this._profile;
98 },
99
100 set profile(profile)
101 {
102 this._profile = profile;
103 },
104
105 get bottomUpProfileDataGridTree()
106 {
107 if (!this._bottomUpProfileDataGridTree)
108 this._bottomUpProfileDataGridTree = new WebInspector.BottomUpProfile DataGridTree(this, this.profile.head);
109 return this._bottomUpProfileDataGridTree;
110 },
111
112 get topDownProfileDataGridTree()
113 {
114 if (!this._topDownProfileDataGridTree)
115 this._topDownProfileDataGridTree = new WebInspector.TopDownProfileDa taGridTree(this, this.profile.head);
116 return this._topDownProfileDataGridTree;
117 },
118
119 get currentTree()
120 {
121 return this._currentTree;
122 },
123
124 set currentTree(tree)
125 {
126 this._currentTree = tree;
127 this.refresh();
128 },
129
130 get topDownTree()
131 {
132 if (!this._topDownTree) {
133 this._topDownTree = WebInspector.TopDownTreeFactory.create(this.prof ile.head);
134 this._sortProfile(this._topDownTree);
135 }
136
137 return this._topDownTree;
138 },
139
140 get bottomUpTree()
141 {
142 if (!this._bottomUpTree) {
143 this._bottomUpTree = WebInspector.BottomUpTreeFactory.create(this.pr ofile.head);
144 this._sortProfile(this._bottomUpTree);
145 }
146
147 return this._bottomUpTree;
148 },
149
150 show: function(parentElement)
151 {
152 WebInspector.View.prototype.show.call(this, parentElement);
153 this.dataGrid.updateWidths();
154 },
155
156 hide: function()
157 {
158 WebInspector.View.prototype.hide.call(this);
159 this._currentSearchResultIndex = -1;
160 },
161
162 resize: function()
163 {
164 if (this.dataGrid)
165 this.dataGrid.updateWidths();
166 },
167
168 refresh: function()
169 {
170 var selectedProfileNode = this.dataGrid.selectedNode ? this.dataGrid.sel ectedNode.profileNode : null;
171
172 this.dataGrid.removeChildren();
173
174 var children = this.profileDataGridTree.children;
175 var count = children.length;
176
177 for (var index = 0; index < count; ++index)
178 this.dataGrid.appendChild(children[index]);
179
180 if (selectedProfileNode)
181 selectedProfileNode.selected = true;
182 },
183
184 refreshVisibleData: function()
185 {
186 var child = this.dataGrid.children[0];
187 while (child) {
188 child.refresh();
189 child = child.traverseNextNode(false, null, true);
190 }
191 },
192
193 refreshShowAsPercents: function()
194 {
195 this._updatePercentButton();
196 this.refreshVisibleData();
197 },
198
199 searchCanceled: function()
200 {
201 if (this._searchResults) {
202 for (var i = 0; i < this._searchResults.length; ++i) {
203 var profileNode = this._searchResults[i].profileNode;
204
205 delete profileNode._searchMatchedSelfColumn;
206 delete profileNode._searchMatchedTotalColumn;
207 delete profileNode._searchMatchedCallsColumn;
208 delete profileNode._searchMatchedFunctionColumn;
209
210 profileNode.refresh();
211 }
212 }
213
214 delete this._searchFinishedCallback;
215 this._currentSearchResultIndex = -1;
216 this._searchResults = [];
217 },
218
219 performSearch: function(query, finishedCallback)
220 {
221 // Call searchCanceled since it will reset everything we need before doi ng a new search.
222 this.searchCanceled();
223
224 query = query.trimWhitespace();
225
226 if (!query.length)
227 return;
228
229 this._searchFinishedCallback = finishedCallback;
230
231 var greaterThan = (query.indexOf(">") === 0);
232 var lessThan = (query.indexOf("<") === 0);
233 var equalTo = (query.indexOf("=") === 0 || ((greaterThan || lessThan) && query.indexOf("=") === 1));
234 var percentUnits = (query.lastIndexOf("%") === (query.length - 1));
235 var millisecondsUnits = (query.length > 2 && query.lastIndexOf("ms") === (query.length - 2));
236 var secondsUnits = (!millisecondsUnits && query.lastIndexOf("s") === (qu ery.length - 1));
237
238 var queryNumber = parseFloat(query);
239 if (greaterThan || lessThan || equalTo) {
240 if (equalTo && (greaterThan || lessThan))
241 queryNumber = parseFloat(query.substring(2));
242 else
243 queryNumber = parseFloat(query.substring(1));
244 }
245
246 var queryNumberMilliseconds = (secondsUnits ? (queryNumber * 1000) : que ryNumber);
247
248 // Make equalTo implicitly true if it wasn't specified there is no other operator.
249 if (!isNaN(queryNumber) && !(greaterThan || lessThan))
250 equalTo = true;
251
252 function matchesQuery(/*ProfileDataGridNode*/ profileDataGridNode)
253 {
254 delete profileDataGridNode._searchMatchedSelfColumn;
255 delete profileDataGridNode._searchMatchedTotalColumn;
256 delete profileDataGridNode._searchMatchedAverageColumn;
257 delete profileDataGridNode._searchMatchedCallsColumn;
258 delete profileDataGridNode._searchMatchedFunctionColumn;
259
260 if (percentUnits) {
261 if (lessThan) {
262 if (profileDataGridNode.selfPercent < queryNumber)
263 profileDataGridNode._searchMatchedSelfColumn = true;
264 if (profileDataGridNode.totalPercent < queryNumber)
265 profileDataGridNode._searchMatchedTotalColumn = true;
266 if (profileDataGridNode.averagePercent < queryNumberMillisec onds)
267 profileDataGridNode._searchMatchedAverageColumn = true;
268 } else if (greaterThan) {
269 if (profileDataGridNode.selfPercent > queryNumber)
270 profileDataGridNode._searchMatchedSelfColumn = true;
271 if (profileDataGridNode.totalPercent > queryNumber)
272 profileDataGridNode._searchMatchedTotalColumn = true;
273 if (profileDataGridNode.averagePercent < queryNumberMillisec onds)
274 profileDataGridNode._searchMatchedAverageColumn = true;
275 }
276
277 if (equalTo) {
278 if (profileDataGridNode.selfPercent == queryNumber)
279 profileDataGridNode._searchMatchedSelfColumn = true;
280 if (profileDataGridNode.totalPercent == queryNumber)
281 profileDataGridNode._searchMatchedTotalColumn = true;
282 if (profileDataGridNode.averagePercent < queryNumberMillisec onds)
283 profileDataGridNode._searchMatchedAverageColumn = true;
284 }
285 } else if (millisecondsUnits || secondsUnits) {
286 if (lessThan) {
287 if (profileDataGridNode.selfTime < queryNumberMilliseconds)
288 profileDataGridNode._searchMatchedSelfColumn = true;
289 if (profileDataGridNode.totalTime < queryNumberMilliseconds)
290 profileDataGridNode._searchMatchedTotalColumn = true;
291 if (profileDataGridNode.averageTime < queryNumberMillisecond s)
292 profileDataGridNode._searchMatchedAverageColumn = true;
293 } else if (greaterThan) {
294 if (profileDataGridNode.selfTime > queryNumberMilliseconds)
295 profileDataGridNode._searchMatchedSelfColumn = true;
296 if (profileDataGridNode.totalTime > queryNumberMilliseconds)
297 profileDataGridNode._searchMatchedTotalColumn = true;
298 if (profileDataGridNode.averageTime > queryNumberMillisecond s)
299 profileDataGridNode._searchMatchedAverageColumn = true;
300 }
301
302 if (equalTo) {
303 if (profileDataGridNode.selfTime == queryNumberMilliseconds)
304 profileDataGridNode._searchMatchedSelfColumn = true;
305 if (profileDataGridNode.totalTime == queryNumberMilliseconds )
306 profileDataGridNode._searchMatchedTotalColumn = true;
307 if (profileDataGridNode.averageTime == queryNumberMillisecon ds)
308 profileDataGridNode._searchMatchedAverageColumn = true;
309 }
310 } else {
311 if (equalTo && profileDataGridNode.numberOfCalls == queryNumber)
312 profileDataGridNode._searchMatchedCallsColumn = true;
313 if (greaterThan && profileDataGridNode.numberOfCalls > queryNumb er)
314 profileDataGridNode._searchMatchedCallsColumn = true;
315 if (lessThan && profileDataGridNode.numberOfCalls < queryNumber)
316 profileDataGridNode._searchMatchedCallsColumn = true;
317 }
318
319 if (profileDataGridNode.functionName.hasSubstring(query, true) || pr ofileDataGridNode.url.hasSubstring(query, true))
320 profileDataGridNode._searchMatchedFunctionColumn = true;
321
322 if (profileDataGridNode._searchMatchedSelfColumn ||
323 profileDataGridNode._searchMatchedTotalColumn ||
324 profileDataGridNode._searchMatchedAverageColumn ||
325 profileDataGridNode._searchMatchedCallsColumn ||
326 profileDataGridNode._searchMatchedFunctionColumn)
327 {
328 profileDataGridNode.refresh();
329 return true;
330 }
331
332 return false;
333 }
334
335 var current = this.profileDataGridTree.children[0];
336
337 while (current) {
338 if (matchesQuery(current)) {
339 this._searchResults.push({ profileNode: current });
340 }
341
342 current = current.traverseNextNode(false, null, false);
343 }
344
345 finishedCallback(this, this._searchResults.length);
346 },
347
348 jumpToFirstSearchResult: function()
349 {
350 if (!this._searchResults || !this._searchResults.length)
351 return;
352 this._currentSearchResultIndex = 0;
353 this._jumpToSearchResult(this._currentSearchResultIndex);
354 },
355
356 jumpToLastSearchResult: function()
357 {
358 if (!this._searchResults || !this._searchResults.length)
359 return;
360 this._currentSearchResultIndex = (this._searchResults.length - 1);
361 this._jumpToSearchResult(this._currentSearchResultIndex);
362 },
363
364 jumpToNextSearchResult: function()
365 {
366 if (!this._searchResults || !this._searchResults.length)
367 return;
368 if (++this._currentSearchResultIndex >= this._searchResults.length)
369 this._currentSearchResultIndex = 0;
370 this._jumpToSearchResult(this._currentSearchResultIndex);
371 },
372
373 jumpToPreviousSearchResult: function()
374 {
375 if (!this._searchResults || !this._searchResults.length)
376 return;
377 if (--this._currentSearchResultIndex < 0)
378 this._currentSearchResultIndex = (this._searchResults.length - 1);
379 this._jumpToSearchResult(this._currentSearchResultIndex);
380 },
381
382 showingFirstSearchResult: function()
383 {
384 return (this._currentSearchResultIndex === 0);
385 },
386
387 showingLastSearchResult: function()
388 {
389 return (this._searchResults && this._currentSearchResultIndex === (this. _searchResults.length - 1));
390 },
391
392 _jumpToSearchResult: function(index)
393 {
394 var searchResult = this._searchResults[index];
395 if (!searchResult)
396 return;
397
398 var profileNode = searchResult.profileNode;
399 profileNode.reveal();
400 profileNode.select();
401 },
402
403 _changeView: function(event)
404 {
405 if (!event || !this.profile)
406 return;
407
408 if (event.target.selectedIndex == 1 && this.view == "Heavy") {
409 this.profileDataGridTree = this.topDownProfileDataGridTree;
410 this._sortProfile();
411 this.view = "Tree";
412 } else if (event.target.selectedIndex == 0 && this.view == "Tree") {
413 this.profileDataGridTree = this.bottomUpProfileDataGridTree;
414 this._sortProfile();
415 this.view = "Heavy";
416 }
417
418 if (!this.currentQuery || !this._searchFinishedCallback || !this._search Results)
419 return;
420
421 // The current search needs to be performed again. First negate out prev ious match
422 // count by calling the search finished callback with a negative number of matches.
423 // Then perform the search again the with same query and callback.
424 this._searchFinishedCallback(this, -this._searchResults.length);
425 this.performSearch(this.currentQuery, this._searchFinishedCallback);
426 },
427
428 _percentClicked: function(event)
429 {
430 var currentState = this.showSelfTimeAsPercent && this.showTotalTimeAsPer cent && this.showAverageTimeAsPercent;
431 this.showSelfTimeAsPercent = !currentState;
432 this.showTotalTimeAsPercent = !currentState;
433 this.showAverageTimeAsPercent = !currentState;
434 this.refreshShowAsPercents();
435 },
436
437 _updatePercentButton: function()
438 {
439 if (this.showSelfTimeAsPercent && this.showTotalTimeAsPercent && this.sh owAverageTimeAsPercent) {
440 this.percentButton.title = WebInspector.UIString("Show absolute tota l and self times.");
441 this.percentButton.toggled = true;
442 } else {
443 this.percentButton.title = WebInspector.UIString("Show total and sel f times as percentages.");
444 this.percentButton.toggled = false;
445 }
446 },
447
448 _focusClicked: function(event)
449 {
450 if (!this.dataGrid.selectedNode)
451 return;
452
453 this.resetButton.visible = true;
454 this.profileDataGridTree.focus(this.dataGrid.selectedNode);
455 this.refresh();
456 this.refreshVisibleData();
457 },
458
459 _excludeClicked: function(event)
460 {
461 var selectedNode = this.dataGrid.selectedNode
462
463 if (!selectedNode)
464 return;
465
466 selectedNode.deselect();
467
468 this.resetButton.visible = true;
469 this.profileDataGridTree.exclude(selectedNode);
470 this.refresh();
471 this.refreshVisibleData();
472 },
473
474 _resetClicked: function(event)
475 {
476 this.resetButton.visible = false;
477 this.profileDataGridTree.restore();
478 this.refresh();
479 this.refreshVisibleData();
480 },
481
482 _dataGridNodeSelected: function(node)
483 {
484 this.focusButton.disabled = false;
485 this.excludeButton.disabled = false;
486 },
487
488 _dataGridNodeDeselected: function(node)
489 {
490 this.focusButton.disabled = true;
491 this.excludeButton.disabled = true;
492 },
493
494 _sortData: function(event)
495 {
496 this._sortProfile(this.profile);
497 },
498
499 _sortProfile: function()
500 {
501 var sortAscending = this.dataGrid.sortOrder === "ascending";
502 var sortColumnIdentifier = this.dataGrid.sortColumnIdentifier;
503 var sortProperty = {
504 "average": "averageTime",
505 "self": "selfTime",
506 "total": "totalTime",
507 "calls": "numberOfCalls",
508 "function": "functionName"
509 }[sortColumnIdentifier];
510
511 this.profileDataGridTree.sort(WebInspector.ProfileDataGridTree.propertyC omparator(sortProperty, sortAscending));
512
513 this.refresh();
514 },
515
516 _mouseDownInDataGrid: function(event)
517 {
518 if (event.detail < 2)
519 return;
520
521 var cell = event.target.enclosingNodeOrSelfWithNodeName("td");
522 if (!cell || (!cell.hasStyleClass("total-column") && !cell.hasStyleClass ("self-column") && !cell.hasStyleClass("average-column")))
523 return;
524
525 if (cell.hasStyleClass("total-column"))
526 this.showTotalTimeAsPercent = !this.showTotalTimeAsPercent;
527 else if (cell.hasStyleClass("self-column"))
528 this.showSelfTimeAsPercent = !this.showSelfTimeAsPercent;
529 else if (cell.hasStyleClass("average-column"))
530 this.showAverageTimeAsPercent = !this.showAverageTimeAsPercent;
531
532 this.refreshShowAsPercents();
533
534 event.preventDefault();
535 event.stopPropagation();
536 }
537 }
538
539 WebInspector.ProfileView.prototype.__proto__ = WebInspector.View.prototype;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698