2015-08-28 10:57:20 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# contentTracing
  
						 
					
						
							
								
									
										
										
										
											2014-07-31 15:40:40 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-05-28 14:15:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								>  Collect tracing data from Chromium to find performance bottlenecks and slow operations.
  
						 
					
						
							
								
									
										
										
										
											2016-04-21 15:35:29 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-23 11:20:56 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Process: [Main ](../glossary.md#main-process )
							 
						 
					
						
							
								
									
										
										
										
											2016-11-11 10:07:36 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-05-28 14:15:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This module does not include a web interface. To view recorded traces, use
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[trace viewer][], available at `chrome://tracing`  in Chrome.
							 
						 
					
						
							
								
									
										
										
										
											2014-07-31 15:40:40 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-02 13:20:38 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								**Note:** You should not use this module until the `ready`  event of the app
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								module is emitted.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-13 02:36:38 +05:30 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-02 13:20:38 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```javascript
							 
						 
					
						
							
								
									
										
										
										
											2018-09-14 02:10:51 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const { app, contentTracing } = require('electron')
							 
						 
					
						
							
								
									
										
										
										
											2017-02-02 13:20:38 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-02-03 16:43:22 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								app.whenReady().then(() => {
							 
						 
					
						
							
								
									
										
										
										
											2019-05-28 14:15:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  (async () => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    await contentTracing.startRecording({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      include_categories: ['*']
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    })
							 
						 
					
						
							
								
									
										
										
										
											2017-02-02 13:20:38 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    console.log('Tracing started')
							 
						 
					
						
							
								
									
										
										
										
											2019-05-28 14:15:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    await new Promise(resolve => setTimeout(resolve, 5000))
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const path = await contentTracing.stopRecording()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    console.log('Tracing data recorded to ' + path)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })()
							 
						 
					
						
							
								
									
										
										
										
											2016-07-25 18:39:25 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								})
							 
						 
					
						
							
								
									
										
										
										
											2014-07-31 15:40:40 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-25 04:49:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Methods
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-04-26 10:28:20 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The `contentTracing`  module has the following methods:
							 
						 
					
						
							
								
									
										
										
										
											2015-08-25 04:49:48 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-01-30 12:39:55 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### `contentTracing.getCategories()`
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Returns `Promise<String[]>`  - resolves with an array of category groups once all child processes have acknowledged the `getCategories`  request
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-05-28 14:15:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								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](https://chromium.googlesource.com/chromium/src/+/master/base/trace_event/builtin_categories.h).
							 
						 
					
						
							
								
									
										
										
										
											2014-07-31 15:40:40 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-12-06 13:15:23 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								>  **NOTE:** Electron adds a non-default tracing category called `"electron"`.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								>  This category can be used to capture Electron-specific tracing events.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-01-30 18:53:55 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### `contentTracing.startRecording(options)`
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-05-28 14:15:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								*  `options`  ([TraceConfig ](structures/trace-config.md ) | [TraceCategoriesAndOptions ](structures/trace-categories-and-options.md )) 
						 
					
						
							
								
									
										
										
										
											2019-01-30 18:53:55 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								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.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-05-28 14:15:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								If a recording is already running, the promise will be immediately resolved, as
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								only one trace operation can be in progress at a time.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 14:03:24 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### `contentTracing.stopRecording([resultFilePath])`
  
						 
					
						
							
								
									
										
										
										
											2019-01-30 18:53:55 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-05-28 14:15:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								*  `resultFilePath`  String (optional) 
						 
					
						
							
								
									
										
										
										
											2019-01-30 18:53:55 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-05-28 14:15:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Returns `Promise<String>`  - resolves with a path to a file that contains the traced data once all child processes have acknowledged the `stopRecording`  request
							 
						 
					
						
							
								
									
										
										
										
											2019-01-30 18:53:55 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								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,
							 
						 
					
						
							
								
									
										
										
										
											2019-05-28 14:15:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								to end tracing, Chromium asynchronously asks all child processes to flush any
							 
						 
					
						
							
								
									
										
										
										
											2019-01-30 18:53:55 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pending trace data.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-05-28 14:15:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								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.
							 
						 
					
						
							
								
									
										
										
										
											2019-01-30 18:53:55 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 13:24:57 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### `contentTracing.getTraceBufferUsage()`
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Returns `Promise<Object>`  - Resolves with an object containing the `value`  and `percentage`  of trace buffer maximum usage
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-05 10:45:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								*  `value`  Number 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*  `percentage`  Number 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-13 13:24:57 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Get the maximum usage across processes of trace buffer as a percentage of the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								full state.
							 
						 
					
						
							
								
									
										
										
										
											2019-05-28 14:15:42 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[trace viewer]: https://github.com/catapult-project/catapult/blob/master/tracing