Skip to content

Commit 6705356

Browse files
committed
trace_events: add process_name metadata
PR-URL: #21477 Reviewed-By: Bradley Farias <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 1f16758 commit 6705356

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/node.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,8 @@ static void ProcessTitleSetter(Local<Name> property,
16651665
Local<Value> value,
16661666
const PropertyCallbackInfo<void>& info) {
16671667
node::Utf8Value title(info.GetIsolate(), value);
1668+
TRACE_EVENT_METADATA1("__metadata", "process_name", "name",
1669+
TRACE_STR_COPY(*title));
16681670
uv_set_process_title(*title);
16691671
}
16701672

@@ -3525,6 +3527,13 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data,
35253527
Environment env(isolate_data, context, v8_platform.GetTracingAgent());
35263528
env.Start(argc, argv, exec_argc, exec_argv, v8_is_profiling);
35273529

3530+
char name_buffer[512];
3531+
if (uv_get_process_title(name_buffer, sizeof(name_buffer)) == 0) {
3532+
// Only emit the metadata event if the title can be retrieved successfully.
3533+
// Ignore it otherwise.
3534+
TRACE_EVENT_METADATA1("__metadata", "process_name", "name",
3535+
TRACE_STR_COPY(name_buffer));
3536+
}
35283537
TRACE_EVENT_METADATA1("__metadata", "version", "node", NODE_VERSION_STRING);
35293538
TRACE_EVENT_METADATA1("__metadata", "thread_name", "name",
35303539
"JavaScriptMainThread");

test/parallel/test-trace-events-metadata.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ if (!common.isMainThread)
88
common.skip('process.chdir is not available in Workers');
99

1010
const CODE =
11-
'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)';
11+
'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1);' +
12+
'process.title = "foo"';
1213
const FILE_NAME = 'node_trace.1.log';
1314

1415
const tmpdir = require('../common/tmpdir');
@@ -17,6 +18,7 @@ process.chdir(tmpdir.path);
1718

1819
const proc = cp.spawn(process.execPath,
1920
[ '--trace-event-categories', 'node.perf.usertiming',
21+
'--title=bar',
2022
'-e', CODE ]);
2123
proc.once('exit', common.mustCall(() => {
2224
assert(common.fileExists(FILE_NAME));
@@ -32,5 +34,14 @@ proc.once('exit', common.mustCall(() => {
3234
assert(traces.some((trace) =>
3335
trace.cat === '__metadata' && trace.name === 'version' &&
3436
trace.args.node === process.versions.node));
37+
if (!common.isSunOS) {
38+
// Changing process.title is currently unsupported on SunOS/SmartOS
39+
assert(traces.some((trace) =>
40+
trace.cat === '__metadata' && trace.name === 'process_name' &&
41+
trace.args.name === 'foo'));
42+
assert(traces.some((trace) =>
43+
trace.cat === '__metadata' && trace.name === 'process_name' &&
44+
trace.args.name === 'bar'));
45+
}
3546
}));
3647
}));

0 commit comments

Comments
 (0)