Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** @typedef {!{id: string, title: string, description: string, setting: string} } */ | |
| 6 Timeline.RecordingOption; | |
| 7 | |
| 8 /** @type {!Object<string, !Timeline.RecordingOption>} */ | |
| 9 Timeline.RecordingConfig = { | |
| 10 network: { | |
| 11 id: 'network', | |
| 12 title: Common.UIString('Network'), | |
| 13 description: Common.UIString('Capture network requests information.'), | |
| 14 setting: 'timelineCaptureNetwork' | |
| 15 }, | |
| 16 javascript: { | |
| 17 id: 'javascript', | |
| 18 title: Common.UIString('JavaScript'), | |
| 19 description: Common.UIString('Use sampling CPU profiler to collect JavaScrip t stacks.'), | |
| 20 setting: 'timelineEnableJSSampling' | |
| 21 }, | |
| 22 screenshots: { | |
| 23 id: 'screenshots', | |
| 24 title: Common.UIString('Screenshots'), | |
| 25 description: | |
| 26 Common.UIString('Collect page screenshots, so you can observe how the pa ge was evolving during recording.'), | |
| 27 setting: 'timelineCaptureFilmStrip' | |
| 28 }, | |
| 29 paints: { | |
| 30 id: 'paints', | |
| 31 title: Common.UIString('Paints'), | |
| 32 description: Common.UIString( | |
| 33 'Capture graphics layer positions and rasterization draw calls (moderate performance overhead).'), | |
| 34 setting: 'timelineCaptureLayersAndPictures' | |
| 35 }, | |
| 36 memory: { | |
| 37 id: 'memory', | |
| 38 title: Common.UIString('Memory'), | |
| 39 description: Common.UIString('Capture memory statistics on every timeline ev ent.'), | |
| 40 setting: 'timelineCaptureMemory' | |
| 41 } | |
| 42 }; | |
| 43 | |
| 44 Timeline.Perspective = class extends UI.VBox { | |
| 45 /** | |
| 46 * @param {string} description | |
| 47 * @param {!Array<!Timeline.RecordingOption>=} visibleOptions | |
| 48 * @param {!Array<!Timeline.RecordingOption>=} enabledOptions | |
| 49 */ | |
| 50 constructor(description, visibleOptions, enabledOptions) { | |
| 51 super(false); | |
| 52 enabledOptions = enabledOptions || []; | |
| 53 this._enabledOptions = new Set(enabledOptions.map(option => option.id)); | |
| 54 this._enabledOptions.add(Timeline.RecordingConfig.javascript.id); | |
| 55 this.contentElement.classList.add('timeline-perspective-body'); | |
| 56 this.contentElement.createChild('div', 'timeline-perspective-description').t extContent = description; | |
| 57 for (const config of visibleOptions || []) | |
| 58 this._createSettingCheckBox(this.contentElement, config); | |
| 59 const actionButton = this.contentElement.createChild('div').createChild('but ton', 'action-button'); | |
| 60 actionButton.textContent = Common.UIString('Start'); | |
| 61 actionButton.addEventListener('click', () => this.action()); | |
| 62 } | |
| 63 | |
| 64 /** | |
| 65 * @param {!Element} parent | |
| 66 * @param {!Timeline.RecordingOption} config | |
| 67 */ | |
| 68 _createSettingCheckBox(parent, config) { | |
|
caseq
2016/12/09 21:53:12
use UI.SettingsUI.createSettingCheckbox()?
alph
2016/12/09 22:01:20
thanks! done
| |
| 69 const value = this._enabledOptions.has(config.id); | |
| 70 const setting = Common.settings.createSetting(config.setting, value); | |
| 71 const div = parent.createChild('div', 'recording-setting'); | |
| 72 const label = div.createChild('label'); | |
| 73 const checkbox = label.createChild('input'); | |
| 74 setting.set(value); | |
| 75 setting.addChangeListener(settingChanged); | |
| 76 if (value) | |
| 77 checkbox.setAttribute('checked', 'checked'); | |
| 78 checkbox.setAttribute('type', 'checkbox'); | |
| 79 checkbox.setAttribute('id', config.id); | |
| 80 checkbox.addEventListener('change', event => setting.set(event.target.checke d)); | |
| 81 label.createTextChild(config.title); | |
| 82 if (config.description) | |
| 83 div.createChild('div', 'recording-setting-description').textContent = conf ig.description; | |
| 84 | |
| 85 /** @param {!Common.Event} event */ | |
| 86 function settingChanged(event) { | |
| 87 if (event.data) | |
| 88 checkbox.setAttribute('checked', 'checked'); | |
| 89 else | |
| 90 checkbox.removeAttribute('checked'); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 activate() { | |
| 95 for (let id in Timeline.RecordingConfig) { | |
| 96 const config = Timeline.RecordingConfig[id]; | |
| 97 const setting = Common.settings.createSetting(config.setting, false); | |
| 98 setting.set(this._enabledOptions.has(id)); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 action() { | |
| 103 UI.actionRegistry.action('timeline.toggle-recording').execute(); | |
| 104 } | |
| 105 }; | |
| 106 | |
| 107 Timeline.LoadPerspective = class extends Timeline.Perspective { | |
| 108 constructor() { | |
| 109 const config = Timeline.RecordingConfig; | |
| 110 super( | |
| 111 Common.UIString( | |
| 112 'Page Load mode allows you to analyze how fast the page is loaded an d becomes responsive.\n' + | |
| 113 'In this mode the page is automatically reloaded right after the rec ording has started. ' + | |
| 114 'During recording it collects information about network requests, sc reen state updates, ' + | |
| 115 'and CPU threads acivity along with JavaScript stacks. ' + | |
| 116 'Recording is stopped automatically shortly after the page processes load event.'), | |
| 117 [config.screenshots], [config.network, config.screenshots]); | |
| 118 } | |
| 119 | |
| 120 /** | |
| 121 * @override | |
| 122 */ | |
| 123 action() { | |
| 124 SDK.targetManager.reloadPage(); | |
| 125 } | |
| 126 }; | |
| 127 | |
| 128 Timeline.ResponsivenessPerspective = class extends Timeline.Perspective { | |
| 129 constructor() { | |
| 130 const config = Timeline.RecordingConfig; | |
| 131 super(Common.UIString('Record page responsiveness.'), [config.screenshots], [config.network]); | |
| 132 } | |
| 133 }; | |
| 134 | |
| 135 Timeline.JavaScriptPerspective = class extends Timeline.Perspective { | |
| 136 constructor() { | |
| 137 super(Common.UIString( | |
| 138 'This mode is useful when you want to focus on JavaScript performance. ' + | |
| 139 'All the options besides sampling CPU profiler are turned off to minimiz e measurement errors.')); | |
| 140 } | |
| 141 }; | |
| 142 | |
| 143 Timeline.CustomPerspective = class extends Timeline.Perspective { | |
| 144 constructor() { | |
| 145 const config = Timeline.RecordingConfig; | |
| 146 super( | |
| 147 Common.UIString('Advanced mode that allows you to customize recording op tions.'), | |
| 148 [config.network, config.javascript, config.screenshots, config.memory, c onfig.paints], | |
| 149 [config.network, config.screenshots]); | |
| 150 } | |
| 151 }; | |
| 152 | |
| 153 Timeline.LandingPage = class extends UI.VBox { | |
| 154 constructor() { | |
| 155 super(true); | |
| 156 this.registerRequiredCSS('timeline/timelineLandingPage.css'); | |
| 157 this.contentElement.classList.add('timeline-landing-page', 'fill'); | |
| 158 const perspectives = Timeline.TimelinePanel.Perspectives; | |
| 159 this._tabbedPane = new UI.TabbedPane(); | |
| 160 this._tabbedPane.registerRequiredCSS('timeline/timelineLandingPage.css'); | |
| 161 this._tabbedPane.registerRequiredCSS('ui_lazy/dialog.css'); | |
| 162 this._tabbedPane.contentElement.classList.add('timeline-landing-page'); | |
| 163 this._tabbedPane.setTabSlider(true); | |
| 164 this._tabbedPane.appendTab(perspectives.Load, Common.UIString('Page Load'), new Timeline.LoadPerspective()); | |
| 165 this._tabbedPane.appendTab( | |
| 166 perspectives.Responsiveness, Common.UIString('Responsiveness'), new Time line.ResponsivenessPerspective()); | |
| 167 this._tabbedPane.appendTab( | |
| 168 perspectives.JavaScript, Common.UIString('JavaScript'), new Timeline.Jav aScriptPerspective()); | |
| 169 this._tabbedPane.appendTab(perspectives.Custom, Common.UIString('Custom'), n ew Timeline.CustomPerspective()); | |
| 170 this._tabbedPane.addEventListener(UI.TabbedPane.Events.TabSelected, this._ta bSelected, this); | |
| 171 this._tabbedPane.show(this.contentElement); | |
| 172 this._perspectiveSetting = | |
| 173 Common.settings.createSetting('timelinePerspective', Timeline.TimelinePa nel.Perspectives.Load); | |
| 174 this._perspectiveSetting.addChangeListener(this._perspectiveChanged, this); | |
| 175 } | |
| 176 | |
| 177 /** | |
| 178 * @param {!Common.Event} event | |
| 179 */ | |
| 180 _tabSelected(event) { | |
| 181 if (this._perspectiveSetting.get() !== event.data.tabId) | |
| 182 this._perspectiveSetting.set(event.data.tabId); | |
| 183 } | |
| 184 | |
| 185 _perspectiveChanged() { | |
| 186 this._tabbedPane.selectTab(this._perspectiveSetting.get()); | |
| 187 const perspective = /** @type {!Timeline.Perspective} */ (this._tabbedPane.v isibleView); | |
| 188 perspective.activate(); | |
| 189 } | |
| 190 }; | |
| OLD | NEW |