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 { isMainThread } = require('worker_threads'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciif (isMainThread) { 91cb0ef41Sopenharmony_ci const CODE = 'const { Worker } = require(\'worker_threads\'); ' + 101cb0ef41Sopenharmony_ci `new Worker(${JSON.stringify(__filename)}, { name: 'foo' })`; 111cb0ef41Sopenharmony_ci const FILE_NAME = 'node_trace.1.log'; 121cb0ef41Sopenharmony_ci const tmpdir = require('../common/tmpdir'); 131cb0ef41Sopenharmony_ci tmpdir.refresh(); 141cb0ef41Sopenharmony_ci process.chdir(tmpdir.path); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci const proc = cp.spawn(process.execPath, 171cb0ef41Sopenharmony_ci [ '--trace-event-categories', 'node', 181cb0ef41Sopenharmony_ci '-e', CODE ]); 191cb0ef41Sopenharmony_ci proc.once('exit', common.mustCall(() => { 201cb0ef41Sopenharmony_ci assert(fs.existsSync(FILE_NAME)); 211cb0ef41Sopenharmony_ci fs.readFile(FILE_NAME, common.mustCall((err, data) => { 221cb0ef41Sopenharmony_ci const traces = JSON.parse(data.toString()).traceEvents; 231cb0ef41Sopenharmony_ci assert(traces.length > 0); 241cb0ef41Sopenharmony_ci assert(traces.some((trace) => 251cb0ef41Sopenharmony_ci trace.cat === '__metadata' && trace.name === 'thread_name' && 261cb0ef41Sopenharmony_ci trace.args.name === '[worker 1] foo')); 271cb0ef41Sopenharmony_ci })); 281cb0ef41Sopenharmony_ci })); 291cb0ef41Sopenharmony_ci} else { 301cb0ef41Sopenharmony_ci // Do nothing here. 311cb0ef41Sopenharmony_ci} 32