electron/docs/api/content-tracing.md

157 lines
5 KiB
Markdown
Raw Normal View History

2015-08-25 11:49:48 +00:00
# content-trace
2014-07-31 07:40:40 +00:00
The `content-trace` module is used to collect tracing data generated by the
underlying Chromium content module. This module does not include a web interface
2015-08-25 11:49:48 +00:00
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
```javascript
var tracing = require('content-tracing');
tracing.startRecording('*', tracing.DEFAULT_OPTIONS, function() {
console.log('Tracing started');
setTimeout(function() {
tracing.stopRecording('', function(path) {
console.log('Tracing data recorded to ' + path);
});
}, 5000);
});
```
2015-08-25 11:49:48 +00:00
## Methods
- The `content-trace` module has the following methods:
### `tracing.getCategories(callback)`
2014-07-31 07:40:40 +00:00
* `callback` Function
Get a set of category groups. The category groups can change as new code paths
are reached.
2015-08-25 12:16:20 +00:00
Once all child processes have acked to the `getCategories` request, `callback`
is invoked with an array of category groups.
2014-07-31 07:40:40 +00:00
2015-08-25 11:49:48 +00:00
### `tracing.startRecording(categoryFilter, traceOptions, callback)`
2014-07-31 07:40:40 +00:00
* `categoryFilter` String
2015-08-04 20:12:57 +00:00
* `traceOptions` String
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
2014-07-31 07:40:40 +00:00
as soon as they receive the EnableRecording request. Once all child processes
2015-08-25 11:49:48 +00:00
have acked to the `startRecording` request the `callback` will be called.
2014-07-31 07:40:40 +00:00
`categoryFilter` is a filter to control what category groups should be
traced. A filter can have an optional `-` prefix to exclude category groups
that contain a matching category. Having both included and excluded
2015-05-23 22:44:58 +00:00
category patterns in the same list is not supported.
2014-07-31 07:40:40 +00:00
Examples:
* `test_MyTest*`,
* `test_MyTest*,test_OtherStuff`,
* `"-excluded_category1,-excluded_category2`
2015-08-25 11:49:48 +00:00
`traceOptions` controls what kind of tracing is enabled, it is a comma-delimited
list. Possible options are:
2015-08-04 20:12:57 +00:00
* `record-until-full`
* `record-continuously`
* `trace-to-console`
* `enable-sampling`
* `enable-systrace`
The first 3 options are trace recoding modes and hence mutually exclusive.
If more than one trace recording modes appear in the `traceOptions` string,
the last one takes precedence. If none of the trace recording mode is specified,
recording mode is `record-until-full`.
The trace option will first be reset to the default option (record_mode set to
2015-08-25 11:49:48 +00:00
`record-until-full`, enable_sampling and enable_systrace set to `false`)
2015-08-04 20:12:57 +00:00
before options parsed from `traceOptions` are applied on it.
2014-07-31 07:40:40 +00:00
2015-08-25 11:49:48 +00:00
### `tracing.stopRecording(resultFilePath, callback)`
2014-07-31 07:40:40 +00:00
* `resultFilePath` String
* `callback` Function
Stop recording on all processes.
Child processes typically are caching trace data and only rarely flush and send
trace data back to the main process. That is because it may be an expensive
2015-08-25 12:16:20 +00:00
operation to send the trace data over IPC, and we would like to avoid runtime
overhead of tracing. So, to end tracing, we must asynchronously ask all
2014-07-31 07:40:40 +00:00
child processes to flush any pending trace data.
Once all child processes have acked to the `stopRecording` request, `callback`
2015-08-25 11:49:48 +00:00
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
2015-08-25 11:49:48 +00:00
### `tracing.startMonitoring(categoryFilter, traceOptions, callback)`
2014-07-31 07:40:40 +00:00
* `categoryFilter` String
2015-08-04 20:12:57 +00:00
* `traceOptions` String
2014-07-31 07:40:40 +00:00
* `callback` Function
Start monitoring on all processes.
2015-08-25 11:49:48 +00:00
Monitoring begins immediately locally and asynchronously on child processes as
2014-07-31 07:40:40 +00:00
soon as they receive the `startMonitoring` request.
2015-08-25 11:49:48 +00:00
Once all child processes have acked to the `startMonitoring` request the
`callback` will be called.
2014-07-31 07:40:40 +00:00
2015-08-25 11:49:48 +00:00
### `tracing.stopMonitoring(callback)`
2014-07-31 07:40:40 +00:00
* `callback` Function
Stop monitoring on all processes.
2015-08-25 12:16:20 +00:00
Once all child processes have acked to the `stopMonitoring` request the
`callback` is called.
2014-07-31 07:40:40 +00:00
2015-08-25 11:49:48 +00:00
### `tracing.captureMonitoringSnapshot(resultFilePath, callback)`
2014-07-31 07:40:40 +00:00
* `resultFilePath` String
* `callback` Function
Get the current monitoring traced data.
Child processes typically are caching trace data and only rarely flush and send
trace data back to the main process. That is because it may be an expensive
2015-08-25 11:49:48 +00:00
operation to send the trace data over IPC and we would like to avoid unneeded
2015-08-25 12:16:20 +00:00
runtime overhead from tracing. 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-25 12:16:20 +00:00
Once all child processes have acked to the `captureMonitoringSnapshot` request
the `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
### `tracing.getTraceBufferUsage(callback)`
2014-07-31 07:40:40 +00:00
* `callback` Function
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.
2014-07-31 07:40:40 +00:00
2015-08-25 11:49:48 +00:00
### `tracing.setWatchEvent(categoryName, eventName, callback)`
2014-07-31 07:40:40 +00:00
* `categoryName` String
* `eventName` String
* `callback` Function
2015-03-10 23:02:22 +00:00
`callback` will will be called every time the given event occurs on any
process.
2014-07-31 07:40:40 +00:00
2015-08-25 11:49:48 +00:00
### `tracing.cancelWatchEvent()`
2014-07-31 07:40:40 +00:00
2015-08-25 11:49:48 +00:00
Cancel the watch event. If tracing is enabled this may race with the watch
2014-07-31 07:40:40 +00:00
event callback.