Chromium Code Reviews| OLD | NEW | 
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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)); | 135 this._cpuThrottlingCombobox = this._cpuThrottlingManager.createControl(); | 
| 
 
caseq
2017/01/12 02:59:12
nit: make it local
 
 | |
| 134 this._throttlingToolbar.appendText(Common.UIString('Network:')); | 136 this._throttlingToolbar.appendText(Common.UIString('Network:')); | 
| 135 this._throttlingToolbar.appendToolbarItem(this._createNetworkConditionsSelec t()); | 137 this._throttlingToolbar.appendToolbarItem(this._createNetworkConditionsSelec t()); | 
| 136 this._throttlingToolbar.appendSeparator(); | 138 this._throttlingToolbar.appendSeparator(); | 
| 137 this._throttlingToolbar.appendText(Common.UIString('CPU:')); | 139 this._throttlingToolbar.appendText(Common.UIString('CPU:')); | 
| 138 this._throttlingToolbar.appendToolbarItem(this._cpuThrottlingCombobox); | 140 this._throttlingToolbar.appendToolbarItem(this._cpuThrottlingCombobox); | 
| 139 this._throttlingToolbar.appendToolbarItem(new UI.ToolbarSeparator(true)); | 141 this._throttlingToolbar.appendToolbarItem(new UI.ToolbarSeparator(true)); | 
| 140 var hideToolbarItem = new UI.ToolbarButton(Common.UIString('Close'), 'largei con-delete'); | 142 var hideToolbarItem = new UI.ToolbarButton(Common.UIString('Close'), 'largei con-delete'); | 
| 141 hideToolbarItem.addEventListener(UI.ToolbarButton.Events.Click, () => this._ configureThrottlingSetting.set(false)); | 143 hideToolbarItem.addEventListener(UI.ToolbarButton.Events.Click, () => this._ configureThrottlingSetting.set(false)); | 
| 142 this._throttlingToolbar.appendToolbarItem(hideToolbarItem); | 144 this._throttlingToolbar.appendToolbarItem(hideToolbarItem); | 
| 143 this._populateCPUThrottingCombobox(); | |
| 144 this._configureThrottlingSetting.addChangeListener(this._updateThrottlingToo lbarVisibility.bind(this)); | 145 this._configureThrottlingSetting.addChangeListener(this._updateThrottlingToo lbarVisibility.bind(this)); | 
| 145 this._updateThrottlingToolbarVisibility(); | 146 this._updateThrottlingToolbarVisibility(); | 
| 146 | 147 | 
| 147 this._showLandingPage(); | 148 this._showLandingPage(); | 
| 148 this._recreateToolbarItems(); | 149 this._recreateToolbarItems(); | 
| 149 | 150 | 
| 150 Extensions.extensionServer.addEventListener( | 151 Extensions.extensionServer.addEventListener( | 
| 151 Extensions.ExtensionServer.Events.TraceProviderAdded, this._recreateTool barItems, this); | 152 Extensions.ExtensionServer.Events.TraceProviderAdded, this._recreateTool barItems, this); | 
| 152 | 153 | 
| 153 this._captureFilmStripSetting.addChangeListener(this._onModeChanged, this); | 154 this._captureFilmStripSetting.addChangeListener(this._onModeChanged, this); | 
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 /** | 363 /** | 
| 363 * @return {!UI.ToolbarComboBox} | 364 * @return {!UI.ToolbarComboBox} | 
| 364 */ | 365 */ | 
| 365 _createNetworkConditionsSelect() { | 366 _createNetworkConditionsSelect() { | 
| 366 var toolbarItem = new UI.ToolbarComboBox(null); | 367 var toolbarItem = new UI.ToolbarComboBox(null); | 
| 367 toolbarItem.setMaxWidth(140); | 368 toolbarItem.setMaxWidth(140); | 
| 368 Components.NetworkConditionsSelector.decorateSelect(toolbarItem.selectElemen t()); | 369 Components.NetworkConditionsSelector.decorateSelect(toolbarItem.selectElemen t()); | 
| 369 return toolbarItem; | 370 return toolbarItem; | 
| 370 } | 371 } | 
| 371 | 372 | 
| 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() { | 373 _prepareToLoadTimeline() { | 
| 395 console.assert(this._state === Timeline.TimelinePanel.State.Idle); | 374 console.assert(this._state === Timeline.TimelinePanel.State.Idle); | 
| 396 this._setState(Timeline.TimelinePanel.State.Loading); | 375 this._setState(Timeline.TimelinePanel.State.Loading); | 
| 397 } | 376 } | 
| 398 | 377 | 
| 399 _createFileSelector() { | 378 _createFileSelector() { | 
| 400 if (this._fileSelectorElement) | 379 if (this._fileSelectorElement) | 
| 401 this._fileSelectorElement.remove(); | 380 this._fileSelectorElement.remove(); | 
| 402 this._fileSelectorElement = UI.createFileSelectorElement(this._loadFromFile. bind(this)); | 381 this._fileSelectorElement = UI.createFileSelectorElement(this._loadFromFile. bind(this)); | 
| 403 this.element.appendChild(this._fileSelectorElement); | 382 this.element.appendChild(this._fileSelectorElement); | 
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 | 477 | 
| 499 if (showMemory) { | 478 if (showMemory) { | 
| 500 this._addModeView( | 479 this._addModeView( | 
| 501 new Timeline.MemoryCountersGraph(this, this._model, [Timeline.Timeline UIUtils.visibleEventsFilter()])); | 480 new Timeline.MemoryCountersGraph(this, this._model, [Timeline.Timeline UIUtils.visibleEventsFilter()])); | 
| 502 } | 481 } | 
| 503 | 482 | 
| 504 this.doResize(); | 483 this.doResize(); | 
| 505 this.select(null); | 484 this.select(null); | 
| 506 } | 485 } | 
| 507 | 486 | 
| 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() { | 487 _updateThrottlingToolbarVisibility() { | 
| 517 this._throttlingToolbar.element.classList.toggle('hidden', !this._configureT hrottlingSetting.get()); | 488 this._throttlingToolbar.element.classList.toggle('hidden', !this._configureT hrottlingSetting.get()); | 
| 518 } | 489 } | 
| 519 | 490 | 
| 520 _updateConfigureThrottlingButton() { | 491 _updateConfigureThrottlingButton() { | 
| 521 var makeRed = this._cpuThrottlingManager.rate() !== 1 || SDK.multitargetNetw orkManager.isThrottling(); | 492 var makeRed = this._cpuThrottlingManager.rate() !== 1 || SDK.multitargetNetw orkManager.isThrottling(); | 
| 522 this._configureThrottlingButton.setDefaultWithRedColor(makeRed); | 493 this._configureThrottlingButton.setDefaultWithRedColor(makeRed); | 
| 523 this._configureThrottlingButton.setToggleWithRedColor(makeRed); | 494 this._configureThrottlingButton.setToggleWithRedColor(makeRed); | 
| 524 } | 495 } | 
| 525 | 496 | 
| (...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1871 }; | 1842 }; | 
| 1872 | 1843 | 
| 1873 Timeline.TimelinePanel._traceProviderSettingSymbol = Symbol('traceProviderSettin g'); | 1844 Timeline.TimelinePanel._traceProviderSettingSymbol = Symbol('traceProviderSettin g'); | 
| 1874 | 1845 | 
| 1875 /** @enum {symbol} */ | 1846 /** @enum {symbol} */ | 
| 1876 Timeline.TimelineFilters.Events = { | 1847 Timeline.TimelineFilters.Events = { | 
| 1877 FilterChanged: Symbol('FilterChanged') | 1848 FilterChanged: Symbol('FilterChanged') | 
| 1878 }; | 1849 }; | 
| 1879 | 1850 | 
| 1880 Timeline.TimelineFilters._durationFilterPresetsMs = [0, 1, 15]; | 1851 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 }; | |
| OLD | NEW |