跳转至

contentTracing

从 Chromium 收集跟踪数据,以查找性能瓶颈和缓慢的操作。

进程:主进程

此模块不包含 Web 界面。跟踪数据以 Perfetto protobuf 格式 记录;要查看它们,请在 Perfetto UI 中打开。

[!NOTE] 在 app 模块发出 ready 事件之前,你不应使用此模块。

const { app, contentTracing } = require('electron')

app.whenReady().then(async () => {
  await contentTracing.startRecording({
    included_categories: ['*']
  })
  console.log('Tracing started')
  await new Promise((resolve) => setTimeout(resolve, 5000))
  const path = await contentTracing.stopRecording()
  console.log('Tracing data recorded to ' + path)
})

方法

contentTracing 模块有以下方法:

contentTracing.getCategories()

返回 Promise<void> - 一旦所有子进程确认了 startRecording 请求,则解析完成。

开始在所有进程中记录。

记录会立即在本地开始,并会在子进程收到 EnableRecording 请求后异步开始。

如果已有正在进行的记录,则该 Promise 会立即解析,因为同一时间只能有一个跟踪操作在进行。如果在已有记录正在进行时设置了 options.nativeHeapProfiling,则该 Promise 会被拒绝,因为无法更改正在进行中的记录选项来启用堆分析。

contentTracing.stopRecording([resultFilePath])

返回 Promise<Object> - 解析为一个对象,其中包含跟踪缓冲区最大使用量的 value 和 percentage。

  • value number
  • percentage number

获取所有进程中跟踪缓冲区最大使用量占完整状态的百分比。

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 el/electron