Skip to content

Commit 7df69d5

Browse files
legendecasnodejs-github-bot
authored andcommitted
src: fix trace macro compatibility
Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net> PR-URL: #64565 Refs: nodejs/diagnostics#654 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ryuhei Shima <shimaryuhei@gmail.com>
1 parent 5022b94 commit 7df69d5

2 files changed

Lines changed: 33 additions & 26 deletions

File tree

src/node_dir.cc

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,10 @@ static const char* get_dir_func_name_by_type(uv_fs_type req_type) {
6363
#define GET_TRACE_ENABLED \
6464
(*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( \
6565
TRACING_CATEGORY_NODE2(fs_dir, sync)) != 0)
66-
#define FS_DIR_SYNC_TRACE_BEGIN(syscall, ...) \
67-
if (GET_TRACE_ENABLED) \
68-
TRACE_EVENT_BEGIN(TRACING_CATEGORY_NODE2(fs_dir, sync), \
69-
TRACE_NAME(syscall), \
70-
##__VA_ARGS__);
71-
#define FS_DIR_SYNC_TRACE_END(syscall, ...) \
72-
if (GET_TRACE_ENABLED) \
73-
TRACE_EVENT_END(TRACING_CATEGORY_NODE2(fs_dir, sync), \
74-
TRACE_NAME(syscall), \
75-
##__VA_ARGS__);
66+
#define FS_DIR_SYNC_TRACE(syscall) \
67+
if (GET_TRACE_ENABLED) { \
68+
TRACE_EVENT0(TRACING_CATEGORY_NODE2(fs_dir, sync), TRACE_NAME(syscall)); \
69+
}
7670

7771
#define FS_DIR_ASYNC_TRACE_BEGIN0(fs_type, id) \
7872
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(TRACING_CATEGORY_NODE2(fs_dir, async), \
@@ -138,9 +132,11 @@ void DirHandle::MemoryInfo(MemoryTracker* tracker) const {
138132
inline void DirHandle::GCClose() {
139133
if (closed_) return;
140134
uv_fs_t req;
141-
FS_DIR_SYNC_TRACE_BEGIN(closedir);
142-
int ret = uv_fs_closedir(nullptr, &req, dir_, nullptr);
143-
FS_DIR_SYNC_TRACE_END(closedir);
135+
int ret;
136+
{
137+
FS_DIR_SYNC_TRACE(closedir);
138+
ret = uv_fs_closedir(nullptr, &req, dir_, nullptr);
139+
}
144140
uv_fs_req_cleanup(&req);
145141
closing_ = false;
146142
closed_ = true;
@@ -201,9 +197,8 @@ void DirHandle::Close(const FunctionCallbackInfo<Value>& args) {
201197
uv_fs_closedir, dir->dir());
202198
} else { // close()
203199
FSReqWrapSync req_wrap_sync("closedir");
204-
FS_DIR_SYNC_TRACE_BEGIN(closedir);
200+
FS_DIR_SYNC_TRACE(closedir);
205201
SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_closedir, dir->dir());
206-
FS_DIR_SYNC_TRACE_END(closedir);
207202
}
208203
}
209204

@@ -299,10 +294,12 @@ void DirHandle::Read(const FunctionCallbackInfo<Value>& args) {
299294
AfterDirRead, uv_fs_readdir, dir->dir());
300295
} else { // dir.read(encoding, bufferSize)
301296
FSReqWrapSync req_wrap_sync("readdir");
302-
FS_DIR_SYNC_TRACE_BEGIN(readdir);
303-
int err =
304-
SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_readdir, dir->dir());
305-
FS_DIR_SYNC_TRACE_END(readdir);
297+
int err;
298+
{
299+
FS_DIR_SYNC_TRACE(readdir);
300+
err = SyncCallAndThrowOnError(
301+
env, &req_wrap_sync, uv_fs_readdir, dir->dir());
302+
}
306303
if (err < 0) {
307304
return; // syscall failed, no need to continue, error is already thrown
308305
}
@@ -377,10 +374,12 @@ static void OpenDir(const FunctionCallbackInfo<Value>& args) {
377374
THROW_IF_INSUFFICIENT_PERMISSIONS(
378375
env, permission::PermissionScope::kFileSystemRead, path.ToStringView());
379376
FSReqWrapSync req_wrap_sync("opendir", *path);
380-
FS_DIR_SYNC_TRACE_BEGIN(opendir);
381-
int result =
382-
SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_opendir, *path);
383-
FS_DIR_SYNC_TRACE_END(opendir);
377+
int result;
378+
{
379+
FS_DIR_SYNC_TRACE(opendir);
380+
result =
381+
SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_opendir, *path);
382+
}
384383
if (result < 0) {
385384
return; // syscall failed, no need to continue, error is already thrown
386385
}
@@ -407,9 +406,11 @@ static void OpenDirSync(const FunctionCallbackInfo<Value>& args) {
407406

408407
uv_fs_t req;
409408
auto make = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); });
410-
FS_DIR_SYNC_TRACE_BEGIN(opendir);
411-
int err = uv_fs_opendir(nullptr, &req, *path, nullptr);
412-
FS_DIR_SYNC_TRACE_END(opendir);
409+
int err;
410+
{
411+
FS_DIR_SYNC_TRACE(opendir);
412+
err = uv_fs_opendir(nullptr, &req, *path, nullptr);
413+
}
413414
if (err < 0) {
414415
return env->ThrowUVException(err, "opendir");
415416
}

src/node_file.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,16 @@ static const char* get_fs_func_name_by_type(uv_fs_type req_type) {
153153
if (GET_TRACE_ENABLED) \
154154
TRACE_EVENT_BEGIN( \
155155
TRACING_CATEGORY_NODE2(fs, sync), TRACE_NAME(syscall), ##__VA_ARGS__);
156+
#ifdef V8_USE_PERFETTO
157+
#define FS_SYNC_TRACE_END(syscall, ...) \
158+
if (GET_TRACE_ENABLED) \
159+
TRACE_EVENT_END(TRACING_CATEGORY_NODE2(fs, sync), ##__VA_ARGS__);
160+
#else
156161
#define FS_SYNC_TRACE_END(syscall, ...) \
157162
if (GET_TRACE_ENABLED) \
158163
TRACE_EVENT_END( \
159164
TRACING_CATEGORY_NODE2(fs, sync), TRACE_NAME(syscall), ##__VA_ARGS__);
165+
#endif
160166

161167
#define FS_ASYNC_TRACE_BEGIN0(fs_type, id) \
162168
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(TRACING_CATEGORY_NODE2(fs, async), \

0 commit comments

Comments
 (0)