Skip to content

contentTracing

Collect tracing data from Chromium to find performance bottlenecks and slow operations.

Process: Main

This module does not include a web interface. Traces are recorded in the Perfetto protobuf format; to view them, open them in the Perfetto UI.

[!NOTE] You should not use this module until the ready event of the app module is emitted.

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

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.

If a recording is already running, the promise will be immediately resolved, as only one trace operation can be in progress at a time. If options.nativeHeapProfiling is set while a recording is already running, the promise is rejected instead, since the already-running recording's options can't be changed to turn on heap profiling.

contentTracing.stopRecording([resultFilePath])

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

  • value number
  • percentage number

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

Markdown source: View on AtomGit·Content from the open-source project el/electron