2016-08-05 23:04:25 +02:00
|
|
|
# Tracing
|
|
|
|
|
2017-11-04 09:08:46 +01:00
|
|
|
<!--introduced_in=v7.7.0-->
|
|
|
|
|
2016-08-05 23:04:25 +02:00
|
|
|
Trace Event provides a mechanism to centralize tracing information generated by
|
2018-03-04 14:46:49 +01:00
|
|
|
V8, Node.js core, and userspace code.
|
2016-08-05 23:04:25 +02:00
|
|
|
|
2018-02-12 08:31:55 +01:00
|
|
|
Tracing can be enabled by passing the `--trace-events-enabled` flag when
|
|
|
|
starting a Node.js application.
|
2016-08-05 23:04:25 +02:00
|
|
|
|
|
|
|
The set of categories for which traces are recorded can be specified using the
|
2018-02-12 08:31:55 +01:00
|
|
|
`--trace-event-categories` flag followed by a list of comma separated category
|
2018-02-14 20:06:32 +01:00
|
|
|
names.
|
|
|
|
|
|
|
|
The available categories are:
|
|
|
|
|
|
|
|
* `node`
|
|
|
|
* `node.async_hooks` - Enables capture of detailed async_hooks trace data.
|
|
|
|
* `node.perf` - Enables capture of [Performance API] measurements.
|
|
|
|
* `node.perf.usertiming` - Enables capture of only Performance API User Timing
|
|
|
|
measures and marks.
|
|
|
|
* `node.perf.timerify` - Enables capture of only Performance API timerify
|
|
|
|
measurements.
|
|
|
|
* `v8`
|
|
|
|
|
|
|
|
By default the `node`, `node.async_hooks`, and `v8` categories are enabled.
|
2016-08-05 23:04:25 +02:00
|
|
|
|
|
|
|
```txt
|
2017-07-18 01:47:12 +02:00
|
|
|
node --trace-events-enabled --trace-event-categories v8,node,node.async_hooks server.js
|
2016-08-05 23:04:25 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Running Node.js with tracing enabled will produce log files that can be opened
|
|
|
|
in the [`chrome://tracing`](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool)
|
|
|
|
tab of Chrome.
|
2018-01-17 02:13:36 +01:00
|
|
|
|
2018-01-31 17:12:09 +01:00
|
|
|
The logging file is by default called `node_trace.${rotation}.log`, where
|
|
|
|
`${rotation}` is an incrementing log-rotation id. The filepath pattern can
|
|
|
|
be specified with `--trace-event-file-pattern` that accepts a template
|
|
|
|
string that supports `${rotation}` and `${pid}`. For example:
|
|
|
|
|
|
|
|
```txt
|
|
|
|
node --trace-events-enabled --trace-event-file-pattern '${pid}-${rotation}.log' server.js
|
|
|
|
```
|
|
|
|
|
2018-03-04 14:46:49 +01:00
|
|
|
Starting with Node.js 10.0.0, the tracing system uses the same time source
|
|
|
|
as the one used by `process.hrtime()`
|
|
|
|
however the trace-event timestamps are expressed in microseconds,
|
|
|
|
unlike `process.hrtime()` which returns nanoseconds.
|
2018-02-14 20:06:32 +01:00
|
|
|
|
|
|
|
[Performance API]: perf_hooks.html
|