Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
trace_events: add process_name metadata
  • Loading branch information
jasnell committed Jun 25, 2018
commit 62efea91c0491b36766c05ed76b31397d2cdb753
9 changes: 9 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,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);
}

Expand Down Expand Up @@ -3528,6 +3530,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");
Expand Down
13 changes: 12 additions & 1 deletion test/parallel/test-trace-events-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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));
Expand All @@ -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'));
}
}));
}));