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

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

Issue 2627103004: DevTools: make cpu throttling manager a control factory we can reuse. (Closed)
Patch Set: for landing Created 3 years, 11 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // Create models. 64 // Create models.
65 this._tracingModelBackingStorage = new Bindings.TempFileBackingStorage('trac ing'); 65 this._tracingModelBackingStorage = new Bindings.TempFileBackingStorage('trac ing');
66 this._tracingModel = new SDK.TracingModel(this._tracingModelBackingStorage); 66 this._tracingModel = new SDK.TracingModel(this._tracingModelBackingStorage);
67 this._model = new TimelineModel.TimelineModel(Timeline.TimelineUIUtils.visib leEventsFilter()); 67 this._model = new TimelineModel.TimelineModel(Timeline.TimelineUIUtils.visib leEventsFilter());
68 this._frameModel = 68 this._frameModel =
69 new TimelineModel.TimelineFrameModel(event => Timeline.TimelineUIUtils.e ventStyle(event).category.name); 69 new TimelineModel.TimelineFrameModel(event => Timeline.TimelineUIUtils.e ventStyle(event).category.name);
70 this._filmStripModel = new SDK.FilmStripModel(this._tracingModel); 70 this._filmStripModel = new SDK.FilmStripModel(this._tracingModel);
71 this._irModel = new TimelineModel.TimelineIRModel(); 71 this._irModel = new TimelineModel.TimelineIRModel();
72 /** @type {!Array<!{title: string, model: !SDK.TracingModel}>} */ 72 /** @type {!Array<!{title: string, model: !SDK.TracingModel}>} */
73 this._extensionTracingModels = []; 73 this._extensionTracingModels = [];
74 this._cpuThrottlingManager = new Timeline.CPUThrottlingManager(); 74 this._cpuThrottlingManager = new Components.CPUThrottlingManager();
75 75
76 /** @type {!Array<!Timeline.TimelineModeView>} */ 76 /** @type {!Array<!Timeline.TimelineModeView>} */
77 this._currentViews = []; 77 this._currentViews = [];
78 78
79 this._captureJSProfileSetting = Common.settings.createSetting('timelineEnabl eJSSampling', true); 79 this._captureJSProfileSetting = Common.settings.createSetting('timelineEnabl eJSSampling', true);
80 this._captureLayersAndPicturesSetting = Common.settings.createSetting('timel ineCaptureLayersAndPictures', false); 80 this._captureLayersAndPicturesSetting = Common.settings.createSetting('timel ineCaptureLayersAndPictures', false);
81 this._captureFilmStripSetting = Common.settings.createSetting('timelineCaptu reFilmStrip', false); 81 this._captureFilmStripSetting = Common.settings.createSetting('timelineCaptu reFilmStrip', false);
82 82
83 this._showScreenshotsSetting = Common.settings.createLocalSetting('timelineS howScreenshots', false); 83 this._showScreenshotsSetting = Common.settings.createLocalSetting('timelineS howScreenshots', false);
84 this._showScreenshotsSetting.addChangeListener(this._onModeChanged, this); 84 this._showScreenshotsSetting.addChangeListener(this._onModeChanged, this);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 this._stackView.element.classList.add('timeline-view-stack'); 122 this._stackView.element.classList.add('timeline-view-stack');
123 123
124 this._stackView.show(this._searchableView.element); 124 this._stackView.show(this._searchableView.element);
125 this._onModeChanged(); 125 this._onModeChanged();
126 126
127 this._configureThrottlingSetting = Common.settings.createSetting('timelineCo nfigureThrottling', false); 127 this._configureThrottlingSetting = Common.settings.createSetting('timelineCo nfigureThrottling', false);
128 this._configureThrottlingButton = new UI.ToolbarSettingToggle( 128 this._configureThrottlingButton = new UI.ToolbarSettingToggle(
129 this._configureThrottlingSetting, 'largeicon-settings-gear', Common.UISt ring('Configure throttling')); 129 this._configureThrottlingSetting, 'largeicon-settings-gear', Common.UISt ring('Configure throttling'));
130 SDK.multitargetNetworkManager.addEventListener( 130 SDK.multitargetNetworkManager.addEventListener(
131 SDK.MultitargetNetworkManager.Events.ConditionsChanged, this._updateConf igureThrottlingButton.bind(this)); 131 SDK.MultitargetNetworkManager.Events.ConditionsChanged, this._updateConf igureThrottlingButton.bind(this));
132 this._cpuThrottlingManager.addEventListener(
133 Components.CPUThrottlingManager.Events.RateChanged, this._updateConfigur eThrottlingButton.bind(this));
132 this._throttlingToolbar = new UI.Toolbar('', this.element); 134 this._throttlingToolbar = new UI.Toolbar('', this.element);
133 this._cpuThrottlingCombobox = new UI.ToolbarComboBox(this._onCPUThrottlingCh anged.bind(this));
134 this._throttlingToolbar.appendText(Common.UIString('Network:')); 135 this._throttlingToolbar.appendText(Common.UIString('Network:'));
135 this._throttlingToolbar.appendToolbarItem(this._createNetworkConditionsSelec t()); 136 this._throttlingToolbar.appendToolbarItem(this._createNetworkConditionsSelec t());
136 this._throttlingToolbar.appendSeparator(); 137 this._throttlingToolbar.appendSeparator();
137 this._throttlingToolbar.appendText(Common.UIString('CPU:')); 138 this._throttlingToolbar.appendText(Common.UIString('CPU:'));
138 this._throttlingToolbar.appendToolbarItem(this._cpuThrottlingCombobox); 139 this._throttlingToolbar.appendToolbarItem(this._cpuThrottlingManager.createC ontrol());
139 this._throttlingToolbar.appendToolbarItem(new UI.ToolbarSeparator(true)); 140 this._throttlingToolbar.appendToolbarItem(new UI.ToolbarSeparator(true));
140 var hideToolbarItem = new UI.ToolbarButton(Common.UIString('Close'), 'largei con-delete'); 141 var hideToolbarItem = new UI.ToolbarButton(Common.UIString('Close'), 'largei con-delete');
141 hideToolbarItem.addEventListener(UI.ToolbarButton.Events.Click, () => this._ configureThrottlingSetting.set(false)); 142 hideToolbarItem.addEventListener(UI.ToolbarButton.Events.Click, () => this._ configureThrottlingSetting.set(false));
142 this._throttlingToolbar.appendToolbarItem(hideToolbarItem); 143 this._throttlingToolbar.appendToolbarItem(hideToolbarItem);
143 this._populateCPUThrottingCombobox();
144 this._configureThrottlingSetting.addChangeListener(this._updateThrottlingToo lbarVisibility.bind(this)); 144 this._configureThrottlingSetting.addChangeListener(this._updateThrottlingToo lbarVisibility.bind(this));
145 this._updateThrottlingToolbarVisibility(); 145 this._updateThrottlingToolbarVisibility();
146 146
147 this._showLandingPage(); 147 this._showLandingPage();
148 this._recreateToolbarItems(); 148 this._recreateToolbarItems();
149 149
150 Extensions.extensionServer.addEventListener( 150 Extensions.extensionServer.addEventListener(
151 Extensions.ExtensionServer.Events.TraceProviderAdded, this._recreateTool barItems, this); 151 Extensions.ExtensionServer.Events.TraceProviderAdded, this._recreateTool barItems, this);
152 152
153 this._captureFilmStripSetting.addChangeListener(this._onModeChanged, this); 153 this._captureFilmStripSetting.addChangeListener(this._onModeChanged, this);
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 /** 362 /**
363 * @return {!UI.ToolbarComboBox} 363 * @return {!UI.ToolbarComboBox}
364 */ 364 */
365 _createNetworkConditionsSelect() { 365 _createNetworkConditionsSelect() {
366 var toolbarItem = new UI.ToolbarComboBox(null); 366 var toolbarItem = new UI.ToolbarComboBox(null);
367 toolbarItem.setMaxWidth(140); 367 toolbarItem.setMaxWidth(140);
368 Components.NetworkConditionsSelector.decorateSelect(toolbarItem.selectElemen t()); 368 Components.NetworkConditionsSelector.decorateSelect(toolbarItem.selectElemen t());
369 return toolbarItem; 369 return toolbarItem;
370 } 370 }
371 371
372 _populateCPUThrottingCombobox() {
373 var cpuThrottlingCombobox = this._cpuThrottlingCombobox;
374 cpuThrottlingCombobox.removeOptions();
375 var currentRate = this._cpuThrottlingManager.rate();
376 var hasSelection = false;
377 /**
378 * @param {string} name
379 * @param {number} value
380 */
381 function addOption(name, value) {
382 var option = cpuThrottlingCombobox.createOption(name, '', String(value));
383 cpuThrottlingCombobox.addOption(option);
384 if (hasSelection || (value && value !== currentRate))
385 return;
386 cpuThrottlingCombobox.select(option);
387 hasSelection = true;
388 }
389 addOption(Common.UIString('No throttling'), 1);
390 for (const rate of [2, 5, 10, 20])
391 addOption(Common.UIString('%d\xD7 slowdown', rate), rate);
392 }
393
394 _prepareToLoadTimeline() { 372 _prepareToLoadTimeline() {
395 console.assert(this._state === Timeline.TimelinePanel.State.Idle); 373 console.assert(this._state === Timeline.TimelinePanel.State.Idle);
396 this._setState(Timeline.TimelinePanel.State.Loading); 374 this._setState(Timeline.TimelinePanel.State.Loading);
397 } 375 }
398 376
399 _createFileSelector() { 377 _createFileSelector() {
400 if (this._fileSelectorElement) 378 if (this._fileSelectorElement)
401 this._fileSelectorElement.remove(); 379 this._fileSelectorElement.remove();
402 this._fileSelectorElement = UI.createFileSelectorElement(this._loadFromFile. bind(this)); 380 this._fileSelectorElement = UI.createFileSelectorElement(this._loadFromFile. bind(this));
403 this.element.appendChild(this._fileSelectorElement); 381 this.element.appendChild(this._fileSelectorElement);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 476
499 if (showMemory) { 477 if (showMemory) {
500 this._addModeView( 478 this._addModeView(
501 new Timeline.MemoryCountersGraph(this, this._model, [Timeline.Timeline UIUtils.visibleEventsFilter()])); 479 new Timeline.MemoryCountersGraph(this, this._model, [Timeline.Timeline UIUtils.visibleEventsFilter()]));
502 } 480 }
503 481
504 this.doResize(); 482 this.doResize();
505 this.select(null); 483 this.select(null);
506 } 484 }
507 485
508 _onCPUThrottlingChanged() {
509 if (!this._cpuThrottlingManager)
510 return;
511 var text = this._cpuThrottlingCombobox.selectedOption().value;
512 this._cpuThrottlingManager.setRate(Number.parseFloat(text));
513 this._updateConfigureThrottlingButton();
514 }
515
516 _updateThrottlingToolbarVisibility() { 486 _updateThrottlingToolbarVisibility() {
517 this._throttlingToolbar.element.classList.toggle('hidden', !this._configureT hrottlingSetting.get()); 487 this._throttlingToolbar.element.classList.toggle('hidden', !this._configureT hrottlingSetting.get());
518 } 488 }
519 489
520 _updateConfigureThrottlingButton() { 490 _updateConfigureThrottlingButton() {
521 var makeRed = this._cpuThrottlingManager.rate() !== 1 || SDK.multitargetNetw orkManager.isThrottling(); 491 var makeRed = this._cpuThrottlingManager.rate() !== 1 || SDK.multitargetNetw orkManager.isThrottling();
522 this._configureThrottlingButton.setDefaultWithRedColor(makeRed); 492 this._configureThrottlingButton.setDefaultWithRedColor(makeRed);
523 this._configureThrottlingButton.setToggleWithRedColor(makeRed); 493 this._configureThrottlingButton.setToggleWithRedColor(makeRed);
524 } 494 }
525 495
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 }; 1841 };
1872 1842
1873 Timeline.TimelinePanel._traceProviderSettingSymbol = Symbol('traceProviderSettin g'); 1843 Timeline.TimelinePanel._traceProviderSettingSymbol = Symbol('traceProviderSettin g');
1874 1844
1875 /** @enum {symbol} */ 1845 /** @enum {symbol} */
1876 Timeline.TimelineFilters.Events = { 1846 Timeline.TimelineFilters.Events = {
1877 FilterChanged: Symbol('FilterChanged') 1847 FilterChanged: Symbol('FilterChanged')
1878 }; 1848 };
1879 1849
1880 Timeline.TimelineFilters._durationFilterPresetsMs = [0, 1, 15]; 1850 Timeline.TimelineFilters._durationFilterPresetsMs = [0, 1, 15];
1881
1882 /**
1883 * @implements {SDK.TargetManager.Observer}
1884 * @unrestricted
1885 */
1886 Timeline.CPUThrottlingManager = class extends Common.Object {
1887 constructor() {
1888 super();
1889 this._targets = [];
1890 this._throttlingRate = 1.; // No throttling
1891 SDK.targetManager.observeTargets(this, SDK.Target.Capability.Browser);
1892 }
1893
1894 /**
1895 * @param {number} value
1896 */
1897 setRate(value) {
1898 this._throttlingRate = value;
1899 this._targets.forEach(target => target.emulationAgent().setCPUThrottlingRate (value));
1900 var icon = null;
1901 if (value !== 1) {
1902 icon = UI.Icon.create('smallicon-warning');
1903 icon.title = Common.UIString('CPU throttling is enabled');
1904 }
1905 UI.inspectorView.setPanelIcon('timeline', icon);
1906 }
1907
1908 /**
1909 * @return {number}
1910 */
1911 rate() {
1912 return this._throttlingRate;
1913 }
1914
1915 /**
1916 * @override
1917 * @param {!SDK.Target} target
1918 */
1919 targetAdded(target) {
1920 this._targets.push(target);
1921 target.emulationAgent().setCPUThrottlingRate(this._throttlingRate);
1922 }
1923
1924 /**
1925 * @override
1926 * @param {!SDK.Target} target
1927 */
1928 targetRemoved(target) {
1929 this._targets.remove(target, true);
1930 }
1931 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698