GeezerVison is showing github.com — trace_events: add process_name metadata · nodejs/node@c4d7413
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/node.cc +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2178,6 +2178,8 @@ static void ProcessTitleSetter(Local<Name> property, | 2178 | 2178 | Local<Value> value, | 2179 | 2179 | const PropertyCallbackInfo<void>& info) { | 2180 | 2180 | node::Utf8Value title(info.GetIsolate(), value); | | 2181 | + TRACE_EVENT_METADATA1("__metadata", "process_name", "name", | | 2182 | + TRACE_STR_COPY(*title)); | 2181 | 2183 | uv_set_process_title(*title); | 2182 | 2184 | } | 2183 | 2185 |
| @@ -4074,6 +4076,13 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, | 4074 | 4076 | Environment env(isolate_data, context, v8_platform.GetTracingAgent()); | 4075 | 4077 | env.Start(argc, argv, exec_argc, exec_argv, v8_is_profiling); | 4076 | 4078 |
| | 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 | + } | 4077 | 4086 | TRACE_EVENT_METADATA1("__metadata", "version", "node", NODE_VERSION_STRING); | 4078 | 4087 | TRACE_EVENT_METADATA1("__metadata", "thread_name", "name", | 4079 | 4088 | "JavaScriptMainThread"); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-trace-events-metadata.js +12-1Lines changed: 12 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,7 +8,8 @@ if (!common.isMainThread) | 8 | 8 | common.skip('process.chdir is not available in Workers'); | 9 | 9 |
| 10 | 10 | 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"'; | 12 | 13 | const FILE_NAME = 'node_trace.1.log'; | 13 | 14 |
| 14 | 15 | const tmpdir = require('../common/tmpdir'); | @@ -17,6 +18,7 @@ process.chdir(tmpdir.path); | 17 | 18 |
| 18 | 19 | const proc = cp.spawn(process.execPath, | 19 | 20 | [ '--trace-event-categories', 'node.perf.usertiming', | | 21 | + '--title=bar', | 20 | 22 | '-e', CODE ]); | 21 | 23 | proc.once('exit', common.mustCall(() => { | 22 | 24 | assert(common.fileExists(FILE_NAME)); | @@ -32,5 +34,14 @@ proc.once('exit', common.mustCall(() => { | 32 | 34 | assert(traces.some((trace) => | 33 | 35 | trace.cat === '__metadata' && trace.name === 'version' && | 34 | 36 | 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 | + } | 35 | 46 | })); | 36 | 47 | })); |
|