contentTracing
Collect tracing data from Chromium to find performance bottlenecks and slow operations.从Chromium收集跟踪数据,以发现性能瓶颈和缓慢的操作。
Process: 进程:Main
This module does not include a web interface. 此模块不包括web界面。To view recorded traces, use trace viewer, available at 要查看记录的跟踪,请使用跟踪查看器,可在chrome中打开chrome://tracing
in Chrome.chrome://tracing
。
Note: You should not use this module until the 在发出应用程序模块的ready
event of the app module is emitted.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方法
The contentTracing
module has the following methods:contentTracing
模块具有以下方法:
contentTracing.getCategories()
Returns 返回Promise<string[]>
- resolves with an array of category groups once all child processes have acknowledged the 在所有子进程都确认getCategories
requestgetCategories
请求后,使用类别组数组进行解析
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.另请参阅内置跟踪类别列表。
NOTE:
Electron adds a non-default tracing category calledElectron添加了一个非默认的追踪类别,称为"electron"
."electron"
。This category can be used to capture Electron-specific tracing events.这一类别可用于捕捉特定于电子的追踪事件。
contentTracing.startRecording(options)
Returns 返回Promise<void>
- resolved once all child processes have acknowledged the 在所有子进程确认startRecording
request.startRecording
请求后解决。
Start recording on all processes.开始对所有进程进行录制。
Recording begins immediately locally and asynchronously on child processes as soon as they receive the EnableRecording request.一旦子进程收到EnableRecording
请求,就立即在本地和异步方式开始录制。
If a recording is already running, the promise will be immediately resolved, as only one trace operation can be in progress at a time.如果录制已经在运行,则promise将立即得到解决,因为一次只能进行一个跟踪操作。
contentTracing.stopRecording([resultFilePath])
resultFilePath
string (optional)
Returns 返回Promise<string>
- resolves with a path to a file that contains the traced data once all child processes have acknowledged the 在所有子进程都确认了stopRecording
requeststopRecording
请求后,使用包含跟踪数据的文件的路径进行解析
Stop recording on all processes.停止所有进程的录制。
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. 这有助于最大限度地减少跟踪的运行时开销,因为通过IPC发送跟踪数据可能是一项昂贵的操作。So, to end tracing, Chromium asynchronously asks all child processes to flush any pending trace data.因此,为了结束跟踪,Chromium异步地要求所有子进程刷新任何挂起的跟踪数据。
Trace data will be written into 跟踪数据将写入resultFilePath
. 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.resultFilePath
为空或未提供,跟踪数据将被写入一个临时文件,并在promise中返回该路径。
contentTracing.getTraceBufferUsage()
Returns 返回Promise<Object>
- Resolves with an object containing the 使用包含跟踪缓冲区最大使用率的value
and percentage
of trace buffer maximum usagevalue
和percentage
的对象进行解析
value
numberpercentage
number
Get the maximum usage across processes of trace buffer as a percentage of the full state.获取跟踪缓冲区在进程之间的最大使用量,作为已满状态的百分比。