我需要有关Puppeteer page.metrics和queryObjects的更多信息 [英] I need more info about Puppeteer page.metrics and queryObjects
问题描述
我正在使用木偶来查找内存泄漏问题.我正在使用puppeteer的 page.metrics() API,但我在理解每个属性的含义时遇到了麻烦.我在指标中的所有值随着时间的推移而不断增加.这是预期的吗?还是这表明可能存在严重的内存泄漏?
I'm using Puppeteer to find a memory leak issue. I'm using puppeteer's page.metrics() API but I am having trouble understanding each properties meaning. All my values in the metrics keep increasing in value over time. Is this expected? Or is this an indication that there might be a serious memory leak?
随着应用程序的运行,其价值不断增长的属性是:
JSEventListeners, Nodes, LayoutCount, RecalcStyleCount, LayoutDuration, RecalcStyleDuration, ScriptDuration, TaskDuration, JSHeapUsedSize, JSHeapTotalSize
The properties which are growing in value as the app runs are:
JSEventListeners, Nodes, LayoutCount, RecalcStyleCount, LayoutDuration, RecalcStyleDuration, ScriptDuration, TaskDuration, JSHeapUsedSize, JSHeapTotalSize
关于这些东西的信息非常稀少,而且我一直看到人们引用page.queryObjects
作为查找内存泄漏的另一种方法.但是我找不到有关如何使用此API以及要查找的内容的任何信息.
The information about this stuff is very sparse and also I keep seeing people refer to page.queryObjects
as another way to find memory leaks. But I cannot find any information about how to use this API and what to look for.
推荐答案
根据
注意所有时间戳均为单调时间:从过去的任意点开始,以秒为单位单调增加时间. NOTE All timestamps are in monotonic time: monotonically increasing time in seconds since an arbitrary point in the past.
page.metrics()
Timestamp
< 数字>采集指标样本的时间戳.Documents
< 数字>页面中的文档数.Frames
< 数字>页面中的帧数.JSEventListeners
< 数字>页面中的事件数.Nodes
< 数字>页面中的DOM节点数.LayoutCount
< 数字>全部或部分页面布局的总数.RecalcStyleCount
< 数字>页面样式重新计算的总数.LayoutDuration
< 数字>所有页面布局的合并持续时间.RecalcStyleDuration
< 数字>所有页面样式重新计算的总持续时间.ScriptDuration
< 数字> JavaScript执行时间的总和.TaskDuration
< 数字>浏览器执行的所有任务的持续时间.JSHeapUsedSize
< 数字>使用的JavaScript堆大小.JSHeapTotalSize
< 数字> JavaScript堆总大小.
page.metrics()
Timestamp
<number> The timestamp when the metrics sample was taken.Documents
<number> Number of documents in the page.Frames
<number> Number of frames in the page.JSEventListeners
<number> Number of events in the page.Nodes
<number> Number of DOM nodes in the page.LayoutCount
<number> Total number of full or partial page layout.RecalcStyleCount
<number> Total number of page style recalculations.LayoutDuration
<number> Combined durations of all page layouts.RecalcStyleDuration
<number> Combined duration of all page style recalculations.ScriptDuration
<number> Combined duration of JavaScript execution.TaskDuration
<number> Combined duration of all tasks performed by the browser.JSHeapUsedSize
<number> Used JavaScript heap size.JSHeapTotalSize
<number> Total JavaScript heap size.
page.queryObjects(prototypeHandle)
page.queryObjects(prototypeHandle)
prototypeHandle
<JSHandle> A handle to the object prototype.- returns: <Promise<JSHandle>> Promise which resolves to a handle to an array of objects with this prototype.
该方法迭代JavaScript堆并查找具有给定原型的所有对象.
The method iterates the JavaScript heap and finds all the objects with the given prototype.
// Create a Map object
await page.evaluate(() => window.map = new Map());
// Get a handle to the Map object prototype
const mapPrototype = await page.evaluateHandle(() => Map.prototype);
// Query all map instances into an array
const mapInstances = await page.queryObjects(mapPrototype);
// Count amount of map objects in heap
const count = await page.evaluate(maps => maps.length, mapInstances);
await mapInstances.dispose();
await mapPrototype.dispose();
page.mainFrame().executionContext()的快捷方式.queryObjects(prototypeHandle).
page.metrics()
方法返回Chrome DevTools协议的结果 Performance.getMetrics
:
The page.metrics()
method returns the result of the Chrome DevTools Protocol Performance.getMetrics
:
Performance.getMetrics
检索运行时指标的当前值.
Performance.getMetrics
Retrieve current values of run-time metrics.
返回对象
-
metrics
数组指标- 运行时指标的当前值.
metrics
array Metric- Current values for run-time metrics.
另一方面,
page.queryObjects()
方法随附的Chrome DevTools协议为On the other hand, the Chrome DevTools Protocol that accompanies the
page.queryObjects()
method isRuntime.queryObjects
:Runtime.queryObjects
参数
Runtime.queryObjects
PARAMETERS
-
prototypeObjectId
RemoteObjectId 强>- 要为其返回对象的原型的标识符.
prototypeObjectId
RemoteObjectId- Identifier of the prototype to return objects for.
- 可用于发布结果的符号组名称.
返回对象
-
objects
RemoteObject 强>- 带有对象的数组.
objects
RemoteObject- Array with objects.
page.matrics()
的源代码和page.queryObjects()
可以在GitHub上找到.
The source code for
page.matrics()
andpage.queryObjects()
can be found on GitHub.这篇关于我需要有关Puppeteer page.metrics和queryObjects的更多信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!