contentTracing
从 Chromium 收集跟踪数据以查找性能瓶颈和慢操作。
进程:主进程
🌐 Process: Main
此模块不包含网页界面。要查看已记录的跟踪,请使用 跟踪查看器,可在 Chrome 的 chrome://tracing 访问。
🌐 This module does not include a web interface. To view recorded traces, use
trace viewer, available at chrome://tracing in Chrome.
在应用模块发出 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)
})()
})
方法
🌐 Methods
contentTracing 模块具有以下方法:
🌐 The contentTracing module has the following methods:
contentTracing.getCategories()
返回 Promise<string[]> - 一旦所有子进程确认了 getCategories 请求,就会返回一个类别组数组
🌐 Returns Promise<string[]> - resolves with an array of category groups once all child processes have acknowledged the getCategories request
获取一组类别组。随着新的代码路径被访问,类别组可能会发生变化。另请参阅内置跟踪类别列表。
🌐 Get a set of category groups. The category groups can change as new code paths are reached. See also the list of built-in tracing categories.
注意: Electron 添加了一个非默认的跟踪类别,称为
"electron"。 该类别可用于捕获 Electron 特定的跟踪事件。
contentTracing.startRecording(options)
返回 Promise<void> - 一旦所有子进程都已确认 startRecording 请求后解析。
🌐 Returns Promise<void> - resolved once all child processes have acknowledged the startRecording request.
开始记录所有进程。
🌐 Start recording on all processes.
一旦子进程收到启用录制请求,录制将立即在本地和异步开始。
🌐 Recording begins immediately locally and asynchronously on child processes as soon as they receive the EnableRecording request.
如果录音已经在进行中,该 Promise 将会立即被解决,因为一次只能进行一次跟踪操作。
🌐 If a recording is already running, the promise will be immediately resolved, as only one trace operation can be in progress at a time.
contentTracing.stopRecording([resultFilePath])
resultFilePath字符串(可选)
返回 Promise<string> - 在所有子进程确认 stopRecording 请求后,解析为包含追踪数据的文件路径
🌐 Returns Promise<string> - resolves with a path to a file that contains the traced data once all child processes have acknowledged the stopRecording request
停止所有进程的记录。
🌐 Stop recording on all processes.
子进程通常会缓存跟踪数据,并且很少刷新并将跟踪数据发送回主进程。这有助于最小化跟踪的运行时开销,因为通过 IPC 发送跟踪数据可能是一项昂贵的操作。因此,为了结束跟踪,Chromium 会异步要求所有子进程刷新任何未处理的跟踪数据。
🌐 Child processes typically cache trace data and only rarely flush and send trace data back to the main process. This helps to minimize the runtime overhead of tracing since sending trace data over IPC can be an expensive operation. So, to end tracing, Chromium asynchronously asks all child processes to flush any pending trace data.
追踪数据将写入 resultFilePath。如果 resultFilePath 为空或未提供,追踪数据将写入临时文件,并且路径将通过 promise 返回。
🌐 Trace data will be written into resultFilePath. If resultFilePath is empty
or not provided, trace data will be written to a temporary file, and the path
will be returned in the promise.
contentTracing.getTraceBufferUsage()
返回 Promise<Object> - 解析为包含跟踪缓冲区最大使用量的 value 和 percentage 的对象
🌐 Returns Promise<Object> - Resolves with an object containing the value and percentage of trace buffer maximum usage
value号码percentage号码
获取跨进程使用跟踪缓冲区的最大值,占完整状态的百分比。
🌐 Get the maximum usage across processes of trace buffer as a percentage of the full state.