• contentTracing
    • 方法
      • contentTracing.getCategories(callback)
      • contentTracing.getCategories()
      • contentTracing.startRecording(options, callback)
      • contentTracing.startRecording(options)
      • contentTracing.stopRecording(resultFilePath, callback)
      • contentTracing.stopRecording(resultFilePath)
      • contentTracing.startMonitoring(options, callback)
      • contentTracing.getTraceBufferUsage()

    contentTracing

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

    进程:主进程

    该模块不包含网页接口,所以你需要在Chrome浏览器打开chrome://tracing/页面,然后加载生成的文件来查看结果。

    注意:在应用程序模块的 ready 事件触发之前,您不应该使用此模块。

    1. const { app, contentTracing } = require('electron')
    2. app.on('ready', () => {
    3. const options = {
    4. categoryFilter: '*',
    5. traceOptions: 'record-until-full,enable-sampling'
    6. }
    7. contentTracing.startRecording(options, () => {
    8. console.log('Tracing started')
    9. setTimeout(() => {
    10. contentTracing.stopRecording('', (path) => {
    11. console.log('Tracing data recorded to ' + path)
    12. })
    13. }, 5000)
    14. })
    15. })

    方法

    contentTracing模块包含以下方法:

    contentTracing.getCategories(callback)

    • callback Function - 回调函数

      • categories String[]Get a set of category groups. The category groups can change as new code paths are reached.

    Once all child processes have acknowledged the getCategories request the callback is invoked with an array of category groups.

    即将弃用

    contentTracing.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.

    contentTracing.startRecording(options, callback)

    • options (TraceCategoriesAndOptions | TraceConfig)
    • callback Function在所有进程上开始记录

    一旦收到EnableRecording请求,记录立即在本地开始进行,并在子进程上异步执行。 一旦所有子进程都确认了startRecording请求,callback就会被调用。

    即将弃用

    contentTracing.startRecording(options)

    • options (TraceCategoriesAndOptions | TraceConfig)Returns Promise<void> - resolved once all child processes have acknowledged the startRecording request.

    在所有进程上开始记录

    一旦收到EnableRecording请求,记录立即在本地开始进行,并在子进程上异步执行。

    contentTracing.stopRecording(resultFilePath, callback)

    • resultFilePath String
    • callback Function

      • resultFilePath String停止所有进程记录。

    子进程通常缓存跟踪数据,并且很少清空和发送跟踪数据回到主进程。 这有助于最小化运行时间开销,因为通过IPC发送跟踪数据可能是一个开销巨大的操作。 所以,为了结束跟踪,我们必须异步地要求所有子进程清空任何等待跟踪数据。

    一旦所有子进程确认了 stopRecording请求,将传递包含跟踪数据的文件作为参数调用callback

    如果resultFilePath不为空,则跟踪数据会被写入该路径,否则就被写入一个临时文件。实际的文件路径如果不为null的话就被传递给callback函数了。

    即将弃用

    contentTracing.stopRecording(resultFilePath)

    • resultFilePath StringReturns Promise<String> - resolves with a file that contains the traced data once all child processes have acknowledged the stopRecording request

    停止所有进程记录。

    子进程通常缓存跟踪数据,并且很少清空和发送跟踪数据回到主进程。 这有助于最小化运行时间开销,因为通过IPC发送跟踪数据可能是一个开销巨大的操作。 所以,为了结束跟踪,我们必须异步地要求所有子进程清空任何等待跟踪数据。

    Trace data will be written into resultFilePath if it is not empty or into a temporary file.

    contentTracing.startMonitoring(options, callback)

    • callback Function

      • Object

        • value Number
        • percentage Number获取跟踪缓冲区进程的最大使用率,以百分比表示完整状态。当 TraceBufferUsage 值被确定后, 将调用 callback

    即将弃用

    contentTracing.getTraceBufferUsage()

    Returns Promise<Object> - Resolves with an object containing the value and percentage of trace buffer maximum usage

    Get the maximum usage across processes of trace buffer as a percentage of the full state.