Skip to content

Commit c4d7413

Browse files
jasnelltargos
authored andcommitted
trace_events: add process_name metadata
PR-URL: #21477 Reviewed-By: Bradley Farias <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent f386c0a commit c4d7413

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/node.cc

+9
Original file line numberDiff line numberDiff line change
@@ -2178,6 +2178,8 @@ static void ProcessTitleSetter(Local<Name> property,
21782178
Local<Value> value,
21792179
const PropertyCallbackInfo<void>& info) {
21802180
node::Utf8Value title(info.GetIsolate(), value);
2181+
TRACE_EVENT_METADATA1("__metadata", "process_name", "name",
2182+
TRACE_STR_COPY(*title));
21812183
uv_set_process_title(*title);
21822184
}
21832185

@@ -4074,6 +4076,13 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data,
40744076
Environment env(isolate_data, context, v8_platform.GetTracingAgent());
40754077
env.Start(argc, argv, exec_argc, exec_argv, v8_is_profiling);
40764078

4079+
char name_buffer[512];
4080+
if (uv_get_process_title(name_buffer, sizeof(name_buffer)) == 0) {
4081+
// Only emit the metadata event if the title can be retrieved successfully.
4082+
// Ignore it otherwise.
4083+
TRACE_EVENT_METADATA1("__metadata", "process_name", "name",
4084+
TRACE_STR_COPY(name_buffer));
4085+
}
40774086
TRACE_EVENT_METADATA1("__metadata", "version", "node", NODE_VERSION_STRING);
40784087
TRACE_EVENT_METADATA1("__metadata", "thread_name", "name",
40794088
"JavaScriptMainThread");

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

+12-1
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)