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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/timeline/TimelinePanel.js

Issue 2223123003: DevTools: Add custom CPU throttling option to timeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor tweaks 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 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2012 Intel Inc. All rights reserved. 3 * Copyright (C) 2012 Intel Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 this._captureFilmStripSetting.addChangeListener(this._onModeChanged, thi s); 399 this._captureFilmStripSetting.addChangeListener(this._onModeChanged, thi s);
400 400
401 this._panelToolbar.appendSeparator(); 401 this._panelToolbar.appendSeparator();
402 var garbageCollectButton = new WebInspector.ToolbarButton(WebInspector.U IString("Collect garbage"), "garbage-collect-toolbar-item"); 402 var garbageCollectButton = new WebInspector.ToolbarButton(WebInspector.U IString("Collect garbage"), "garbage-collect-toolbar-item");
403 garbageCollectButton.addEventListener("click", this._garbageCollectButto nClicked, this); 403 garbageCollectButton.addEventListener("click", this._garbageCollectButto nClicked, this);
404 this._panelToolbar.appendToolbarItem(garbageCollectButton); 404 this._panelToolbar.appendToolbarItem(garbageCollectButton);
405 405
406 if (Runtime.experiments.isEnabled("cpuThrottling")) { 406 if (Runtime.experiments.isEnabled("cpuThrottling")) {
407 this._panelToolbar.appendSeparator(); 407 this._panelToolbar.appendSeparator();
408 this._cpuThrottlingCombobox = new WebInspector.ToolbarComboBox(this. _onCPUThrottlingChanged.bind(this)); 408 this._cpuThrottlingCombobox = new WebInspector.ToolbarComboBox(this. _onCPUThrottlingChanged.bind(this));
409 /**
410 * @param {string} name
411 * @param {number} value
412 * @this {WebInspector.TimelinePanel}
413 */
414 function addGroupingOption(name, value)
415 {
416 var option = this._cpuThrottlingCombobox.createOption(name, "", String(value));
417 this._cpuThrottlingCombobox.addOption(option);
418 if (value === this._cpuThrottlingManager.rate())
419 this._cpuThrottlingCombobox.select(option);
420 }
421 addGroupingOption.call(this, WebInspector.UIString("No CPU throttlin g"), 1);
422 addGroupingOption.call(this, WebInspector.UIString("High end device\ u2003(2x slowdown)"), 2);
423 addGroupingOption.call(this, WebInspector.UIString("Low end device\u 2003(5x slowdown)"), 5);
424 this._panelToolbar.appendToolbarItem(this._cpuThrottlingCombobox); 409 this._panelToolbar.appendToolbarItem(this._cpuThrottlingCombobox);
410 this._populateCPUThrottingCombobox();
425 } 411 }
426 }, 412 },
427 413
414 _populateCPUThrottingCombobox: function()
415 {
416 var cpuThrottlingCombobox = this._cpuThrottlingCombobox;
417 cpuThrottlingCombobox.removeOptions();
418 var currentRate = this._cpuThrottlingManager.rate();
419 var hasSelection = false;
420 /**
421 * @param {string} name
422 * @param {number} value
423 */
424 function addGroupingOption(name, value)
425 {
426 var option = cpuThrottlingCombobox.createOption(name, "", String(val ue));
427 cpuThrottlingCombobox.addOption(option);
428 if (hasSelection || (value && value !== currentRate))
429 return;
430 cpuThrottlingCombobox.select(option);
431 hasSelection = true;
432 }
433 var predefinedRates = new Map([
434 [1, WebInspector.UIString("No CPU throttling")],
435 [2, WebInspector.UIString("High end device (2\xD7 slowdown)")],
436 [5, WebInspector.UIString("Low end device (5\xD7 slowdown)")]
437 ]);
438 for (var rate of predefinedRates)
439 addGroupingOption(rate[1], rate[0]);
440 var customRate = predefinedRates.has(currentRate) ? "" : WebInspector.UI String(" (%d\xD7 slowdown)", currentRate);
441 addGroupingOption(WebInspector.UIString("Custom rate%s\u2026", customRat e), 0);
caseq 2016/08/10 18:28:47 addGroupingOption(predefinedRates.has(currentRate)
alph 2016/08/10 21:14:21 Done.
442 },
443
428 _prepareToLoadTimeline: function() 444 _prepareToLoadTimeline: function()
429 { 445 {
430 console.assert(this._state === WebInspector.TimelinePanel.State.Idle); 446 console.assert(this._state === WebInspector.TimelinePanel.State.Idle);
431 this._setState(WebInspector.TimelinePanel.State.Loading); 447 this._setState(WebInspector.TimelinePanel.State.Loading);
432 }, 448 },
433 449
434 _createFileSelector: function() 450 _createFileSelector: function()
435 { 451 {
436 if (this._fileSelectorElement) 452 if (this._fileSelectorElement)
437 this._fileSelectorElement.remove(); 453 this._fileSelectorElement.remove();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 _onNetworkChanged: function() 567 _onNetworkChanged: function()
552 { 568 {
553 if (this._flameChart) 569 if (this._flameChart)
554 this._flameChart.enableNetworkPane(this._captureNetworkSetting.get() , true); 570 this._flameChart.enableNetworkPane(this._captureNetworkSetting.get() , true);
555 }, 571 },
556 572
557 _onCPUThrottlingChanged: function() 573 _onCPUThrottlingChanged: function()
558 { 574 {
559 if (!this._cpuThrottlingManager) 575 if (!this._cpuThrottlingManager)
560 return; 576 return;
561 var value = Number.parseFloat(this._cpuThrottlingCombobox.selectedOption ().value); 577 var value = this._cpuThrottlingCombobox.selectedOption().value;
562 this._cpuThrottlingManager.setRate(value); 578 this._populateCPUThrottingCombobox();
579 if (value === "0")
caseq 2016/08/10 18:28:47 can we have some other check here? Either check fo
alph 2016/08/10 21:14:21 Done.
580 WebInspector.TimelinePanel.CustomCPUThrottlingRateDialog.show(setNew Rate.bind(this), this._cpuThrottlingCombobox.element);
581 else
582 setNewRate.call(this, value);
583
584 /**
585 * @param {string} text
586 * @this {WebInspector.TimelinePanel}
587 */
588 function setNewRate(text)
589 {
590 this._cpuThrottlingManager.setRate(Number.parseFloat(text));
591 this._populateCPUThrottingCombobox();
592 }
563 }, 593 },
564 594
565 /** 595 /**
566 * @param {boolean} enabled 596 * @param {boolean} enabled
567 */ 597 */
568 _setUIControlsEnabled: function(enabled) 598 _setUIControlsEnabled: function(enabled)
569 { 599 {
570 /** 600 /**
571 * @param {!WebInspector.ToolbarButton} toolbarButton 601 * @param {!WebInspector.ToolbarButton} toolbarButton
572 */ 602 */
(...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 * @override 2046 * @override
2017 * @param {!WebInspector.Target} target 2047 * @param {!WebInspector.Target} target
2018 */ 2048 */
2019 targetRemoved: function(target) 2049 targetRemoved: function(target)
2020 { 2050 {
2021 this._targets.remove(target, true); 2051 this._targets.remove(target, true);
2022 }, 2052 },
2023 2053
2024 __proto__: WebInspector.Object.prototype 2054 __proto__: WebInspector.Object.prototype
2025 } 2055 }
2056
2057 /**
2058 * @constructor
2059 * @extends {WebInspector.HBox}
2060 * @param {function(string)} callback
caseq 2016/08/10 18:28:47 use a promise perhaps?
alph 2016/08/10 21:14:21 Done.
2061 */
2062 WebInspector.TimelinePanel.CustomCPUThrottlingRateDialog = function(callback)
2063 {
2064 WebInspector.HBox.call(this, true);
2065 this.registerRequiredCSS("ui_lazy/dialog.css");
caseq 2016/08/10 18:28:47 can this be taken care of by Dialog?
alph 2016/08/10 21:14:21 Looks like a separate CL.
2066 this.contentElement.createChild("label").textContent = WebInspector.UIString ("CPU Slowdown Rate: ");
2067
2068 this._input = this.contentElement.createChild("input");
2069 this._input.setAttribute("type", "text");
2070 this._input.style.width = "64px";
2071 this._input.addEventListener("keydown", this._onKeyDown.bind(this), false);
2072
2073 var addButton = this.contentElement.createChild("button");
2074 addButton.textContent = WebInspector.UIString("Set");
2075 addButton.addEventListener("click", this._apply.bind(this), false);
2076
2077 this.setDefaultFocusedElement(this._input);
2078 this._callback = callback;
2079 this.contentElement.tabIndex = 0;
2080 }
2081
2082 /**
2083 * @param {function(string)} callback
2084 * @param {!Element=} anchor
2085 */
2086 WebInspector.TimelinePanel.CustomCPUThrottlingRateDialog.show = function(callbac k, anchor)
2087 {
2088 var dialog = new WebInspector.Dialog();
2089 var dialogContent = new WebInspector.TimelinePanel.CustomCPUThrottlingRateDi alog(done);
2090 dialogContent.show(dialog.element);
2091 dialog.setWrapsContent(true);
2092 if (anchor)
2093 dialog.setPosition(anchor.totalOffsetLeft() - 32, anchor.totalOffsetTop( ) + anchor.offsetHeight);
2094 dialog.show();
2095
2096 /**
2097 * @param {string} value
2098 */
2099 function done(value)
2100 {
2101 dialog.detach();
2102 callback(value);
2103 }
2104 }
2105
2106 WebInspector.TimelinePanel.CustomCPUThrottlingRateDialog.prototype = {
2107 _apply: function()
2108 {
2109 this._callback(this._input.value);
2110 },
2111
2112 /**
2113 * @param {!Event} event
2114 */
2115 _onKeyDown: function(event)
2116 {
2117 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Enter.code) {
2118 event.preventDefault();
2119 this._apply();
2120 }
2121 },
2122
2123 __proto__: WebInspector.HBox.prototype
2124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698