trace_events: add process_name metadata
PR-URL: https://github.com/nodejs/node/pull/21477 Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
1f1675817c
commit
67053568ee
@ -1665,6 +1665,8 @@ static void ProcessTitleSetter(Local<Name> property,
|
||||
Local<Value> value,
|
||||
const PropertyCallbackInfo<void>& info) {
|
||||
node::Utf8Value title(info.GetIsolate(), value);
|
||||
TRACE_EVENT_METADATA1("__metadata", "process_name", "name",
|
||||
TRACE_STR_COPY(*title));
|
||||
uv_set_process_title(*title);
|
||||
}
|
||||
|
||||
@ -3525,6 +3527,13 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data,
|
||||
Environment env(isolate_data, context, v8_platform.GetTracingAgent());
|
||||
env.Start(argc, argv, exec_argc, exec_argv, v8_is_profiling);
|
||||
|
||||
char name_buffer[512];
|
||||
if (uv_get_process_title(name_buffer, sizeof(name_buffer)) == 0) {
|
||||
// Only emit the metadata event if the title can be retrieved successfully.
|
||||
// Ignore it otherwise.
|
||||
TRACE_EVENT_METADATA1("__metadata", "process_name", "name",
|
||||
TRACE_STR_COPY(name_buffer));
|
||||
}
|
||||
TRACE_EVENT_METADATA1("__metadata", "version", "node", NODE_VERSION_STRING);
|
||||
TRACE_EVENT_METADATA1("__metadata", "thread_name", "name",
|
||||
"JavaScriptMainThread");
|
||||
|
@ -8,7 +8,8 @@ if (!common.isMainThread)
|
||||
common.skip('process.chdir is not available in Workers');
|
||||
|
||||
const CODE =
|
||||
'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)';
|
||||
'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1);' +
|
||||
'process.title = "foo"';
|
||||
const FILE_NAME = 'node_trace.1.log';
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
@ -17,6 +18,7 @@ process.chdir(tmpdir.path);
|
||||
|
||||
const proc = cp.spawn(process.execPath,
|
||||
[ '--trace-event-categories', 'node.perf.usertiming',
|
||||
'--title=bar',
|
||||
'-e', CODE ]);
|
||||
proc.once('exit', common.mustCall(() => {
|
||||
assert(common.fileExists(FILE_NAME));
|
||||
@ -32,5 +34,14 @@ proc.once('exit', common.mustCall(() => {
|
||||
assert(traces.some((trace) =>
|
||||
trace.cat === '__metadata' && trace.name === 'version' &&
|
||||
trace.args.node === process.versions.node));
|
||||
if (!common.isSunOS) {
|
||||
// Changing process.title is currently unsupported on SunOS/SmartOS
|
||||
assert(traces.some((trace) =>
|
||||
trace.cat === '__metadata' && trace.name === 'process_name' &&
|
||||
trace.args.name === 'foo'));
|
||||
assert(traces.some((trace) =>
|
||||
trace.cat === '__metadata' && trace.name === 'process_name' &&
|
||||
trace.args.name === 'bar'));
|
||||
}
|
||||
}));
|
||||
}));
|
||||
|
Loading…
x
Reference in New Issue
Block a user