2017-07-17 16:47:12 -07:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const cp = require('child_process');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
const CODE =
|
|
|
|
'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)';
|
|
|
|
const FILE_NAME = 'node_trace.1.log';
|
|
|
|
|
2017-12-24 22:38:11 -08:00
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
|
|
|
process.chdir(tmpdir.path);
|
2017-07-17 16:47:12 -07:00
|
|
|
|
|
|
|
const proc = cp.spawn(process.execPath,
|
2018-04-03 18:05:33 -07:00
|
|
|
[ '--trace-event-categories', 'node.async_hooks',
|
2017-07-17 16:47:12 -07:00
|
|
|
'-e', CODE ]);
|
|
|
|
|
|
|
|
proc.once('exit', common.mustCall(() => {
|
|
|
|
assert(common.fileExists(FILE_NAME));
|
|
|
|
fs.readFile(FILE_NAME, common.mustCall((err, data) => {
|
|
|
|
const traces = JSON.parse(data.toString()).traceEvents;
|
|
|
|
assert(traces.length > 0);
|
|
|
|
// V8 trace events should be generated.
|
|
|
|
assert(!traces.some((trace) => {
|
|
|
|
if (trace.pid !== proc.pid)
|
|
|
|
return false;
|
|
|
|
if (trace.cat !== 'v8')
|
|
|
|
return false;
|
|
|
|
if (trace.name !== 'V8.ScriptCompiler')
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}));
|
|
|
|
|
|
|
|
// C++ async_hooks trace events should be generated.
|
|
|
|
assert(traces.some((trace) => {
|
|
|
|
if (trace.pid !== proc.pid)
|
|
|
|
return false;
|
src: add tracing category macros
Adds `TRACING_CATEGORY_NODE`, `TRACING_CATEGORY_NODE1` and
`TRACING_CATEGORY_NODE2` helper macros for consistently building
trace event category strings. For instance,
`TRACING_CATEGORY_NODE2(foo, bar)` would generate the category
string `node,node.foo,node.foo.bar`, such that...
```
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
TRACING_CATEGORY_NODE2(foo, bar),
"baz", 1);
```
Would emit if trace events are enabled for categories: `node`,
`node.foo`, or `node.foo.bar`.
This allows a natural scoping down of what trace events a user
may want to receive. Enabling the `node` category would receive
everything Node.js produces.
PR-URL: https://github.com/nodejs/node/pull/19155
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
2018-03-05 14:46:19 -08:00
|
|
|
if (trace.cat !== 'node,node.async_hooks')
|
2017-07-17 16:47:12 -07:00
|
|
|
return false;
|
|
|
|
if (trace.name !== 'TIMERWRAP')
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}));
|
|
|
|
|
|
|
|
// JavaScript async_hooks trace events should be generated.
|
|
|
|
assert(traces.some((trace) => {
|
|
|
|
if (trace.pid !== proc.pid)
|
|
|
|
return false;
|
src: add tracing category macros
Adds `TRACING_CATEGORY_NODE`, `TRACING_CATEGORY_NODE1` and
`TRACING_CATEGORY_NODE2` helper macros for consistently building
trace event category strings. For instance,
`TRACING_CATEGORY_NODE2(foo, bar)` would generate the category
string `node,node.foo,node.foo.bar`, such that...
```
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
TRACING_CATEGORY_NODE2(foo, bar),
"baz", 1);
```
Would emit if trace events are enabled for categories: `node`,
`node.foo`, or `node.foo.bar`.
This allows a natural scoping down of what trace events a user
may want to receive. Enabling the `node` category would receive
everything Node.js produces.
PR-URL: https://github.com/nodejs/node/pull/19155
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
2018-03-05 14:46:19 -08:00
|
|
|
if (trace.cat !== 'node,node.async_hooks')
|
2017-07-17 16:47:12 -07:00
|
|
|
return false;
|
|
|
|
if (trace.name !== 'Timeout')
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}));
|
2017-11-24 16:08:47 +01:00
|
|
|
|
|
|
|
// Check args in init events
|
|
|
|
const initEvents = traces.filter((trace) => {
|
|
|
|
return (trace.ph === 'b' && !trace.name.includes('_CALLBACK'));
|
|
|
|
});
|
|
|
|
assert(initEvents.every((trace) => {
|
|
|
|
return (trace.args.executionAsyncId > 0 &&
|
|
|
|
trace.args.triggerAsyncId > 0);
|
|
|
|
}));
|
2017-07-17 16:47:12 -07:00
|
|
|
}));
|
|
|
|
}));
|