是否可以在Chrome DevTools中设置自定义CPU限制?

Chr*_*s92 17 cpu throttling google-chrome-devtools

我使用的是Google Chrome 63.

Performance选项卡的DevTools中,有三种CPU限制设置:" 无限制","4x减速"和"6x减速".

是否可以设置自定义限制,例如"20x减速"?它可以通过在chrome.exe文件中设置一些标志或通过NodeJS库以编程方式设置.

我发现Lighthouse库有一些有用的功能,但如果我将其中的默认值(CPU_THROTTLE_METRICS似乎等于4)从4更改为(例如)20并运行它,我怎么能确定它真的是20x减速下?

另外,我想知道,如果有可能以类似的方式对GPU进行模拟"减速"吗?

谢谢你的建议.

she*_*erb 12

可以在 Chrome 中直接设置自定义值Emulation.setCPUThrottlingRate,但您需要在开发工具窗口上打开开发工具窗口才能以编程方式更改设置。

  1. 打开开发工具;确保它已分离(在其自己的窗口中打开)。
  2. 使用组合键 Cmd-Opt-i (Mac) 或 Ctrl-Shift-i (Windows) 在步骤 1 的开发工具窗口中再次打开开发工具。
  3. 在“控制台”选项卡中运行以下命令:
    let Main = await import('./devtools-frontend/front_end/entrypoints/main/main.js');
    await Main.MainImpl.sendOverProtocol('Emulation.setCPUThrottlingRate', {rate: 40});
    
    Run Code Online (Sandbox Code Playgroud)

此示例将使 Chrome 性能降低 40 倍。注意:传递 1 将rate关闭节流。

在创建第二个开发工具窗口后,步骤 1 中创建的第一个开发工具窗口可能会重新停靠。

  • 为我工作,但我必须导入 main.js 以避免错误: `let Main = wait import('./devtools-frontend/front_end/entrypoints/main/main.js'); 等待 Main.MainImpl.sendOverProtocol('Emulation.setCPUThrotdlingRate', {rate: 40});` (8认同)
  • 这给了我一个错误:“未捕获的类型错误:无法读取未定义的属性(读取'sendOverProtocol')” (2认同)

Max*_*Max 4

Lighthouse 使用Emulation.setCPUThrottlingRateChrome DevTools 协议中的命令:

https://chromedevtools.github.io/devtools-protocol/tot/Emulation#method-setCPUThrotdlingRate

您可以通过以下方式监控协议:

https://umaar.com/dev-tips/166-protocol-monitor/

当您使用性能面板中的限制设置进行切换时,您将在协议日志中看到此命令。

如果您询问如何确定它是否有效 - 以下是 Chromium 源代码的实现:

https://github.com/chromium/chromium/blob/master/third_party/blink/renderer/platform/scheduler/util/thread_cpu_throttler.h#L21

// This class is used to slow down the main thread for // inspector "cpu throttling". It does it by spawning an // additional thread which frequently interrupts main thread // and sleeps.

希望这可以帮助。

  • 节流器的最新链接:https://github.com/chromium/chromium/blob/master/third_party/blink/renderer/platform/scheduler/public/thread_cpu_throttler.h (2认同)