@@ -42,19 +42,54 @@ using v8::Object;
42
42
using v8::ObjectTemplate;
43
43
using v8::Value;
44
44
45
+ static const char * get_fs_name_by_type (uv_fs_type req_type) {
46
+ switch (req_type) {
47
+ #define FS_TYPE_TO_NAME (type, name ) \
48
+ case UV_FS_##type: \
49
+ return name;
50
+ FS_TYPE_TO_NAME (OPENDIR, " opendir" )
51
+ FS_TYPE_TO_NAME (READDIR, " readdir" )
52
+ FS_TYPE_TO_NAME (CLOSEDIR, " closedir" )
53
+ #undef FS_TYPE_TO_NAME
54
+ default :
55
+ return " unknow" ;
56
+ }
57
+ }
58
+
45
59
#define TRACE_NAME (name ) " fs_dir.sync." #name
46
- #define GET_TRACE_ENABLED \
47
- (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
60
+ #define GET_TRACE_ENABLED \
61
+ (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
48
62
(TRACING_CATEGORY_NODE2(fs_dir, sync)) != 0 )
49
- #define FS_DIR_SYNC_TRACE_BEGIN (syscall, ...) \
50
- if (GET_TRACE_ENABLED) \
51
- TRACE_EVENT_BEGIN (TRACING_CATEGORY_NODE2(fs_dir, sync), TRACE_NAME(syscall), \
63
+ #define FS_DIR_SYNC_TRACE_BEGIN (syscall, ...) \
64
+ if (GET_TRACE_ENABLED) \
65
+ TRACE_EVENT_BEGIN (TRACING_CATEGORY_NODE2(fs_dir, sync), TRACE_NAME(syscall), \
52
66
##__VA_ARGS__);
53
- #define FS_DIR_SYNC_TRACE_END (syscall, ...) \
54
- if (GET_TRACE_ENABLED) \
55
- TRACE_EVENT_END (TRACING_CATEGORY_NODE2(fs_dir, sync), TRACE_NAME(syscall), \
67
+ #define FS_DIR_SYNC_TRACE_END (syscall, ...) \
68
+ if (GET_TRACE_ENABLED) \
69
+ TRACE_EVENT_END (TRACING_CATEGORY_NODE2(fs_dir, sync), TRACE_NAME(syscall), \
56
70
##__VA_ARGS__);
57
71
72
+ #define FS_ASYNC_TRACE_BEGIN0 (fs_type, id ) \
73
+ TRACE_EVENT_NESTABLE_ASYNC_BEGIN0 (TRACING_CATEGORY_NODE2(fs_dir, async), \
74
+ get_fs_name_by_type (fs_type), \
75
+ id);
76
+ #define FS_ASYNC_TRACE_END0 (fs_type, id ) \
77
+ TRACE_EVENT_NESTABLE_ASYNC_END0 (TRACING_CATEGORY_NODE2(fs_dir, async), \
78
+ get_fs_name_by_type (fs_type), \
79
+ id);
80
+
81
+ #define FS_ASYNC_TRACE_BEGIN1 (fs_type, id, ...) \
82
+ TRACE_EVENT_NESTABLE_ASYNC_BEGIN1 (TRACING_CATEGORY_NODE2(fs_dir, async), \
83
+ get_fs_name_by_type (fs_type), \
84
+ id, \
85
+ ##__VA_ARGS__);
86
+
87
+ #define FS_ASYNC_TRACE_END1 (fs_type, id, ...) \
88
+ TRACE_EVENT_NESTABLE_ASYNC_END1 (TRACING_CATEGORY_NODE2(fs_dir, async), \
89
+ get_fs_name_by_type (fs_type), \
90
+ id, \
91
+ ##__VA_ARGS__);
92
+
58
93
DirHandle::DirHandle (Environment* env, Local<Object> obj, uv_dir_t * dir)
59
94
: AsyncWrap(env, obj, AsyncWrap::PROVIDER_DIRHANDLE),
60
95
dir_ (dir) {
@@ -132,7 +167,8 @@ inline void DirHandle::GCClose() {
132
167
void AfterClose (uv_fs_t * req) {
133
168
FSReqBase* req_wrap = FSReqBase::from_req (req);
134
169
FSReqAfterScope after (req_wrap, req);
135
-
170
+ FS_ASYNC_TRACE_END1 (
171
+ req->fs_type , req_wrap, " result" , static_cast <int >(req->result ))
136
172
if (after.Proceed ())
137
173
req_wrap->Resolve (Undefined (req_wrap->env ()->isolate ()));
138
174
}
@@ -151,6 +187,7 @@ void DirHandle::Close(const FunctionCallbackInfo<Value>& args) {
151
187
152
188
FSReqBase* req_wrap_async = GetReqWrap (args, 0 );
153
189
if (req_wrap_async != nullptr ) { // close(req)
190
+ FS_ASYNC_TRACE_BEGIN0 (UV_FS_CLOSEDIR, req_wrap_async)
154
191
AsyncCall (env, req_wrap_async, args, " closedir" , UTF8, AfterClose,
155
192
uv_fs_closedir, dir->dir ());
156
193
} else { // close(undefined, ctx)
@@ -196,7 +233,8 @@ static MaybeLocal<Array> DirentListToArray(
196
233
static void AfterDirRead (uv_fs_t * req) {
197
234
BaseObjectPtr<FSReqBase> req_wrap { FSReqBase::from_req (req) };
198
235
FSReqAfterScope after (req_wrap.get (), req);
199
-
236
+ FS_ASYNC_TRACE_END1 (
237
+ req->fs_type , req_wrap, " result" , static_cast <int >(req->result ))
200
238
if (!after.Proceed ()) {
201
239
return ;
202
240
}
@@ -256,6 +294,7 @@ void DirHandle::Read(const FunctionCallbackInfo<Value>& args) {
256
294
257
295
FSReqBase* req_wrap_async = GetReqWrap (args, 2 );
258
296
if (req_wrap_async != nullptr ) { // dir.read(encoding, bufferSize, req)
297
+ FS_ASYNC_TRACE_BEGIN0 (UV_FS_READDIR, req_wrap_async)
259
298
AsyncCall (env, req_wrap_async, args, " readdir" , encoding,
260
299
AfterDirRead, uv_fs_readdir, dir->dir ());
261
300
} else { // dir.read(encoding, bufferSize, undefined, ctx)
@@ -298,7 +337,8 @@ void DirHandle::Read(const FunctionCallbackInfo<Value>& args) {
298
337
void AfterOpenDir (uv_fs_t * req) {
299
338
FSReqBase* req_wrap = FSReqBase::from_req (req);
300
339
FSReqAfterScope after (req_wrap, req);
301
-
340
+ FS_ASYNC_TRACE_END1 (
341
+ req->fs_type , req_wrap, " result" , static_cast <int >(req->result ))
302
342
if (!after.Proceed ()) {
303
343
return ;
304
344
}
@@ -325,6 +365,8 @@ static void OpenDir(const FunctionCallbackInfo<Value>& args) {
325
365
326
366
FSReqBase* req_wrap_async = GetReqWrap (args, 2 );
327
367
if (req_wrap_async != nullptr ) { // openDir(path, encoding, req)
368
+ FS_ASYNC_TRACE_BEGIN1 (
369
+ UV_FS_OPENDIR, req_wrap_async, " path" , TRACE_STR_COPY (*path))
328
370
AsyncCall (env, req_wrap_async, args, " opendir" , encoding, AfterOpenDir,
329
371
uv_fs_opendir, *path);
330
372
} else { // openDir(path, encoding, undefined, ctx)
0 commit comments