Skip to content

Commit

Permalink
trace_events: add process_name metadata
Browse files Browse the repository at this point in the history
PR-URL: nodejs#21477
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
jasnell committed Jul 10, 2018
1 parent 1f16758 commit 6705356
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/node.cc
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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");
Expand Down
13 changes: 12 additions & 1 deletion test/parallel/test-trace-events-metadata.js
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'));
}
}));
}));

0 comments on commit 6705356

Please sign in to comment.