Chrome --enable-precise-memory-info 不起作用并且 performance.memory 仍然被分桶

Chrome --enable-precise-memory-info doesn't work and performance.memory is still bucketized

我必须以编程方式在 Windows 上测试 Chrome 中某些页面的内存使用情况。

这是我的 Chrome 版本(60.0.3112.113 - 官方版本 - 64 位)

以下 Chromium Command Line Switches Documentation 我 运行 Chrome 带有 --enable-precise-memory-info 标志:

然后在打开的 Chrome 实例中我尝试检查 window.performance.memory.usedJSHeapSize

的值

但看起来尽管有 --enable-precise-memory-info 标记,但此信息仍被分桶。

即使在 Chrome 任务管理器(Shift + Esc)中,我也看到每次执行以下命令后内存使用量增加了大约 1 Mb:

for(let i=0;i<100000;i++) {a.push('sdftgkljhghertyukytedtreut56ytirty7uikty' +i)}

我只发现了一个关于此的过时讨论issue,即使这个问题存在,我也希望能在网上找到更多讨论。

如果我做错了什么 - 我的错误是什么?

如果不再支持此标志,那么新的正确方法是什么?

谢谢!

我没有找到 --enable-precise-memory-info 不起作用的原因,因此我们会提供任何帮助。

同时我发现了另一种方法,我决定分享它。

我创建了一个 chrome 扩展并在其 background.js 中为 chrome.processes.onUpdatedWithMemory 添加了一个监听器。

它为我提供了有关 chrome 进程的更新信息,包括内存使用情况(privateMemory 字段),但是此解决方案有两个问题:

  1. 要使用 chrome.processes,我必须 运行 Dev channel only 上的扩展。
  2. 以这种方式收集内存使用信息会导致 extra CPU usage

在 Chrome 68+ 中,您现在可以每 50 毫秒对来自与网页 (eTLD+1) 相同来源的脚本进行一次采样。这意味着您可能不再需要 --enable-precise-memory-info

https://chromium.googlesource.com/chromium/src/+/7c7847f69de403f6c798dfccba10812039a60480

也许你需要在运行 /Applications/Google\ Chrome.app/Contents/MacOS/Google之前关闭所有打开的chrome window (cmd + q) \ Chrome --enable-precise-memory-info