我需要有关Puppeteer page.metrics和queryObjects的更多信息 [英] I need more info about Puppeteer page.metrics and queryObjects

查看:131
本文介绍了我需要有关Puppeteer page.metrics和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.

推荐答案

根据

page.metrics()

  • 返回:< 承诺 < 对象 >>包含指标的对象作为键/值对.
    • Timestamp< 数字>采集指标样本的时间戳.
    • Documents< 数字>页面中的文档数.
    • Frames< 数字>页面中的帧数.
    • JSEventListeners< 数字>页面中的事件数.
    • Nodes< 数字>页面中的DOM节点数.
    • LayoutCount< 数字>全部或部分页面布局的总数.
    • RecalcStyleCount< 数字>页面样式重新计算的总数.
    • LayoutDuration< 数字>所有页面布局的合并持续时间.
    • RecalcStyleDuration< 数字>所有页面样式重新计算的总持续时间.
    • ScriptDuration< 数字> JavaScript执行时间的总和.
    • TaskDuration< 数字>浏览器执行的所有任务的持续时间.
    • JSHeapUsedSize< 数字>使用的JavaScript堆大小.
    • JSHeapTotalSize< 数字> JavaScript堆总大小.
    • page.metrics()

      • returns: <Promise<Object>> Object containing metrics as key/value pairs.
        • 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.

      注意所有时间戳均为单调时间:从过去的任意点开始,以秒为单位单调增加时间.

      NOTE All timestamps are in monotonic time: monotonically increasing time in seconds since an arbitrary point in the past.

      page.queryObjects(prototypeHandle)

      • prototypeHandle< JSHandle >对象原型的句柄.
      • 返回:< 承诺 < JSHandle >>解决的承诺这个原型处理一个对象数组的句柄.
      • 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.

          返回对象

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆