我使用的是Google Chrome 63。
在Performance选项卡的DevTools中,有三种CPU限制设置:“无限制”,“4x减速”和“6x减速”。
是否可以设置自定义限制,例如“20x减速”?它可以通过在chrome.exe文件中设置一些标志或通过NodeJS库以编程方式设置。
我发现Lighthouse库有一种helpful function,但如果我将其中的默认值(CPU_THROTTLE_METRICS似乎等于4)从4更改为(例如)20并运行它,我怎么能确定它真的是20x减速?
另外,我想知道,如果有可能以类似的方式对GPU进行模拟“减速”吗?
谢谢你的建议。
Lighthouse使用Chrome DevTools协议中的Emulation.setCPUThrottlingRate
命令:
https://chromedevtools.github.io/devtools-protocol/tot/Emulation#method-setCPUThrottlingRate
您可以通过以下方式监控协议:
https://umaar.com/dev-tips/166-protocol-monitor/
当您使用性能面板中的限制设置进行切换时,您将在协议日志中看到此命令。
如果你问如何确定它是否有效 - 这是Chromium源代码的实现:
// 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.
希望这可以帮助。