contentTracing | Electron
https://www.electronjs.org/docs/latest/api/content-tracing • 59 KB fetched Open original page
contentTracing | Electron
Skip to main content
Electron Docs API Blog Tools
* Electron Forge
* Electron Fiddle
Community
* Governance
* Showcase
* Resources
Releases English
* English
* Deutsch
* Español
* Français
* 日本語
* Português
* Русский
* 中文
Search
* Main Process Modules
* app
* autoUpdater
* BaseWindow
* BrowserView
* Deprecated
* BrowserWindow
* clipboard
* contentTracing
* crashReporter
* desktopCapturer
* dialog
* globalShortcut
* ImageView
* inAppPurchase
* ipcMain
* Menu
* MenuItem
* MessageChannelMain
* MessagePortMain
* nativeImage
* nativeTheme
* net
* netLog
* Notification
* powerMonitor
* powerSaveBlocker
* process
* protocol
* pushNotifications
* safeStorage
* screen
* session
* sharedTexture
* ShareMenu
* shell
* systemPreferences
* TouchBar
* Tray
* utilityProcess
* webContents
* WebContentsView
* webFrameMain
* View
* Renderer Process Modules
* Utility Process Modules
* Custom DOM Elements
* Chromium and Node.js
* Classes
* API Structures
*
* Main Process Modules
* contentTracing On this page
contentTracing
Collect tracing data from Chromium to find performance bottlenecks and slow operations.
Process: Main
This module does not include a web interface. To view recorded traces, use
trace viewer , available at chrome://tracing in Chrome.
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()
History Version(s) Changes None
This method now returns a Promise instead of using a callback function.
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 .
NOTE: Electron adds a non-default tracing category called "electron" .
This category can be used to capture Electron-specific tracing events.
contentTracing.startRecording(options)
History Version(s) Changes None
The options parameter now accepts TraceConfig in addition to TraceCategoriesAndOptions . None
This function now returns a callback Promise<void> .
* options ( TraceConfig | TraceCategoriesAndOptions )
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.
contentTracing.stopRecording([resultFilePath])
History Version(s) Changes None
This method now returns a Promise instead of using a callback function.
None
The resultFilePath parameter is now optional.
* 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 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, Chromium asynchronously asks all child processes to flush any
pending trace data.
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()
History Version(s) Changes None
This method now returns a Promise instead of using a callback function.
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.
contentTracing.enableHeapProfiling([options]) Experimental
History Version(s) Changes >=43.0.0
API ADDED
* options ( EnableHeapProfilingOptions ) (optional)
Returns Promise<void> - Resolves once heap profiling has been enabled.
Enable heap profiling
for MemoryInfra traces. Equivalent to the --memlog switch in Chrome.
Only takes effect if the disabled-by-default-memory-infra category is included.
Needs to be called before contentTracing.startRecording() .
Usage:
const { contentTracing } = require ( 'electron' )
async function recordTrace ( ) {
await contentTracing . enableHeapProfiling ( )
await contentTracing . startRecording ( {
included_categories : [ 'disabled-by-default-memory-infra' ] ,
excluded_categories : [ '*' ] ,
memory_dump_config : {
triggers : [
{ mode : 'detailed' , periodic_interval_ms : 1000 }
]
}
} )
await new Promise ( resolve => setTimeout ( resolve , 5000 ) )
const filePath = await contentTracing . stopRecording ( )
}
To view the recorded heap dumps:
*
Download the breakpad symbols for your Electron version from the Electron GitHub
releases
*
Clone the Electron source code
*
In your Chromium checkout for Electron, run this command to symbolicate the heap dump:
python3 third_party/catapult/tracing/bin/symbolize_trace --use-breakpad-symbols --breakpad-symbols-directory /path/to/breakpad_symbols /path/to/trace.json
*
Open the symbolicated trace in chrome://tracing (the Perfetto UI does not support memory dumps
yet)
*
Click on one of the M symbols
*
Click on a ☰ triple bar icon (e.g., in the malloc column)
Edit this page
Previous
clipboard
Next
crashReporter
* Methods
* getCategories
* startRecording
* stopRecording
* getTraceBufferUsage
* enableHeapProfiling
Docs
* Getting Started
* API Reference
Checklists
* Performance
* Security
Tools
* Electron Forge
* Electron Fiddle
Community
* Governance
* Resources
* Bluesky
* X
* Mastodon
* Stack Overflow
More
* GitHub
* Open Collective
* Infrastructure Dashboard
Copyright OpenJS Foundation and Electron contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation , please see our Trademark Policy and Trademark List . Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them. The OpenJS Foundation | Terms of Use | Privacy Policy | Bylaws | Code of Conduct | Trademark Policy | Trademark List | Cookie Policy
Hosting and infrastructure graciously provided by
Links found on this page
- Skip to main content [direct]
- Electron [direct]
- Docs [direct]
- API [direct]
- Blog [direct]
- Electron Forge [direct]
- Electron Fiddle [direct]
- Governance [direct]
- Showcase [direct]
- Resources [direct]
- Releases [direct]
- Deutsch [direct]
- Español [direct]
- Français [direct]
- 日本語 [direct]
- Português [direct]
- Русский [direct]
- 中文 [direct]
- autoUpdater [direct]
- BaseWindow [direct]
- BrowserView Deprecated [direct]
- BrowserWindow [direct]
- clipboard [direct]
- crashReporter [direct]
- desktopCapturer [direct]
- dialog [direct]
- globalShortcut [direct]
- ImageView [direct]
- inAppPurchase [direct]
- ipcMain [direct]
- Menu [direct]
- MenuItem [direct]
- MessageChannelMain [direct]
- MessagePortMain [direct]
- nativeImage [direct]
- nativeTheme [direct]
- net [direct]
- netLog [direct]
- Notification [direct]
- powerMonitor [direct]
- powerSaveBlocker [direct]
- process [direct]
- protocol [direct]
- pushNotifications [direct]
- safeStorage [direct]
- screen [direct]
- session [direct]
- sharedTexture [direct]
- ShareMenu [direct]
- shell [direct]
- systemPreferences [direct]
- TouchBar [direct]
- Tray [direct]
- utilityProcess [direct]
- webContents [direct]
- WebContentsView [direct]
- webFrameMain [direct]
- View [direct]
- Custom DOM Elements [direct]
- Chromium and Node.js [direct]
- Classes [direct]
- API Structures [direct]
- Main [direct]
- trace viewer [direct]
- This method now returns a Promise instead of using a callback function. [direct]
- list of built-in tracing categories [direct]
- TraceConfig [direct]
- TraceCategoriesAndOptions [direct]
- >=43.0.0 [direct]
- EnableHeapProfilingOptions [direct]
- heap profiling [direct]
- releases [direct]
- Electron source code [direct]
- Edit this page [direct]
- Performance [direct]
- Security [direct]
- Bluesky [direct]
- X [direct]
- Mastodon [direct]
- Stack Overflow [direct]
|
|