Skip to content

Commit 6b8ed27

Browse files
theanarkhjuanarbol
authored andcommittedOct 11, 2022
src: trace fs async api
PR-URL: #44057 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent a3bdd07 commit 6b8ed27

File tree

4 files changed

+585
-27
lines changed

4 files changed

+585
-27
lines changed
 

‎doc/api/tracing.md

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ The available categories are:
2626
* `node.net.native`: Enables capture of trace data for network.
2727
* `node.environment`: Enables capture of Node.js Environment milestones.
2828
* `node.fs.sync`: Enables capture of trace data for file system sync methods.
29+
* `node.fs_dir.sync`: Enables capture of trace data for file system sync
30+
directory methods.
31+
* `node.fs.async`: Enables capture of trace data for file system async methods.
32+
* `node.fs_dir.async`: Enables capture of trace data for file system async
33+
directory methods.
2934
* `node.perf`: Enables capture of [Performance API][] measurements.
3035
* `node.perf.usertiming`: Enables capture of only Performance API User Timing
3136
measures and marks.

‎src/node_dir.cc

+55-9
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,57 @@ using v8::Object;
4242
using v8::ObjectTemplate;
4343
using v8::Value;
4444

45+
static const char* get_dir_func_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+
4559
#define TRACE_NAME(name) "fs_dir.sync." #name
4660
#define GET_TRACE_ENABLED \
47-
(*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
48-
(TRACING_CATEGORY_NODE2(fs_dir, sync)) != 0)
61+
(*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( \
62+
TRACING_CATEGORY_NODE2(fs_dir, sync)) != 0)
4963
#define FS_DIR_SYNC_TRACE_BEGIN(syscall, ...) \
5064
if (GET_TRACE_ENABLED) \
51-
TRACE_EVENT_BEGIN(TRACING_CATEGORY_NODE2(fs_dir, sync), TRACE_NAME(syscall), \
52-
##__VA_ARGS__);
65+
TRACE_EVENT_BEGIN(TRACING_CATEGORY_NODE2(fs_dir, sync), \
66+
TRACE_NAME(syscall), \
67+
##__VA_ARGS__);
5368
#define FS_DIR_SYNC_TRACE_END(syscall, ...) \
5469
if (GET_TRACE_ENABLED) \
55-
TRACE_EVENT_END(TRACING_CATEGORY_NODE2(fs_dir, sync), TRACE_NAME(syscall), \
56-
##__VA_ARGS__);
70+
TRACE_EVENT_END(TRACING_CATEGORY_NODE2(fs_dir, sync), \
71+
TRACE_NAME(syscall), \
72+
##__VA_ARGS__);
73+
74+
#define FS_DIR_ASYNC_TRACE_BEGIN0(fs_type, id) \
75+
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(TRACING_CATEGORY_NODE2(fs_dir, async), \
76+
get_dir_func_name_by_type(fs_type), \
77+
id);
78+
#define FS_DIR_ASYNC_TRACE_END0(fs_type, id) \
79+
TRACE_EVENT_NESTABLE_ASYNC_END0(TRACING_CATEGORY_NODE2(fs_dir, async), \
80+
get_dir_func_name_by_type(fs_type), \
81+
id);
82+
83+
#define FS_DIR_ASYNC_TRACE_BEGIN1(fs_type, id, name, value) \
84+
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(TRACING_CATEGORY_NODE2(fs_dir, async), \
85+
get_dir_func_name_by_type(fs_type), \
86+
id, \
87+
name, \
88+
value);
89+
90+
#define FS_DIR_ASYNC_TRACE_END1(fs_type, id, name, value) \
91+
TRACE_EVENT_NESTABLE_ASYNC_END1(TRACING_CATEGORY_NODE2(fs_dir, async), \
92+
get_dir_func_name_by_type(fs_type), \
93+
id, \
94+
name, \
95+
value);
5796

5897
DirHandle::DirHandle(Environment* env, Local<Object> obj, uv_dir_t* dir)
5998
: AsyncWrap(env, obj, AsyncWrap::PROVIDER_DIRHANDLE),
@@ -132,7 +171,8 @@ inline void DirHandle::GCClose() {
132171
void AfterClose(uv_fs_t* req) {
133172
FSReqBase* req_wrap = FSReqBase::from_req(req);
134173
FSReqAfterScope after(req_wrap, req);
135-
174+
FS_DIR_ASYNC_TRACE_END1(
175+
req->fs_type, req_wrap, "result", static_cast<int>(req->result))
136176
if (after.Proceed())
137177
req_wrap->Resolve(Undefined(req_wrap->env()->isolate()));
138178
}
@@ -151,6 +191,7 @@ void DirHandle::Close(const FunctionCallbackInfo<Value>& args) {
151191

152192
FSReqBase* req_wrap_async = GetReqWrap(args, 0);
153193
if (req_wrap_async != nullptr) { // close(req)
194+
FS_DIR_ASYNC_TRACE_BEGIN0(UV_FS_CLOSEDIR, req_wrap_async)
154195
AsyncCall(env, req_wrap_async, args, "closedir", UTF8, AfterClose,
155196
uv_fs_closedir, dir->dir());
156197
} else { // close(undefined, ctx)
@@ -196,7 +237,8 @@ static MaybeLocal<Array> DirentListToArray(
196237
static void AfterDirRead(uv_fs_t* req) {
197238
BaseObjectPtr<FSReqBase> req_wrap { FSReqBase::from_req(req) };
198239
FSReqAfterScope after(req_wrap.get(), req);
199-
240+
FS_DIR_ASYNC_TRACE_END1(
241+
req->fs_type, req_wrap, "result", static_cast<int>(req->result))
200242
if (!after.Proceed()) {
201243
return;
202244
}
@@ -256,6 +298,7 @@ void DirHandle::Read(const FunctionCallbackInfo<Value>& args) {
256298

257299
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
258300
if (req_wrap_async != nullptr) { // dir.read(encoding, bufferSize, req)
301+
FS_DIR_ASYNC_TRACE_BEGIN0(UV_FS_READDIR, req_wrap_async)
259302
AsyncCall(env, req_wrap_async, args, "readdir", encoding,
260303
AfterDirRead, uv_fs_readdir, dir->dir());
261304
} else { // dir.read(encoding, bufferSize, undefined, ctx)
@@ -298,7 +341,8 @@ void DirHandle::Read(const FunctionCallbackInfo<Value>& args) {
298341
void AfterOpenDir(uv_fs_t* req) {
299342
FSReqBase* req_wrap = FSReqBase::from_req(req);
300343
FSReqAfterScope after(req_wrap, req);
301-
344+
FS_DIR_ASYNC_TRACE_END1(
345+
req->fs_type, req_wrap, "result", static_cast<int>(req->result))
302346
if (!after.Proceed()) {
303347
return;
304348
}
@@ -325,6 +369,8 @@ static void OpenDir(const FunctionCallbackInfo<Value>& args) {
325369

326370
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
327371
if (req_wrap_async != nullptr) { // openDir(path, encoding, req)
372+
FS_DIR_ASYNC_TRACE_BEGIN1(
373+
UV_FS_OPENDIR, req_wrap_async, "path", TRACE_STR_COPY(*path))
328374
AsyncCall(env, req_wrap_async, args, "opendir", encoding, AfterOpenDir,
329375
uv_fs_opendir, *path);
330376
} else { // openDir(path, encoding, undefined, ctx)

‎src/node_file.cc

+184-18
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,104 @@ inline int64_t GetOffset(Local<Value> value) {
111111
return IsSafeJsInt(value) ? value.As<Integer>()->Value() : -1;
112112
}
113113

114+
static const char* get_fs_func_name_by_type(uv_fs_type req_type) {
115+
switch (req_type) {
116+
#define FS_TYPE_TO_NAME(type, name) \
117+
case UV_FS_##type: \
118+
return name;
119+
FS_TYPE_TO_NAME(OPEN, "open")
120+
FS_TYPE_TO_NAME(CLOSE, "close")
121+
FS_TYPE_TO_NAME(READ, "read")
122+
FS_TYPE_TO_NAME(WRITE, "write")
123+
FS_TYPE_TO_NAME(SENDFILE, "sendfile")
124+
FS_TYPE_TO_NAME(STAT, "stat")
125+
FS_TYPE_TO_NAME(LSTAT, "lstat")
126+
FS_TYPE_TO_NAME(FSTAT, "fstat")
127+
FS_TYPE_TO_NAME(FTRUNCATE, "ftruncate")
128+
FS_TYPE_TO_NAME(UTIME, "utime")
129+
FS_TYPE_TO_NAME(FUTIME, "futime")
130+
FS_TYPE_TO_NAME(ACCESS, "access")
131+
FS_TYPE_TO_NAME(CHMOD, "chmod")
132+
FS_TYPE_TO_NAME(FCHMOD, "fchmod")
133+
FS_TYPE_TO_NAME(FSYNC, "fsync")
134+
FS_TYPE_TO_NAME(FDATASYNC, "fdatasync")
135+
FS_TYPE_TO_NAME(UNLINK, "unlink")
136+
FS_TYPE_TO_NAME(RMDIR, "rmdir")
137+
FS_TYPE_TO_NAME(MKDIR, "mkdir")
138+
FS_TYPE_TO_NAME(MKDTEMP, "mkdtemp")
139+
FS_TYPE_TO_NAME(RENAME, "rename")
140+
FS_TYPE_TO_NAME(SCANDIR, "scandir")
141+
FS_TYPE_TO_NAME(LINK, "link")
142+
FS_TYPE_TO_NAME(SYMLINK, "symlink")
143+
FS_TYPE_TO_NAME(READLINK, "readlink")
144+
FS_TYPE_TO_NAME(CHOWN, "chown")
145+
FS_TYPE_TO_NAME(FCHOWN, "fchown")
146+
FS_TYPE_TO_NAME(REALPATH, "realpath")
147+
FS_TYPE_TO_NAME(COPYFILE, "copyfile")
148+
FS_TYPE_TO_NAME(LCHOWN, "lchown")
149+
FS_TYPE_TO_NAME(STATFS, "statfs")
150+
FS_TYPE_TO_NAME(MKSTEMP, "mkstemp")
151+
FS_TYPE_TO_NAME(LUTIME, "lutime")
152+
#undef FS_TYPE_TO_NAME
153+
default:
154+
return "unknow";
155+
}
156+
}
157+
114158
#define TRACE_NAME(name) "fs.sync." #name
115-
#define GET_TRACE_ENABLED \
116-
(*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
117-
(TRACING_CATEGORY_NODE2(fs, sync)) != 0)
118-
#define FS_SYNC_TRACE_BEGIN(syscall, ...) \
119-
if (GET_TRACE_ENABLED) \
120-
TRACE_EVENT_BEGIN(TRACING_CATEGORY_NODE2(fs, sync), TRACE_NAME(syscall), \
121-
##__VA_ARGS__);
122-
#define FS_SYNC_TRACE_END(syscall, ...) \
123-
if (GET_TRACE_ENABLED) \
124-
TRACE_EVENT_END(TRACING_CATEGORY_NODE2(fs, sync), TRACE_NAME(syscall), \
125-
##__VA_ARGS__);
159+
#define GET_TRACE_ENABLED \
160+
(*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( \
161+
TRACING_CATEGORY_NODE2(fs, sync)) != 0)
162+
#define FS_SYNC_TRACE_BEGIN(syscall, ...) \
163+
if (GET_TRACE_ENABLED) \
164+
TRACE_EVENT_BEGIN( \
165+
TRACING_CATEGORY_NODE2(fs, sync), TRACE_NAME(syscall), ##__VA_ARGS__);
166+
#define FS_SYNC_TRACE_END(syscall, ...) \
167+
if (GET_TRACE_ENABLED) \
168+
TRACE_EVENT_END( \
169+
TRACING_CATEGORY_NODE2(fs, sync), TRACE_NAME(syscall), ##__VA_ARGS__);
170+
171+
#define FS_ASYNC_TRACE_BEGIN0(fs_type, id) \
172+
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(TRACING_CATEGORY_NODE2(fs, async), \
173+
get_fs_func_name_by_type(fs_type), \
174+
id);
175+
176+
#define FS_ASYNC_TRACE_END0(fs_type, id) \
177+
TRACE_EVENT_NESTABLE_ASYNC_END0(TRACING_CATEGORY_NODE2(fs, async), \
178+
get_fs_func_name_by_type(fs_type), \
179+
id);
180+
181+
#define FS_ASYNC_TRACE_BEGIN1(fs_type, id, name, value) \
182+
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(TRACING_CATEGORY_NODE2(fs, async), \
183+
get_fs_func_name_by_type(fs_type), \
184+
id, \
185+
name, \
186+
value);
187+
188+
#define FS_ASYNC_TRACE_END1(fs_type, id, name, value) \
189+
TRACE_EVENT_NESTABLE_ASYNC_END1(TRACING_CATEGORY_NODE2(fs, async), \
190+
get_fs_func_name_by_type(fs_type), \
191+
id, \
192+
name, \
193+
value);
194+
195+
#define FS_ASYNC_TRACE_BEGIN2(fs_type, id, name1, value1, name2, value2) \
196+
TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(TRACING_CATEGORY_NODE2(fs, async), \
197+
get_fs_func_name_by_type(fs_type), \
198+
id, \
199+
name1, \
200+
value1, \
201+
name2, \
202+
value2);
203+
204+
#define FS_ASYNC_TRACE_END2(fs_type, id, name1, value1, name2, value2) \
205+
TRACE_EVENT_NESTABLE_ASYNC_END2(TRACING_CATEGORY_NODE2(fs, async), \
206+
get_fs_func_name_by_type(fs_type), \
207+
id, \
208+
name1, \
209+
value1, \
210+
name2, \
211+
value2);
126212

127213
// We sometimes need to convert a C++ lambda function to a raw C-style function.
128214
// This is helpful, because ReqWrap::Dispatch() does not recognize lambda
@@ -665,15 +751,17 @@ bool FSReqAfterScope::Proceed() {
665751
void AfterNoArgs(uv_fs_t* req) {
666752
FSReqBase* req_wrap = FSReqBase::from_req(req);
667753
FSReqAfterScope after(req_wrap, req);
668-
754+
FS_ASYNC_TRACE_END1(
755+
req->fs_type, req_wrap, "result", static_cast<int>(req->result))
669756
if (after.Proceed())
670757
req_wrap->Resolve(Undefined(req_wrap->env()->isolate()));
671758
}
672759

673760
void AfterStat(uv_fs_t* req) {
674761
FSReqBase* req_wrap = FSReqBase::from_req(req);
675762
FSReqAfterScope after(req_wrap, req);
676-
763+
FS_ASYNC_TRACE_END1(
764+
req->fs_type, req_wrap, "result", static_cast<int>(req->result))
677765
if (after.Proceed()) {
678766
req_wrap->ResolveStat(&req->statbuf);
679767
}
@@ -682,7 +770,8 @@ void AfterStat(uv_fs_t* req) {
682770
void AfterInteger(uv_fs_t* req) {
683771
FSReqBase* req_wrap = FSReqBase::from_req(req);
684772
FSReqAfterScope after(req_wrap, req);
685-
773+
FS_ASYNC_TRACE_END1(
774+
req->fs_type, req_wrap, "result", static_cast<int>(req->result))
686775
int result = static_cast<int>(req->result);
687776
if (result >= 0 && req_wrap->is_plain_open())
688777
req_wrap->env()->AddUnmanagedFd(result);
@@ -694,7 +783,8 @@ void AfterInteger(uv_fs_t* req) {
694783
void AfterOpenFileHandle(uv_fs_t* req) {
695784
FSReqBase* req_wrap = FSReqBase::from_req(req);
696785
FSReqAfterScope after(req_wrap, req);
697-
786+
FS_ASYNC_TRACE_END1(
787+
req->fs_type, req_wrap, "result", static_cast<int>(req->result))
698788
if (after.Proceed()) {
699789
FileHandle* fd = FileHandle::New(req_wrap->binding_data(),
700790
static_cast<int>(req->result));
@@ -719,6 +809,8 @@ void FromNamespacedPath(std::string* path) {
719809
void AfterMkdirp(uv_fs_t* req) {
720810
FSReqBase* req_wrap = FSReqBase::from_req(req);
721811
FSReqAfterScope after(req_wrap, req);
812+
FS_ASYNC_TRACE_END1(
813+
req->fs_type, req_wrap, "result", static_cast<int>(req->result))
722814
if (after.Proceed()) {
723815
std::string first_path(req_wrap->continuation_data()->first_path());
724816
if (first_path.empty())
@@ -738,7 +830,8 @@ void AfterMkdirp(uv_fs_t* req) {
738830
void AfterStringPath(uv_fs_t* req) {
739831
FSReqBase* req_wrap = FSReqBase::from_req(req);
740832
FSReqAfterScope after(req_wrap, req);
741-
833+
FS_ASYNC_TRACE_END1(
834+
req->fs_type, req_wrap, "result", static_cast<int>(req->result))
742835
MaybeLocal<Value> link;
743836
Local<Value> error;
744837

@@ -757,7 +850,8 @@ void AfterStringPath(uv_fs_t* req) {
757850
void AfterStringPtr(uv_fs_t* req) {
758851
FSReqBase* req_wrap = FSReqBase::from_req(req);
759852
FSReqAfterScope after(req_wrap, req);
760-
853+
FS_ASYNC_TRACE_END1(
854+
req->fs_type, req_wrap, "result", static_cast<int>(req->result))
761855
MaybeLocal<Value> link;
762856
Local<Value> error;
763857

@@ -776,7 +870,8 @@ void AfterStringPtr(uv_fs_t* req) {
776870
void AfterScanDir(uv_fs_t* req) {
777871
FSReqBase* req_wrap = FSReqBase::from_req(req);
778872
FSReqAfterScope after(req_wrap, req);
779-
873+
FS_ASYNC_TRACE_END1(
874+
req->fs_type, req_wrap, "result", static_cast<int>(req->result))
780875
if (!after.Proceed()) {
781876
return;
782877
}
@@ -837,6 +932,8 @@ void Access(const FunctionCallbackInfo<Value>& args) {
837932

838933
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
839934
if (req_wrap_async != nullptr) { // access(path, mode, req)
935+
FS_ASYNC_TRACE_BEGIN1(
936+
UV_FS_ACCESS, req_wrap_async, "path", TRACE_STR_COPY(*path))
840937
AsyncCall(env, req_wrap_async, args, "access", UTF8, AfterNoArgs,
841938
uv_fs_access, *path, mode);
842939
} else { // access(path, mode, undefined, ctx)
@@ -861,6 +958,7 @@ void Close(const FunctionCallbackInfo<Value>& args) {
861958

862959
FSReqBase* req_wrap_async = GetReqWrap(args, 1);
863960
if (req_wrap_async != nullptr) { // close(fd, req)
961+
FS_ASYNC_TRACE_BEGIN0(UV_FS_CLOSE, req_wrap_async)
864962
AsyncCall(env, req_wrap_async, args, "close", UTF8, AfterNoArgs,
865963
uv_fs_close, fd);
866964
} else { // close(fd, undefined, ctx)
@@ -1002,6 +1100,8 @@ static void Stat(const FunctionCallbackInfo<Value>& args) {
10021100
bool use_bigint = args[1]->IsTrue();
10031101
FSReqBase* req_wrap_async = GetReqWrap(args, 2, use_bigint);
10041102
if (req_wrap_async != nullptr) { // stat(path, use_bigint, req)
1103+
FS_ASYNC_TRACE_BEGIN1(
1104+
UV_FS_STAT, req_wrap_async, "path", TRACE_STR_COPY(*path))
10051105
AsyncCall(env, req_wrap_async, args, "stat", UTF8, AfterStat,
10061106
uv_fs_stat, *path);
10071107
} else { // stat(path, use_bigint, undefined, ctx)
@@ -1033,6 +1133,8 @@ static void LStat(const FunctionCallbackInfo<Value>& args) {
10331133
bool use_bigint = args[1]->IsTrue();
10341134
FSReqBase* req_wrap_async = GetReqWrap(args, 2, use_bigint);
10351135
if (req_wrap_async != nullptr) { // lstat(path, use_bigint, req)
1136+
FS_ASYNC_TRACE_BEGIN1(
1137+
UV_FS_LSTAT, req_wrap_async, "path", TRACE_STR_COPY(*path))
10361138
AsyncCall(env, req_wrap_async, args, "lstat", UTF8, AfterStat,
10371139
uv_fs_lstat, *path);
10381140
} else { // lstat(path, use_bigint, undefined, ctx)
@@ -1065,6 +1167,7 @@ static void FStat(const FunctionCallbackInfo<Value>& args) {
10651167
bool use_bigint = args[1]->IsTrue();
10661168
FSReqBase* req_wrap_async = GetReqWrap(args, 2, use_bigint);
10671169
if (req_wrap_async != nullptr) { // fstat(fd, use_bigint, req)
1170+
FS_ASYNC_TRACE_BEGIN0(UV_FS_FSTAT, req_wrap_async)
10681171
AsyncCall(env, req_wrap_async, args, "fstat", UTF8, AfterStat,
10691172
uv_fs_fstat, fd);
10701173
} else { // fstat(fd, use_bigint, undefined, ctx)
@@ -1100,6 +1203,12 @@ static void Symlink(const FunctionCallbackInfo<Value>& args) {
11001203

11011204
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
11021205
if (req_wrap_async != nullptr) { // symlink(target, path, flags, req)
1206+
FS_ASYNC_TRACE_BEGIN2(UV_FS_SYMLINK,
1207+
req_wrap_async,
1208+
"target",
1209+
TRACE_STR_COPY(*target),
1210+
"path",
1211+
TRACE_STR_COPY(*path))
11031212
AsyncDestCall(env, req_wrap_async, args, "symlink", *path, path.length(),
11041213
UTF8, AfterNoArgs, uv_fs_symlink, *target, *path, flags);
11051214
} else { // symlink(target, path, flags, undefinec, ctx)
@@ -1127,6 +1236,12 @@ static void Link(const FunctionCallbackInfo<Value>& args) {
11271236

11281237
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
11291238
if (req_wrap_async != nullptr) { // link(src, dest, req)
1239+
FS_ASYNC_TRACE_BEGIN2(UV_FS_LINK,
1240+
req_wrap_async,
1241+
"src",
1242+
TRACE_STR_COPY(*src),
1243+
"dest",
1244+
TRACE_STR_COPY(*dest))
11301245
AsyncDestCall(env, req_wrap_async, args, "link", *dest, dest.length(), UTF8,
11311246
AfterNoArgs, uv_fs_link, *src, *dest);
11321247
} else { // link(src, dest)
@@ -1153,6 +1268,8 @@ static void ReadLink(const FunctionCallbackInfo<Value>& args) {
11531268

11541269
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
11551270
if (req_wrap_async != nullptr) { // readlink(path, encoding, req)
1271+
FS_ASYNC_TRACE_BEGIN1(
1272+
UV_FS_READLINK, req_wrap_async, "path", TRACE_STR_COPY(*path))
11561273
AsyncCall(env, req_wrap_async, args, "readlink", encoding, AfterStringPtr,
11571274
uv_fs_readlink, *path);
11581275
} else {
@@ -1196,6 +1313,12 @@ static void Rename(const FunctionCallbackInfo<Value>& args) {
11961313

11971314
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
11981315
if (req_wrap_async != nullptr) {
1316+
FS_ASYNC_TRACE_BEGIN2(UV_FS_RENAME,
1317+
req_wrap_async,
1318+
"old_path",
1319+
TRACE_STR_COPY(*old_path),
1320+
"new_path",
1321+
TRACE_STR_COPY(*new_path))
11991322
AsyncDestCall(env, req_wrap_async, args, "rename", *new_path,
12001323
new_path.length(), UTF8, AfterNoArgs, uv_fs_rename,
12011324
*old_path, *new_path);
@@ -1223,6 +1346,7 @@ static void FTruncate(const FunctionCallbackInfo<Value>& args) {
12231346

12241347
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
12251348
if (req_wrap_async != nullptr) {
1349+
FS_ASYNC_TRACE_BEGIN0(UV_FS_FTRUNCATE, req_wrap_async)
12261350
AsyncCall(env, req_wrap_async, args, "ftruncate", UTF8, AfterNoArgs,
12271351
uv_fs_ftruncate, fd, len);
12281352
} else {
@@ -1246,6 +1370,7 @@ static void Fdatasync(const FunctionCallbackInfo<Value>& args) {
12461370

12471371
FSReqBase* req_wrap_async = GetReqWrap(args, 1);
12481372
if (req_wrap_async != nullptr) {
1373+
FS_ASYNC_TRACE_BEGIN0(UV_FS_FDATASYNC, req_wrap_async)
12491374
AsyncCall(env, req_wrap_async, args, "fdatasync", UTF8, AfterNoArgs,
12501375
uv_fs_fdatasync, fd);
12511376
} else {
@@ -1268,6 +1393,7 @@ static void Fsync(const FunctionCallbackInfo<Value>& args) {
12681393

12691394
FSReqBase* req_wrap_async = GetReqWrap(args, 1);
12701395
if (req_wrap_async != nullptr) {
1396+
FS_ASYNC_TRACE_BEGIN0(UV_FS_FSYNC, req_wrap_async)
12711397
AsyncCall(env, req_wrap_async, args, "fsync", UTF8, AfterNoArgs,
12721398
uv_fs_fsync, fd);
12731399
} else {
@@ -1290,6 +1416,8 @@ static void Unlink(const FunctionCallbackInfo<Value>& args) {
12901416

12911417
FSReqBase* req_wrap_async = GetReqWrap(args, 1);
12921418
if (req_wrap_async != nullptr) {
1419+
FS_ASYNC_TRACE_BEGIN1(
1420+
UV_FS_UNLINK, req_wrap_async, "path", TRACE_STR_COPY(*path))
12931421
AsyncCall(env, req_wrap_async, args, "unlink", UTF8, AfterNoArgs,
12941422
uv_fs_unlink, *path);
12951423
} else {
@@ -1312,6 +1440,8 @@ static void RMDir(const FunctionCallbackInfo<Value>& args) {
13121440

13131441
FSReqBase* req_wrap_async = GetReqWrap(args, 1); // rmdir(path, req)
13141442
if (req_wrap_async != nullptr) {
1443+
FS_ASYNC_TRACE_BEGIN1(
1444+
UV_FS_RMDIR, req_wrap_async, "path", TRACE_STR_COPY(*path))
13151445
AsyncCall(env, req_wrap_async, args, "rmdir", UTF8, AfterNoArgs,
13161446
uv_fs_rmdir, *path);
13171447
} else { // rmdir(path, undefined, ctx)
@@ -1523,6 +1653,8 @@ static void MKDir(const FunctionCallbackInfo<Value>& args) {
15231653

15241654
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
15251655
if (req_wrap_async != nullptr) { // mkdir(path, mode, req)
1656+
FS_ASYNC_TRACE_BEGIN1(
1657+
UV_FS_UNLINK, req_wrap_async, "path", TRACE_STR_COPY(*path))
15261658
AsyncCall(env, req_wrap_async, args, "mkdir", UTF8,
15271659
mkdirp ? AfterMkdirp : AfterNoArgs,
15281660
mkdirp ? MKDirpAsync : uv_fs_mkdir, *path, mode);
@@ -1569,6 +1701,8 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
15691701

15701702
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
15711703
if (req_wrap_async != nullptr) { // realpath(path, encoding, req)
1704+
FS_ASYNC_TRACE_BEGIN1(
1705+
UV_FS_REALPATH, req_wrap_async, "path", TRACE_STR_COPY(*path))
15721706
AsyncCall(env, req_wrap_async, args, "realpath", encoding, AfterStringPtr,
15731707
uv_fs_realpath, *path);
15741708
} else { // realpath(path, encoding, undefined, ctx)
@@ -1616,6 +1750,8 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
16161750
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
16171751
if (req_wrap_async != nullptr) { // readdir(path, encoding, withTypes, req)
16181752
req_wrap_async->set_with_file_types(with_types);
1753+
FS_ASYNC_TRACE_BEGIN1(
1754+
UV_FS_SCANDIR, req_wrap_async, "path", TRACE_STR_COPY(*path))
16191755
AsyncCall(env,
16201756
req_wrap_async,
16211757
args,
@@ -1707,6 +1843,8 @@ static void Open(const FunctionCallbackInfo<Value>& args) {
17071843
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
17081844
if (req_wrap_async != nullptr) { // open(path, flags, mode, req)
17091845
req_wrap_async->set_is_plain_open(true);
1846+
FS_ASYNC_TRACE_BEGIN1(
1847+
UV_FS_OPEN, req_wrap_async, "path", TRACE_STR_COPY(*path))
17101848
AsyncCall(env, req_wrap_async, args, "open", UTF8, AfterInteger,
17111849
uv_fs_open, *path, flags, mode);
17121850
} else { // open(path, flags, mode, undefined, ctx)
@@ -1740,6 +1878,8 @@ static void OpenFileHandle(const FunctionCallbackInfo<Value>& args) {
17401878

17411879
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
17421880
if (req_wrap_async != nullptr) { // openFileHandle(path, flags, mode, req)
1881+
FS_ASYNC_TRACE_BEGIN1(
1882+
UV_FS_OPEN, req_wrap_async, "path", TRACE_STR_COPY(*path))
17431883
AsyncCall(env, req_wrap_async, args, "open", UTF8, AfterOpenFileHandle,
17441884
uv_fs_open, *path, flags, mode);
17451885
} else { // openFileHandle(path, flags, mode, undefined, ctx)
@@ -1776,6 +1916,12 @@ static void CopyFile(const FunctionCallbackInfo<Value>& args) {
17761916

17771917
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
17781918
if (req_wrap_async != nullptr) { // copyFile(src, dest, flags, req)
1919+
FS_ASYNC_TRACE_BEGIN2(UV_FS_COPYFILE,
1920+
req_wrap_async,
1921+
"src",
1922+
TRACE_STR_COPY(*src),
1923+
"dest",
1924+
TRACE_STR_COPY(*dest))
17791925
AsyncDestCall(env, req_wrap_async, args, "copyfile",
17801926
*dest, dest.length(), UTF8, AfterNoArgs,
17811927
uv_fs_copyfile, *src, *dest, flags);
@@ -1832,6 +1978,7 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
18321978

18331979
FSReqBase* req_wrap_async = GetReqWrap(args, 5);
18341980
if (req_wrap_async != nullptr) { // write(fd, buffer, off, len, pos, req)
1981+
FS_ASYNC_TRACE_BEGIN0(UV_FS_WRITE, req_wrap_async)
18351982
AsyncCall(env, req_wrap_async, args, "write", UTF8, AfterInteger,
18361983
uv_fs_write, fd, &uvbuf, 1, pos);
18371984
} else { // write(fd, buffer, off, len, pos, undefined, ctx)
@@ -1877,6 +2024,7 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& args) {
18772024

18782025
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
18792026
if (req_wrap_async != nullptr) { // writeBuffers(fd, chunks, pos, req)
2027+
FS_ASYNC_TRACE_BEGIN0(UV_FS_WRITE, req_wrap_async)
18802028
AsyncCall(env, req_wrap_async, args, "write", UTF8, AfterInteger,
18812029
uv_fs_write, fd, *iovs, iovs.length(), pos);
18822030
} else { // writeBuffers(fd, chunks, pos, undefined, ctx)
@@ -1950,6 +2098,7 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
19502098
len = StringBytes::Write(isolate, *stack_buffer, len, args[1], enc);
19512099
stack_buffer.SetLengthAndZeroTerminate(len);
19522100
uv_buf_t uvbuf = uv_buf_init(*stack_buffer, len);
2101+
FS_ASYNC_TRACE_BEGIN0(UV_FS_WRITE, req_wrap_async)
19532102
int err = req_wrap_async->Dispatch(uv_fs_write,
19542103
fd,
19552104
&uvbuf,
@@ -2035,6 +2184,7 @@ static void Read(const FunctionCallbackInfo<Value>& args) {
20352184

20362185
FSReqBase* req_wrap_async = GetReqWrap(args, 5);
20372186
if (req_wrap_async != nullptr) { // read(fd, buffer, offset, len, pos, req)
2187+
FS_ASYNC_TRACE_BEGIN0(UV_FS_READ, req_wrap_async)
20382188
AsyncCall(env, req_wrap_async, args, "read", UTF8, AfterInteger,
20392189
uv_fs_read, fd, &uvbuf, 1, pos);
20402190
} else { // read(fd, buffer, offset, len, pos, undefined, ctx)
@@ -2081,6 +2231,7 @@ static void ReadBuffers(const FunctionCallbackInfo<Value>& args) {
20812231

20822232
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
20832233
if (req_wrap_async != nullptr) { // readBuffers(fd, buffers, pos, req)
2234+
FS_ASYNC_TRACE_BEGIN0(UV_FS_READ, req_wrap_async)
20842235
AsyncCall(env, req_wrap_async, args, "read", UTF8, AfterInteger,
20852236
uv_fs_read, fd, *iovs, iovs.length(), pos);
20862237
} else { // readBuffers(fd, buffers, undefined, ctx)
@@ -2112,6 +2263,8 @@ static void Chmod(const FunctionCallbackInfo<Value>& args) {
21122263

21132264
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
21142265
if (req_wrap_async != nullptr) { // chmod(path, mode, req)
2266+
FS_ASYNC_TRACE_BEGIN1(
2267+
UV_FS_CHMOD, req_wrap_async, "path", TRACE_STR_COPY(*path))
21152268
AsyncCall(env, req_wrap_async, args, "chmod", UTF8, AfterNoArgs,
21162269
uv_fs_chmod, *path, mode);
21172270
} else { // chmod(path, mode, undefined, ctx)
@@ -2142,6 +2295,7 @@ static void FChmod(const FunctionCallbackInfo<Value>& args) {
21422295

21432296
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
21442297
if (req_wrap_async != nullptr) { // fchmod(fd, mode, req)
2298+
FS_ASYNC_TRACE_BEGIN0(UV_FS_FCHMOD, req_wrap_async)
21452299
AsyncCall(env, req_wrap_async, args, "fchmod", UTF8, AfterNoArgs,
21462300
uv_fs_fchmod, fd, mode);
21472301
} else { // fchmod(fd, mode, undefined, ctx)
@@ -2175,6 +2329,8 @@ static void Chown(const FunctionCallbackInfo<Value>& args) {
21752329

21762330
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
21772331
if (req_wrap_async != nullptr) { // chown(path, uid, gid, req)
2332+
FS_ASYNC_TRACE_BEGIN1(
2333+
UV_FS_CHOWN, req_wrap_async, "path", TRACE_STR_COPY(*path))
21782334
AsyncCall(env, req_wrap_async, args, "chown", UTF8, AfterNoArgs,
21792335
uv_fs_chown, *path, uid, gid);
21802336
} else { // chown(path, uid, gid, undefined, ctx)
@@ -2208,6 +2364,7 @@ static void FChown(const FunctionCallbackInfo<Value>& args) {
22082364

22092365
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
22102366
if (req_wrap_async != nullptr) { // fchown(fd, uid, gid, req)
2367+
FS_ASYNC_TRACE_BEGIN0(UV_FS_FCHOWN, req_wrap_async)
22112368
AsyncCall(env, req_wrap_async, args, "fchown", UTF8, AfterNoArgs,
22122369
uv_fs_fchown, fd, uid, gid);
22132370
} else { // fchown(fd, uid, gid, undefined, ctx)
@@ -2238,6 +2395,8 @@ static void LChown(const FunctionCallbackInfo<Value>& args) {
22382395

22392396
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
22402397
if (req_wrap_async != nullptr) { // lchown(path, uid, gid, req)
2398+
FS_ASYNC_TRACE_BEGIN1(
2399+
UV_FS_LCHOWN, req_wrap_async, "path", TRACE_STR_COPY(*path))
22412400
AsyncCall(env, req_wrap_async, args, "lchown", UTF8, AfterNoArgs,
22422401
uv_fs_lchown, *path, uid, gid);
22432402
} else { // lchown(path, uid, gid, undefined, ctx)
@@ -2268,6 +2427,8 @@ static void UTimes(const FunctionCallbackInfo<Value>& args) {
22682427

22692428
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
22702429
if (req_wrap_async != nullptr) { // utimes(path, atime, mtime, req)
2430+
FS_ASYNC_TRACE_BEGIN1(
2431+
UV_FS_UTIME, req_wrap_async, "path", TRACE_STR_COPY(*path))
22712432
AsyncCall(env, req_wrap_async, args, "utime", UTF8, AfterNoArgs,
22722433
uv_fs_utime, *path, atime, mtime);
22732434
} else { // utimes(path, atime, mtime, undefined, ctx)
@@ -2297,6 +2458,7 @@ static void FUTimes(const FunctionCallbackInfo<Value>& args) {
22972458

22982459
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
22992460
if (req_wrap_async != nullptr) { // futimes(fd, atime, mtime, req)
2461+
FS_ASYNC_TRACE_BEGIN0(UV_FS_FUTIME, req_wrap_async)
23002462
AsyncCall(env, req_wrap_async, args, "futime", UTF8, AfterNoArgs,
23012463
uv_fs_futime, fd, atime, mtime);
23022464
} else { // futimes(fd, atime, mtime, undefined, ctx)
@@ -2326,6 +2488,8 @@ static void LUTimes(const FunctionCallbackInfo<Value>& args) {
23262488

23272489
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
23282490
if (req_wrap_async != nullptr) { // lutimes(path, atime, mtime, req)
2491+
FS_ASYNC_TRACE_BEGIN1(
2492+
UV_FS_LUTIME, req_wrap_async, "path", TRACE_STR_COPY(*path))
23292493
AsyncCall(env, req_wrap_async, args, "lutime", UTF8, AfterNoArgs,
23302494
uv_fs_lutime, *path, atime, mtime);
23312495
} else { // lutimes(path, atime, mtime, undefined, ctx)
@@ -2352,6 +2516,8 @@ static void Mkdtemp(const FunctionCallbackInfo<Value>& args) {
23522516

23532517
FSReqBase* req_wrap_async = GetReqWrap(args, 2);
23542518
if (req_wrap_async != nullptr) { // mkdtemp(tmpl, encoding, req)
2519+
FS_ASYNC_TRACE_BEGIN1(
2520+
UV_FS_MKDTEMP, req_wrap_async, "path", TRACE_STR_COPY(*tmpl))
23552521
AsyncCall(env, req_wrap_async, args, "mkdtemp", encoding, AfterStringPath,
23562522
uv_fs_mkdtemp, *tmpl);
23572523
} else { // mkdtemp(tmpl, encoding, undefined, ctx)
+341
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,341 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const cp = require('child_process');
5+
const fs = require('fs');
6+
const path = require('path');
7+
const util = require('util');
8+
9+
const tests = Object.create(null);
10+
11+
let gid = 1;
12+
let uid = 1;
13+
14+
if (!common.isWindows) {
15+
gid = process.getgid();
16+
uid = process.getuid();
17+
}
18+
19+
function wrapper(func, args) {
20+
return `(${func.toString()})(${JSON.stringify(args)})`;
21+
}
22+
23+
function access() {
24+
const fs = require('fs');
25+
fs.writeFileSync('fs0.txt', '123', 'utf8');
26+
fs.access('fs0.txt', () => {
27+
fs.unlinkSync('fs0.txt');
28+
});
29+
}
30+
31+
function chmod() {
32+
const fs = require('fs');
33+
fs.writeFileSync('fs1.txt', '123', 'utf8');
34+
fs.chmod('fs1.txt', 100, () => {
35+
fs.unlinkSync('fs1.txt');
36+
});
37+
}
38+
39+
function chown({ uid, gid }) {
40+
const fs = require('fs');
41+
fs.writeFileSync('fs2.txt', '123', 'utf8');
42+
fs.chown('fs2.txt', uid, gid, () => {
43+
fs.unlinkSync('fs2.txt');
44+
});
45+
}
46+
47+
function close() {
48+
const fs = require('fs');
49+
fs.writeFile('fs3.txt', '123', 'utf8', () => {
50+
fs.unlinkSync('fs3.txt');
51+
});
52+
}
53+
54+
function copyfile() {
55+
const fs = require('fs');
56+
fs.writeFileSync('fs4.txt', '123', 'utf8');
57+
fs.copyFile('fs4.txt', 'a.txt', () => {
58+
fs.unlinkSync('fs4.txt');
59+
fs.unlinkSync('a.txt');
60+
});
61+
}
62+
63+
function fchmod() {
64+
const fs = require('fs');
65+
fs.writeFileSync('fs5.txt', '123', 'utf8');
66+
const fd = fs.openSync('fs5.txt', 'r+');
67+
fs.fchmod(fd, 100, () => {
68+
fs.unlinkSync('fs5.txt');
69+
});
70+
}
71+
72+
function fchown({ uid, gid }) {
73+
const fs = require('fs');
74+
fs.writeFileSync('fs6.txt', '123', 'utf8');
75+
const fd = fs.openSync('fs6.txt', 'r+');
76+
fs.fchown(fd, uid, gid, () => {
77+
fs.unlinkSync('fs6.txt');
78+
});
79+
}
80+
81+
function fdatasync() {
82+
const fs = require('fs');
83+
fs.writeFileSync('fs7.txt', '123', 'utf8');
84+
const fd = fs.openSync('fs7.txt', 'r+');
85+
fs.fdatasync(fd, () => {
86+
fs.unlinkSync('fs7.txt');
87+
});
88+
}
89+
90+
function fstat() {
91+
const fs = require('fs');
92+
fs.writeFileSync('fs8.txt', '123', 'utf8');
93+
fs.readFile('fs8.txt', () => {
94+
fs.unlinkSync('fs8.txt');
95+
});
96+
}
97+
98+
function fsync() {
99+
const fs = require('fs');
100+
fs.writeFileSync('fs9.txt', '123', 'utf8');
101+
const fd = fs.openSync('fs9.txt', 'r+');
102+
fs.fsync(fd, () => {
103+
fs.unlinkSync('fs9.txt');
104+
});
105+
}
106+
107+
function ftruncate() {
108+
const fs = require('fs');
109+
fs.writeFileSync('fs10.txt', '123', 'utf8');
110+
const fd = fs.openSync('fs10.txt', 'r+');
111+
fs.ftruncate(fd, 1, () => {
112+
fs.unlinkSync('fs10.txt');
113+
});
114+
}
115+
116+
function futime() {
117+
const fs = require('fs');
118+
fs.writeFileSync('fs11.txt', '123', 'utf8');
119+
const fd = fs.openSync('fs11.txt', 'r+');
120+
fs.futimes(fd, 1, 1, () => {
121+
fs.unlinkSync('fs11.txt');
122+
});
123+
}
124+
125+
function lutime() {
126+
const fs = require('fs');
127+
fs.writeFileSync('fs111.txt', '123', 'utf8');
128+
fs.lutimes('fs111.txt', 1, 1, () => {
129+
fs.unlinkSync('fs111.txt');
130+
});
131+
}
132+
133+
function lchown({ uid, gid }) {
134+
const fs = require('fs');
135+
fs.writeFileSync('fs12.txt', '123', 'utf8');
136+
fs.lchown('fs12.txt', uid, gid, () => {
137+
fs.unlinkSync('fs12.txt');
138+
});
139+
}
140+
141+
function link() {
142+
const fs = require('fs');
143+
fs.writeFileSync('fs13.txt', '123', 'utf8');
144+
fs.link('fs13.txt', 'fs14.txt', () => {
145+
fs.unlinkSync('fs13.txt');
146+
fs.unlinkSync('fs14.txt');
147+
});
148+
}
149+
150+
function lstat() {
151+
const fs = require('fs');
152+
fs.writeFileSync('fs15.txt', '123', 'utf8');
153+
fs.lstat('fs15.txt', () => {
154+
fs.unlinkSync('fs15.txt');
155+
});
156+
}
157+
158+
function mkdir() {
159+
const fs = require('fs');
160+
fs.mkdir('fstemp0', () => {
161+
fs.rmdir('fstemp0', () => {});
162+
});
163+
}
164+
165+
function mktmp() {
166+
fs.mkdtemp('fstemp1', (err, fp) => {
167+
fs.rmdir(fp, () => {});
168+
});
169+
}
170+
171+
function open() {
172+
const fs = require('fs');
173+
fs.writeFile('fs16.txt', '123', 'utf8', () => {
174+
fs.unlinkSync('fs16.txt');
175+
});
176+
}
177+
178+
function read() {
179+
const fs = require('fs');
180+
fs.writeFileSync('fs17.txt', '123', 'utf8');
181+
fs.readFile('fs17.txt', () => {
182+
fs.unlinkSync('fs17.txt');
183+
});
184+
}
185+
186+
function readdir() {
187+
const fs = require('fs');
188+
fs.readdir('./', () => {});
189+
}
190+
191+
function opendir() {
192+
const fs = require('fs');
193+
fs.opendir('./', () => {});
194+
}
195+
196+
function realpath() {
197+
const fs = require('fs');
198+
fs.writeFileSync('fs18.txt', '123', 'utf8');
199+
fs.linkSync('fs18.txt', 'fs19.txt');
200+
fs.realpath.native('fs19.txt', () => {
201+
fs.unlinkSync('fs18.txt');
202+
fs.unlinkSync('fs19.txt');
203+
});
204+
}
205+
206+
function rename() {
207+
const fs = require('fs');
208+
fs.writeFileSync('fs20.txt', '123', 'utf8');
209+
fs.rename('fs20.txt', 'fs21.txt', () => {
210+
fs.unlinkSync('fs21.txt');
211+
});
212+
}
213+
214+
function rmdir() {
215+
const fs = require('fs');
216+
fs.mkdirSync('fstemp2');
217+
fs.rmdir('fstemp2', () => {});
218+
}
219+
220+
function stat() {
221+
const fs = require('fs');
222+
fs.writeFileSync('fs22.txt', '123', 'utf8');
223+
fs.stat('fs22.txt', () => {
224+
fs.unlinkSync('fs22.txt');
225+
});
226+
}
227+
228+
function unlink() {
229+
const fs = require('fs');
230+
fs.writeFileSync('fs23.txt', '123', 'utf8');
231+
fs.linkSync('fs23.txt', 'fs24.txt');
232+
fs.unlink('fs23.txt', () => {});
233+
fs.unlink('fs24.txt', () => {});
234+
}
235+
236+
function utime() {
237+
const fs = require('fs');
238+
fs.writeFileSync('fs25.txt', '123', 'utf8');
239+
fs.utimes('fs25.txt', 1, 1, () => {
240+
fs.unlinkSync('fs25.txt');
241+
});
242+
}
243+
244+
function write() {
245+
const fs = require('fs');
246+
fs.writeFile('fs26.txt', '123', 'utf8', () => {
247+
fs.unlinkSync('fs26.txt');
248+
});
249+
}
250+
251+
function symlink() {
252+
const fs = require('fs');
253+
fs.writeFileSync('fs27.txt', '123', 'utf8');
254+
fs.symlink('fs27.txt', 'fs28.txt', () => {
255+
fs.unlinkSync('fs27.txt');
256+
fs.unlinkSync('fs28.txt');
257+
});
258+
}
259+
260+
function readlink() {
261+
const fs = require('fs');
262+
fs.writeFileSync('fs29.txt', '123', 'utf8');
263+
fs.symlinkSync('fs29.txt', 'fs30.txt');
264+
fs.readlink('fs30.txt', () => {
265+
fs.unlinkSync('fs29.txt');
266+
fs.unlinkSync('fs30.txt');
267+
});
268+
}
269+
// The key defined in get_fs_name_by_type function in node_file.cc and node_dir.cc
270+
tests.access = wrapper(access);
271+
tests.chmod = wrapper(chmod);
272+
tests.chown = wrapper(chown, { uid, gid });
273+
tests.close = wrapper(close);
274+
tests.copyfile = wrapper(copyfile);
275+
tests.fchmod = wrapper(fchmod);
276+
tests.fchown = wrapper(fchown, { uid, gid });
277+
tests.fdatasync = wrapper(fdatasync);
278+
tests.fstat = wrapper(fstat);
279+
tests.fsync = wrapper(fsync);
280+
tests.ftruncate = wrapper(ftruncate);
281+
tests.futime = wrapper(futime);
282+
tests.lutime = wrapper(lutime);
283+
tests.lchown = wrapper(lchown, { uid, gid });
284+
tests.link = wrapper(link);
285+
tests.lstat = wrapper(lstat);
286+
tests.mkdir = wrapper(mkdir);
287+
tests.mkdtemp = wrapper(mktmp);
288+
tests.open = wrapper(open);
289+
tests.read = wrapper(read);
290+
tests.scandir = wrapper(readdir);
291+
tests.opendir = wrapper(opendir);
292+
tests.realpath = wrapper(realpath);
293+
tests.rename = wrapper(rename);
294+
tests.rmdir = wrapper(rmdir);
295+
tests.stat = wrapper(stat);
296+
tests.unlink = wrapper(unlink);
297+
tests.utime = wrapper(utime);
298+
tests.write = wrapper(write);
299+
300+
// On windows, we need permissions to test symlink and readlink.
301+
// We'll only try to run these tests if we have enough privileges.
302+
if (common.canCreateSymLink()) {
303+
tests.symlink = wrapper(symlink);
304+
tests.readlink = wrapper(readlink);
305+
}
306+
const tmpdir = require('../common/tmpdir');
307+
tmpdir.refresh();
308+
const traceFile = path.join(tmpdir.path, 'node_trace.1.log');
309+
310+
for (const tr in tests) {
311+
const proc = cp.spawnSync(process.execPath,
312+
[ '--trace-events-enabled',
313+
'--trace-event-categories', 'node.fs_dir.async,node.fs.async',
314+
'-e', tests[tr] ],
315+
{ cwd: tmpdir.path, encoding: 'utf8' });
316+
317+
// Make sure the operation is successful.
318+
// Don't use assert with a custom message here. Otherwise the
319+
// inspection in the message is done eagerly and wastes a lot of CPU
320+
// time.
321+
if (proc.status !== 0) {
322+
throw new Error(`${tr}:\n${util.inspect(proc)}`);
323+
}
324+
325+
// Confirm that trace log file is created.
326+
assert(fs.existsSync(traceFile));
327+
const data = fs.readFileSync(traceFile);
328+
const { traceEvents } = JSON.parse(data.toString());
329+
// Confirm that the data we want is produced
330+
const traces = traceEvents.filter((item) => {
331+
return [
332+
'node,node.fs,node.fs.async',
333+
'node,node.fs_dir,node.fs_dir.async',
334+
].includes(item.cat);
335+
});
336+
// Confirm that the data we want is produced
337+
assert(traces.length > 0);
338+
assert(traces.some((trace) => {
339+
return trace.name === tr;
340+
}));
341+
}

0 commit comments

Comments
 (0)
Please sign in to comment.