当前位置: 首页 > 文档资料 > Electron 中文文档 >

contentTracing

优质
小牛编辑
161浏览
2023-12-01

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

进程:主进程

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

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

const { app, contentTracing } = require('electron')
app.on('ready', () => {
  const options = {
    categoryFilter: '*',
    traceOptions: 'record-until-full,enable-sampling'
  }
  contentTracing.startRecording(options, () => {
    console.log('Tracing started')
    setTimeout(() => {contentTracing.stopRecording('', (path) => {  console.log('Tracing data recorded to ' + path)})
    }, 5000)
  })
})

Collect tracing data from Chromium's content module for finding performance bottlenecks and slow operations.

Process: Main

This module does not include a web interface so you need to open chrome://tracing/ in a Chrome browser and load the generated file to view the result.

Note: You should not use this module until the ready event of the app module is emitted.

const { app, contentTracing } = require('electron')
app.on('ready', () => {
  const options = {
    categoryFilter: '*',
    traceOptions: 'record-until-full,enable-sampling'
  }
  contentTracing.startRecording(options, () => {
    console.log('Tracing started')
    setTimeout(() => {contentTracing.stopRecording('', (path) => {  console.log('Tracing data recorded to ' + path)})
    }, 5000)
  })
})

方法

contentTracing模块包含以下方法:

Methods

The contentTracing module has the following methods:

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

Deprecated Soon

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.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, callback)

  • options (TraceCategoriesAndOptions | TraceConfig)
  • callback Function

Start recording on all processes.

Recording begins immediately locally and asynchronously on child processes as soon as they receive the EnableRecording request. The callback will be called once all child processes have acknowledged the startRecording request.

Deprecated Soon

contentTracing.startRecording(options)

  • options (TraceCategoriesAndOptions | TraceConfig)

Returns Promise<void> - resolved once all child processes have acknowledged the startRecording request.

在所有进程上开始记录

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

contentTracing.startRecording(options)

  • options (TraceCategoriesAndOptions | TraceConfig)

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.

contentTracing.stopRecording(resultFilePath, callback)

  • resultFilePath String
  • callback Function

    • resultFilePath String

停止所有进程记录。

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

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

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

即将弃用

contentTracing.stopRecording(resultFilePath, callback)

  • resultFilePath String
  • callback Function

    • resultFilePath String

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. So, to end tracing, we must asynchronously ask all child processes to flush any pending trace data.

Once all child processes have acknowledged the stopRecording request, callback will be called with a file that contains the traced data.

Trace data will be written into resultFilePath if it is not empty or into a temporary file. The actual file path will be passed to callback if it's not null.

Deprecated Soon

contentTracing.stopRecording(resultFilePath)

  • resultFilePath String

Returns 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.stopRecording(resultFilePath)

  • resultFilePath String

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

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. So, to end tracing, we must asynchronously ask all child processes to flush any pending trace data.

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(callback)

  • callback Function

    • Object

      • value Number
      • percentage Number

Get the maximum usage across processes of trace buffer as a percentage of the full state. When the TraceBufferUsage value is determined the callback is called.

Deprecated Soon

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.

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.