• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const cp = require('child_process');
5const fs = require('fs');
6const path = require('path');
7
8const CODE = `
9  const { internalBinding } = require('internal/test/binding');
10  const { trace } = internalBinding('trace_events');
11  trace('b'.charCodeAt(0), 'custom',
12        'type-value', 10, {'extra-value': 20 });
13  trace('b'.charCodeAt(0), 'custom',
14        'type-value', 20, {'first-value': 20, 'second-value': 30 });
15  trace('b'.charCodeAt(0), 'custom', 'type-value', 30);
16  trace('b'.charCodeAt(0), 'missing',
17        'type-value', 10, {'extra-value': 20 });
18`;
19
20const tmpdir = require('../common/tmpdir');
21tmpdir.refresh();
22const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
23
24const proc = cp.spawn(process.execPath,
25                      [ '--trace-event-categories', 'custom',
26                        '--no-warnings',
27                        '--expose-internals',
28                        '-e', CODE ],
29                      { cwd: tmpdir.path });
30
31proc.once('exit', common.mustCall(() => {
32  assert(fs.existsSync(FILE_NAME));
33  fs.readFile(FILE_NAME, common.mustCall((err, data) => {
34    const traces = JSON.parse(data.toString()).traceEvents
35      .filter((trace) => trace.cat !== '__metadata');
36    assert.strictEqual(traces.length, 3);
37
38    assert.strictEqual(traces[0].pid, proc.pid);
39    assert.strictEqual(traces[0].ph, 'b');
40    assert.strictEqual(traces[0].cat, 'custom');
41    assert.strictEqual(traces[0].name, 'type-value');
42    assert.strictEqual(traces[0].id, '0xa');
43    assert.deepStrictEqual(traces[0].args.data, { 'extra-value': 20 });
44
45    assert.strictEqual(traces[1].pid, proc.pid);
46    assert.strictEqual(traces[1].ph, 'b');
47    assert.strictEqual(traces[1].cat, 'custom');
48    assert.strictEqual(traces[1].name, 'type-value');
49    assert.strictEqual(traces[1].id, '0x14');
50    assert.deepStrictEqual(traces[1].args.data, {
51      'first-value': 20,
52      'second-value': 30
53    });
54
55    assert.strictEqual(traces[2].pid, proc.pid);
56    assert.strictEqual(traces[2].ph, 'b');
57    assert.strictEqual(traces[2].cat, 'custom');
58    assert.strictEqual(traces[2].name, 'type-value');
59    assert.strictEqual(traces[2].id, '0x1e');
60    assert.deepStrictEqual(traces[2].args, { });
61  }));
62}));
63