{ "type": "module", "source": "doc/api/tracing.md", "modules": [ { "textRaw": "Trace Events", "name": "trace_events", "introduced_in": "v7.7.0", "stability": 1, "stabilityText": "Experimental", "desc": "

Trace Event provides a mechanism to centralize tracing information generated by\nV8, Node.js core, and userspace code.

\n

Tracing can be enabled with the --trace-event-categories command-line flag\nor by using the trace_events module. The --trace-event-categories flag\naccepts a list of comma-separated category names.

\n

The available categories are:

\n\n

By default the node, node.async_hooks, and v8 categories are enabled.

\n
node --trace-event-categories v8,node,node.async_hooks server.js\n
\n

Prior versions of Node.js required the use of the --trace-events-enabled\nflag to enable trace events. This requirement has been removed. However, the\n--trace-events-enabled flag may still be used and will enable the\nnode, node.async_hooks, and v8 trace event categories by default.

\n
node --trace-events-enabled\n\n// is equivalent to\n\nnode --trace-event-categories v8,node,node.async_hooks\n
\n

Alternatively, trace events may be enabled using the trace_events module:

\n
const trace_events = require('trace_events');\nconst tracing = trace_events.createTracing({ categories: ['node.perf'] });\ntracing.enable();  // Enable trace event capture for the 'node.perf' category\n\n// do work\n\ntracing.disable();  // Disable trace event capture for the 'node.perf' category\n
\n

Running Node.js with tracing enabled will produce log files that can be opened\nin the chrome://tracing\ntab of Chrome.

\n

The logging file is by default called node_trace.${rotation}.log, where\n${rotation} is an incrementing log-rotation id. The filepath pattern can\nbe specified with --trace-event-file-pattern that accepts a template\nstring that supports ${rotation} and ${pid}:

\n
node --trace-event-categories v8 --trace-event-file-pattern '${pid}-${rotation}.log' server.js\n
\n

Starting with Node.js 10.0.0, the tracing system uses the same time source\nas the one used by process.hrtime()\nhowever the trace-event timestamps are expressed in microseconds,\nunlike process.hrtime() which returns nanoseconds.

", "modules": [ { "textRaw": "The `trace_events` module", "name": "the_`trace_events`_module", "meta": { "added": [ "v10.0.0" ], "changes": [] }, "modules": [ { "textRaw": "`Tracing` object", "name": "`tracing`_object", "meta": { "added": [ "v10.0.0" ], "changes": [] }, "desc": "

The Tracing object is used to enable or disable tracing for sets of\ncategories. Instances are created using the trace_events.createTracing()\nmethod.

\n

When created, the Tracing object is disabled. Calling the\ntracing.enable() method adds the categories to the set of enabled trace event\ncategories. Calling tracing.disable() will remove the categories from the\nset of enabled trace event categories.

", "modules": [ { "textRaw": "`tracing.categories`", "name": "`tracing.categories`", "meta": { "added": [ "v10.0.0" ], "changes": [] }, "desc": "\n

A comma-separated list of the trace event categories covered by this\nTracing object.

", "type": "module", "displayName": "`tracing.categories`" }, { "textRaw": "`tracing.disable()`", "name": "`tracing.disable()`", "meta": { "added": [ "v10.0.0" ], "changes": [] }, "desc": "

Disables this Tracing object.

\n

Only trace event categories not covered by other enabled Tracing objects\nand not specified by the --trace-event-categories flag will be disabled.

\n
const trace_events = require('trace_events');\nconst t1 = trace_events.createTracing({ categories: ['node', 'v8'] });\nconst t2 = trace_events.createTracing({ categories: ['node.perf', 'node'] });\nt1.enable();\nt2.enable();\n\n// Prints 'node,node.perf,v8'\nconsole.log(trace_events.getEnabledCategories());\n\nt2.disable(); // will only disable emission of the 'node.perf' category\n\n// Prints 'node,v8'\nconsole.log(trace_events.getEnabledCategories());\n
", "type": "module", "displayName": "`tracing.disable()`" }, { "textRaw": "`tracing.enable()`", "name": "`tracing.enable()`", "meta": { "added": [ "v10.0.0" ], "changes": [] }, "desc": "

Enables this Tracing object for the set of categories covered by the\nTracing object.

", "type": "module", "displayName": "`tracing.enable()`" }, { "textRaw": "`tracing.enabled`", "name": "`tracing.enabled`", "meta": { "added": [ "v10.0.0" ], "changes": [] }, "desc": "", "type": "module", "displayName": "`tracing.enabled`" } ], "type": "module", "displayName": "`Tracing` object" }, { "textRaw": "`trace_events.createTracing(options)`", "name": "`trace_events.createtracing(options)`", "meta": { "added": [ "v10.0.0" ], "changes": [] }, "desc": "\n

Creates and returns a Tracing object for the given set of categories.

\n
const trace_events = require('trace_events');\nconst categories = ['node.perf', 'node.async_hooks'];\nconst tracing = trace_events.createTracing({ categories });\ntracing.enable();\n// do stuff\ntracing.disable();\n
", "type": "module", "displayName": "`trace_events.createTracing(options)`" }, { "textRaw": "`trace_events.getEnabledCategories()`", "name": "`trace_events.getenabledcategories()`", "meta": { "added": [ "v10.0.0" ], "changes": [] }, "desc": "\n

Returns a comma-separated list of all currently-enabled trace event\ncategories. The current set of enabled trace event categories is determined\nby the union of all currently-enabled Tracing objects and any categories\nenabled using the --trace-event-categories flag.

\n

Given the file test.js below, the command\nnode --trace-event-categories node.perf test.js will print\n'node.async_hooks,node.perf' to the console.

\n
const trace_events = require('trace_events');\nconst t1 = trace_events.createTracing({ categories: ['node.async_hooks'] });\nconst t2 = trace_events.createTracing({ categories: ['node.perf'] });\nconst t3 = trace_events.createTracing({ categories: ['v8'] });\n\nt1.enable();\nt2.enable();\n\nconsole.log(trace_events.getEnabledCategories());\n
", "type": "module", "displayName": "`trace_events.getEnabledCategories()`" } ], "type": "module", "displayName": "The `trace_events` module" } ], "type": "module", "displayName": "Trace Events" } ] }