2015-08-28 17:57:20 +00:00
|
|
|
# contentTracing
|
2014-07-31 07:40:40 +00:00
|
|
|
|
2016-04-22 17:30:49 +00:00
|
|
|
> Collect tracing data from Chromium's content module for finding performance
|
|
|
|
bottlenecks and slow operations.
|
2016-04-21 22:35:29 +00:00
|
|
|
|
2016-11-23 19:20:56 +00:00
|
|
|
Process: [Main](../glossary.md#main-process)
|
2016-11-11 18:07:36 +00:00
|
|
|
|
2016-04-22 18:42:54 +00:00
|
|
|
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.
|
2014-07-31 07:40:40 +00:00
|
|
|
|
2017-02-02 21:20:38 +00:00
|
|
|
**Note:** You should not use this module until the `ready` event of the app
|
|
|
|
module is emitted.
|
2015-11-12 21:06:38 +00:00
|
|
|
|
2017-02-02 21:20:38 +00:00
|
|
|
```javascript
|
2018-09-13 16:10:51 +00:00
|
|
|
const { app, contentTracing } = require('electron')
|
2017-02-02 21:20:38 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
2016-07-26 01:39:25 +00:00
|
|
|
})
|
2014-07-31 07:40:40 +00:00
|
|
|
```
|
|
|
|
|
2015-08-25 11:49:48 +00:00
|
|
|
## Methods
|
|
|
|
|
2016-04-26 17:28:20 +00:00
|
|
|
The `contentTracing` module has the following methods:
|
2015-08-25 11:49:48 +00:00
|
|
|
|
2015-08-28 17:57:20 +00:00
|
|
|
### `contentTracing.getCategories(callback)`
|
2014-07-31 07:40:40 +00:00
|
|
|
|
|
|
|
* `callback` Function
|
2016-10-13 06:30:57 +00:00
|
|
|
* `categories` String[]
|
2014-07-31 07:40:40 +00:00
|
|
|
|
2019-01-30 20:39:55 +00:00
|
|
|
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](promisification.md)**
|
|
|
|
|
|
|
|
### `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.
|
2014-07-31 07:40:40 +00:00
|
|
|
|
|
|
|
|
2015-09-02 07:16:49 +00:00
|
|
|
### `contentTracing.startRecording(options, callback)`
|
2014-07-31 07:40:40 +00:00
|
|
|
|
2018-12-20 12:11:17 +00:00
|
|
|
* `options` ([TraceCategoriesAndOptions](structures/trace-categories-and-options.md) | [TraceConfig](structures/trace-config.md))
|
2014-07-31 07:40:40 +00:00
|
|
|
* `callback` Function
|
|
|
|
|
|
|
|
Start recording on all processes.
|
|
|
|
|
2015-08-25 11:49:48 +00:00
|
|
|
Recording begins immediately locally and asynchronously on child processes
|
2015-08-27 15:11:51 +00:00
|
|
|
as soon as they receive the EnableRecording request. The `callback` will be
|
|
|
|
called once all child processes have acknowledged the `startRecording` request.
|
2014-07-31 07:40:40 +00:00
|
|
|
|
2019-01-31 02:53:55 +00:00
|
|
|
**[Deprecated Soon](promisification.md)**
|
|
|
|
|
|
|
|
### `contentTracing.startRecording(options)`
|
|
|
|
|
|
|
|
* `options` ([TraceCategoriesAndOptions](structures/trace-categories-and-options.md) | [TraceConfig](structures/trace-config.md))
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2015-08-28 17:57:20 +00:00
|
|
|
### `contentTracing.stopRecording(resultFilePath, callback)`
|
2014-07-31 07:40:40 +00:00
|
|
|
|
|
|
|
* `resultFilePath` String
|
|
|
|
* `callback` Function
|
2016-10-13 06:30:57 +00:00
|
|
|
* `resultFilePath` String
|
2014-07-31 07:40:40 +00:00
|
|
|
|
|
|
|
Stop recording on all processes.
|
|
|
|
|
2015-08-27 15:11:51 +00:00
|
|
|
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.
|
2014-07-31 07:40:40 +00:00
|
|
|
|
2015-08-26 21:56:00 +00:00
|
|
|
Once all child processes have acknowledged the `stopRecording` request,
|
|
|
|
`callback` will be called with a file that contains the traced data.
|
2014-07-31 07:40:40 +00:00
|
|
|
|
2015-08-25 11:49:48 +00:00
|
|
|
Trace data will be written into `resultFilePath` if it is not empty or into a
|
2014-07-31 07:40:40 +00:00
|
|
|
temporary file. The actual file path will be passed to `callback` if it's not
|
2015-08-25 11:49:48 +00:00
|
|
|
`null`.
|
2014-07-31 07:40:40 +00:00
|
|
|
|
2019-01-31 02:53:55 +00:00
|
|
|
**[Deprecated Soon](promisification.md)**
|
|
|
|
|
|
|
|
### `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.
|
|
|
|
|
2015-08-28 17:57:20 +00:00
|
|
|
### `contentTracing.getTraceBufferUsage(callback)`
|
2014-07-31 07:40:40 +00:00
|
|
|
|
|
|
|
* `callback` Function
|
2016-10-13 06:30:57 +00:00
|
|
|
* `value` Number
|
|
|
|
* `percentage` Number
|
2014-07-31 07:40:40 +00:00
|
|
|
|
2015-08-25 12:16:20 +00:00
|
|
|
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.
|