-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RPP Observations] Add throttling settings to landing page
This CL adds 2 new components for selecting CPU and network throttling. They are meant to be web component versions of the toolbar throttling selectors. https://screenshot.googleplex.com/8QCkWHpu9sUT9Yj Bug: 311440438 Change-Id: Ie53a153acbdf3289b8386f42c7ded6adaac8ef0b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5673433 Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Reviewed-by: Nancy Li <nancyly@chromium.org> Commit-Queue: Adam Raine <asraine@chromium.org>
- Loading branch information
Adam Raine
authored and
Devtools-frontend LUCI CQ
committed
Jul 8, 2024
1 parent
1690af9
commit a2155b7
Showing
9 changed files
with
522 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
front_end/panels/timeline/components/CPUThrottlingSelector.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2024 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import * as SDK from '../../../core/sdk/sdk.js'; | ||
import {renderElementIntoDOM} from '../../../testing/DOMHelpers.js'; | ||
import {describeWithEnvironment} from '../../../testing/EnvironmentHelpers.js'; | ||
import type * as Menus from '../../../ui/components/menus/menus.js'; | ||
import * as Coordinator from '../../../ui/components/render_coordinator/render_coordinator.js'; | ||
|
||
import * as Components from './components.js'; | ||
|
||
describeWithEnvironment('CPUThrottlingSelector', () => { | ||
const coordinator = Coordinator.RenderCoordinator.RenderCoordinator.instance(); | ||
let cpuThrottlingManager: SDK.CPUThrottlingManager.CPUThrottlingManager; | ||
|
||
beforeEach(() => { | ||
cpuThrottlingManager = SDK.CPUThrottlingManager.CPUThrottlingManager.instance({forceNew: true}); | ||
}); | ||
|
||
it('renders all CPU throttling presets', async () => { | ||
const view = new Components.CPUThrottlingSelector.CPUThrottlingSelector(); | ||
renderElementIntoDOM(view); | ||
|
||
await coordinator.done(); | ||
|
||
const menuItems = view.shadowRoot!.querySelectorAll('devtools-menu-item') as NodeListOf<Menus.Menu.MenuItem>; | ||
|
||
assert.lengthOf(menuItems, 4); | ||
|
||
assert.strictEqual(menuItems[0].value, 1); | ||
assert.isTrue(menuItems[0].selected); | ||
assert.match(menuItems[0].innerText, /No throttling/); | ||
|
||
assert.strictEqual(menuItems[1].value, 4); | ||
assert.isFalse(menuItems[1].selected); | ||
assert.match(menuItems[1].innerText, /4× slowdown/); | ||
|
||
assert.strictEqual(menuItems[2].value, 6); | ||
assert.isFalse(menuItems[2].selected); | ||
assert.match(menuItems[2].innerText, /6× slowdown/); | ||
|
||
assert.strictEqual(menuItems[3].value, 20); | ||
assert.isFalse(menuItems[3].selected); | ||
assert.match(menuItems[3].innerText, /20× slowdown/); | ||
}); | ||
|
||
it('updates CPU throttling manager on change', async () => { | ||
const view = new Components.CPUThrottlingSelector.CPUThrottlingSelector(); | ||
renderElementIntoDOM(view); | ||
|
||
await coordinator.done(); | ||
|
||
const menuItems = view.shadowRoot!.querySelectorAll('devtools-menu-item') as NodeListOf<Menus.Menu.MenuItem>; | ||
|
||
assert.isTrue(menuItems[0].selected); | ||
assert.strictEqual(cpuThrottlingManager.cpuThrottlingRate(), 1); | ||
|
||
menuItems[1].click(); | ||
await coordinator.done(); | ||
|
||
assert.isTrue(menuItems[1].selected); | ||
assert.strictEqual(cpuThrottlingManager.cpuThrottlingRate(), 4); | ||
}); | ||
|
||
it('reacts to changes in CPU throttling manager', async () => { | ||
const view = new Components.CPUThrottlingSelector.CPUThrottlingSelector(); | ||
renderElementIntoDOM(view); | ||
|
||
await coordinator.done(); | ||
|
||
const menuItems = view.shadowRoot!.querySelectorAll('devtools-menu-item') as NodeListOf<Menus.Menu.MenuItem>; | ||
|
||
assert.isTrue(menuItems[0].selected); | ||
|
||
cpuThrottlingManager.setCPUThrottlingRate(6); | ||
await coordinator.done(); | ||
|
||
assert.isTrue(menuItems[2].selected); | ||
}); | ||
}); |
96 changes: 96 additions & 0 deletions
96
front_end/panels/timeline/components/CPUThrottlingSelector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2024 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import * as i18n from '../../../core/i18n/i18n.js'; | ||
import * as SDK from '../../../core/sdk/sdk.js'; | ||
import * as ComponentHelpers from '../../../ui/components/helpers/helpers.js'; | ||
import * as Menus from '../../../ui/components/menus/menus.js'; | ||
import * as LitHtml from '../../../ui/lit-html/lit-html.js'; | ||
import * as MobileThrottling from '../../mobile_throttling/mobile_throttling.js'; | ||
|
||
const {html} = LitHtml; | ||
|
||
const UIStrings = { | ||
/** | ||
* @description Text label for a menu item indicating that no throttling is applied. | ||
*/ | ||
noThrottling: 'No throttling', | ||
/** | ||
* @description Text label for a menu item indicating that a specific slowdown multiplier is applied. | ||
* @example {2} PH1 | ||
*/ | ||
dSlowdown: '{PH1}× slowdown', | ||
}; | ||
|
||
const str_ = i18n.i18n.registerUIStrings('panels/timeline/components/CPUThrottlingSelector.ts', UIStrings); | ||
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); | ||
|
||
export class CPUThrottlingSelector extends HTMLElement { | ||
static readonly litTagName = LitHtml.literal`devtools-cpu-throttling-selector`; | ||
readonly #shadow = this.attachShadow({mode: 'open'}); | ||
|
||
#currentRate: number; | ||
|
||
constructor() { | ||
super(); | ||
this.#currentRate = SDK.CPUThrottlingManager.CPUThrottlingManager.instance().cpuThrottlingRate(); | ||
this.#render(); | ||
} | ||
|
||
connectedCallback(): void { | ||
SDK.CPUThrottlingManager.CPUThrottlingManager.instance().addEventListener( | ||
SDK.CPUThrottlingManager.Events.RateChanged, this.#onRateChange, this); | ||
} | ||
|
||
disconnectedCallback(): void { | ||
SDK.CPUThrottlingManager.CPUThrottlingManager.instance().removeEventListener( | ||
SDK.CPUThrottlingManager.Events.RateChanged, this.#onRateChange, this); | ||
} | ||
|
||
#onRateChange(event: {data: SDK.CPUThrottlingManager.EventTypes['RateChanged']}): void { | ||
this.#currentRate = event.data; | ||
void ComponentHelpers.ScheduledRender.scheduleRender(this, this.#render); | ||
} | ||
|
||
#onMenuItemSelected(event: Menus.SelectMenu.SelectMenuItemSelectedEvent): void { | ||
MobileThrottling.ThrottlingManager.throttlingManager().setCPUThrottlingRate(Number(event.itemValue)); | ||
} | ||
|
||
#render = (): void => { | ||
// clang-format off | ||
const output = html` | ||
<${Menus.SelectMenu.SelectMenu.litTagName} | ||
@selectmenuselected=${this.#onMenuItemSelected} | ||
.showDivider=${true} | ||
.showArrow=${true} | ||
.sideButton=${false} | ||
.showSelectedItem=${true} | ||
.showConnector=${false} | ||
.buttonTitle=${this.#currentRate === 1 ? i18nString(UIStrings.noThrottling) : i18nString(UIStrings.dSlowdown, {PH1: this.#currentRate})} | ||
> | ||
${MobileThrottling.ThrottlingPresets.ThrottlingPresets.cpuThrottlingPresets.map(rate => { | ||
const title = rate === 1 ? i18nString(UIStrings.noThrottling) : i18nString(UIStrings.dSlowdown, {PH1: rate}); | ||
return LitHtml.html` | ||
<${Menus.Menu.MenuItem.litTagName} | ||
.value=${rate} | ||
.selected=${this.#currentRate === rate} | ||
> | ||
${title} | ||
</${Menus.Menu.MenuItem.litTagName}> | ||
`; | ||
})} | ||
</${Menus.SelectMenu.SelectMenu.litTagName}> | ||
`; | ||
// clang-format on | ||
LitHtml.render(output, this.#shadow, {host: this}); | ||
}; | ||
} | ||
|
||
customElements.define('devtools-cpu-throttling-selector', CPUThrottlingSelector); | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'devtools-cpu-throttling-selector': CPUThrottlingSelector; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.