Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: trace sync api #48857

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions doc/api/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ The available categories are:
measures and marks.
* `node.perf.timerify`: Enables capture of only Performance API timerify
measurements.
* `node.process.sync`: Enables capture of trace data for the sync APIs of
process module.
* `node.promises.rejections`: Enables capture of trace data tracking the number
of unhandled Promise rejections and handled-after-rejections.
* `node.vm.script`: Enables capture of trace data for the `node:vm` module's
Expand Down
1 change: 1 addition & 0 deletions src/inspector/tracing_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ DispatchResponse TracingAgent::getCategories(
categories_list->emplace_back("node.perf");
categories_list->emplace_back("node.perf.timerify");
categories_list->emplace_back("node.perf.usertiming");
categories_list->emplace_back("node.process.sync");
categories_list->emplace_back("node.promises.rejections");
categories_list->emplace_back("node.threadpoolwork.async");
categories_list->emplace_back("node.threadpoolwork.sync");
Expand Down
14 changes: 14 additions & 0 deletions src/spawn_sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "node_external_reference.h"
#include "node_internals.h"
#include "string_bytes.h"
#include "tracing/trace_event.h"
#include "util-inl.h"

#include <cstring>
Expand Down Expand Up @@ -519,8 +520,21 @@ Maybe<bool> SyncProcessRunner::TryInitializeAndRunLoop(Local<Value> options) {
}
}
}
if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
TRACING_CATEGORY_NODE2(process, sync)) != 0) {
TRACE_EVENT_BEGIN1(TRACING_CATEGORY_NODE2(process, sync),
"spawnSync",
"file",
TRACE_STR_COPY(uv_process_options_.file));
}

r = uv_run(uv_loop_, UV_RUN_DEFAULT);

if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
TRACING_CATEGORY_NODE2(process, sync)) != 0) {
TRACE_EVENT_END0(TRACING_CATEGORY_NODE2(process, sync), "spawnSync");
}

if (r < 0)
// We can't handle uv_run failure.
ABORT();
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-inspector-tracing-domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async function test() {
'node.perf',
'node.perf.timerify',
'node.perf.usertiming',
'node.process.sync',
'node.promises.rejections',
'node.threadpoolwork.async',
'node.threadpoolwork.sync',
Expand Down
39 changes: 39 additions & 0 deletions test/parallel/test-trace-process-sync-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';
require('../common');
const assert = require('assert');
const cp = require('child_process');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');

if (process.env.isChild === '1') {
cp.execFileSync('node', ['-e', '']);
cp.execSync('node', ['-e', '']);
cp.spawnSync('node', ['-e', '']);
return;
}

tmpdir.refresh();
const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');

cp.spawnSync(process.execPath,
[
'--trace-events-enabled',
'--trace-event-categories', 'node.process.sync',
__filename,
],
{
cwd: tmpdir.path,
env: {
...process.env,
isChild: '1',
},
});

assert(fs.existsSync(FILE_NAME));
const data = fs.readFileSync(FILE_NAME);
const traces = JSON.parse(data.toString()).traceEvents;
assert(traces.length > 0);
const count = traces.filter((item) => item.name === 'spawnSync').length;
// Two begin, Two end
assert.strictEqual(count === 3 * 2, true);
Loading