• 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  'setTimeout(() => { for (let i = 0; i < 100000; i++) { "test" + i } }, 1);' +
10  'process.title = "foo"';
11
12const tmpdir = require('../common/tmpdir');
13tmpdir.refresh();
14const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
15
16const proc = cp.spawn(process.execPath,
17                      [ '--trace-event-categories', 'node.perf.usertiming',
18                        '--title=bar',
19                        '-e', CODE ],
20                      { cwd: tmpdir.path });
21proc.once('exit', common.mustCall(() => {
22  assert(fs.existsSync(FILE_NAME));
23  fs.readFile(FILE_NAME, common.mustCall((err, data) => {
24    const traces = JSON.parse(data.toString()).traceEvents
25      .filter((trace) => trace.cat === '__metadata');
26    assert(traces.length > 0);
27    assert(traces.some((trace) =>
28      trace.name === 'thread_name' &&
29        trace.args.name === 'JavaScriptMainThread'));
30    assert(traces.some((trace) =>
31      trace.name === 'thread_name' &&
32        trace.args.name === 'PlatformWorkerThread'));
33    assert(traces.some((trace) =>
34      trace.name === 'version' &&
35        trace.args.node === process.versions.node));
36
37    assert(traces.some((trace) =>
38      trace.name === 'node' &&
39        trace.args.process.versions.http_parser ===
40          process.versions.http_parser &&
41        trace.args.process.versions.llhttp ===
42          process.versions.llhttp &&
43        trace.args.process.versions.node ===
44          process.versions.node &&
45        trace.args.process.versions.v8 ===
46          process.versions.v8 &&
47        trace.args.process.versions.uv ===
48          process.versions.uv &&
49        trace.args.process.versions.zlib ===
50          process.versions.zlib &&
51        trace.args.process.versions.ares ===
52          process.versions.ares &&
53        trace.args.process.versions.modules ===
54          process.versions.modules &&
55        trace.args.process.versions.nghttp2 ===
56          process.versions.nghttp2 &&
57        trace.args.process.versions.napi ===
58          process.versions.napi &&
59        trace.args.process.versions.openssl ===
60          process.versions.openssl &&
61        trace.args.process.arch === process.arch &&
62        trace.args.process.platform === process.platform &&
63        trace.args.process.release.name === process.release.name &&
64        (!process.release.lts ||
65          trace.args.process.release.lts === process.release.lts)));
66
67    if (!common.isSunOS && !common.isIBMi) {
68      // Changing process.title is currently unsupported on SunOS/SmartOS
69      // and IBMi
70      assert(traces.some((trace) =>
71        trace.name === 'process_name' && trace.args.name === 'foo'));
72      assert(traces.some((trace) =>
73        trace.name === 'process_name' && trace.args.name === 'bar'));
74    }
75  }));
76}));
77