11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst cp = require('child_process');
51cb0ef41Sopenharmony_ciconst fs = require('fs');
61cb0ef41Sopenharmony_ciconst path = require('path');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst CODE =
91cb0ef41Sopenharmony_ci  'setTimeout(() => { for (let i = 0; i < 100000; i++) { "test" + i } }, 1);' +
101cb0ef41Sopenharmony_ci  'process.title = "foo"';
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
131cb0ef41Sopenharmony_citmpdir.refresh();
141cb0ef41Sopenharmony_ciconst FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciconst proc = cp.spawn(process.execPath,
171cb0ef41Sopenharmony_ci                      [ '--trace-event-categories', 'node.perf.usertiming',
181cb0ef41Sopenharmony_ci                        '--title=bar',
191cb0ef41Sopenharmony_ci                        '-e', CODE ],
201cb0ef41Sopenharmony_ci                      { cwd: tmpdir.path });
211cb0ef41Sopenharmony_ciproc.once('exit', common.mustCall(() => {
221cb0ef41Sopenharmony_ci  assert(fs.existsSync(FILE_NAME));
231cb0ef41Sopenharmony_ci  fs.readFile(FILE_NAME, common.mustCall((err, data) => {
241cb0ef41Sopenharmony_ci    const traces = JSON.parse(data.toString()).traceEvents
251cb0ef41Sopenharmony_ci      .filter((trace) => trace.cat === '__metadata');
261cb0ef41Sopenharmony_ci    assert(traces.length > 0);
271cb0ef41Sopenharmony_ci    assert(traces.some((trace) =>
281cb0ef41Sopenharmony_ci      trace.name === 'thread_name' &&
291cb0ef41Sopenharmony_ci        trace.args.name === 'JavaScriptMainThread'));
301cb0ef41Sopenharmony_ci    assert(traces.some((trace) =>
311cb0ef41Sopenharmony_ci      trace.name === 'thread_name' &&
321cb0ef41Sopenharmony_ci        trace.args.name === 'PlatformWorkerThread'));
331cb0ef41Sopenharmony_ci    assert(traces.some((trace) =>
341cb0ef41Sopenharmony_ci      trace.name === 'version' &&
351cb0ef41Sopenharmony_ci        trace.args.node === process.versions.node));
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci    assert(traces.some((trace) =>
381cb0ef41Sopenharmony_ci      trace.name === 'node' &&
391cb0ef41Sopenharmony_ci        trace.args.process.versions.http_parser ===
401cb0ef41Sopenharmony_ci          process.versions.http_parser &&
411cb0ef41Sopenharmony_ci        trace.args.process.versions.llhttp ===
421cb0ef41Sopenharmony_ci          process.versions.llhttp &&
431cb0ef41Sopenharmony_ci        trace.args.process.versions.node ===
441cb0ef41Sopenharmony_ci          process.versions.node &&
451cb0ef41Sopenharmony_ci        trace.args.process.versions.v8 ===
461cb0ef41Sopenharmony_ci          process.versions.v8 &&
471cb0ef41Sopenharmony_ci        trace.args.process.versions.uv ===
481cb0ef41Sopenharmony_ci          process.versions.uv &&
491cb0ef41Sopenharmony_ci        trace.args.process.versions.zlib ===
501cb0ef41Sopenharmony_ci          process.versions.zlib &&
511cb0ef41Sopenharmony_ci        trace.args.process.versions.ares ===
521cb0ef41Sopenharmony_ci          process.versions.ares &&
531cb0ef41Sopenharmony_ci        trace.args.process.versions.modules ===
541cb0ef41Sopenharmony_ci          process.versions.modules &&
551cb0ef41Sopenharmony_ci        trace.args.process.versions.nghttp2 ===
561cb0ef41Sopenharmony_ci          process.versions.nghttp2 &&
571cb0ef41Sopenharmony_ci        trace.args.process.versions.napi ===
581cb0ef41Sopenharmony_ci          process.versions.napi &&
591cb0ef41Sopenharmony_ci        trace.args.process.versions.openssl ===
601cb0ef41Sopenharmony_ci          process.versions.openssl &&
611cb0ef41Sopenharmony_ci        trace.args.process.arch === process.arch &&
621cb0ef41Sopenharmony_ci        trace.args.process.platform === process.platform &&
631cb0ef41Sopenharmony_ci        trace.args.process.release.name === process.release.name &&
641cb0ef41Sopenharmony_ci        (!process.release.lts ||
651cb0ef41Sopenharmony_ci          trace.args.process.release.lts === process.release.lts)));
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci    if (!common.isSunOS && !common.isIBMi) {
681cb0ef41Sopenharmony_ci      // Changing process.title is currently unsupported on SunOS/SmartOS
691cb0ef41Sopenharmony_ci      // and IBMi
701cb0ef41Sopenharmony_ci      assert(traces.some((trace) =>
711cb0ef41Sopenharmony_ci        trace.name === 'process_name' && trace.args.name === 'foo'));
721cb0ef41Sopenharmony_ci      assert(traces.some((trace) =>
731cb0ef41Sopenharmony_ci        trace.name === 'process_name' && trace.args.name === 'bar'));
741cb0ef41Sopenharmony_ci    }
751cb0ef41Sopenharmony_ci  }));
761cb0ef41Sopenharmony_ci}));
77