24
24
#include " node_internals.h"
25
25
#include " node_stat_watcher.h"
26
26
#include " node_file.h"
27
+ #include " tracing/trace_event.h"
27
28
28
29
#include " req_wrap-inl.h"
29
30
#include " stream_base-inl.h"
@@ -75,6 +76,18 @@ using v8::Value;
75
76
#endif
76
77
77
78
#define GET_OFFSET (a ) ((a)->IsNumber () ? (a).As<Integer>()->Value() : -1)
79
+ #define TRACE_NAME (name ) " fs.sync." #name
80
+ #define GET_TRACE_ENABLED \
81
+ (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
82
+ (TRACING_CATEGORY_NODE2(fs, sync)) != 0 )
83
+ #define FS_SYNC_TRACE_BEGIN (syscall, ...) \
84
+ if (GET_TRACE_ENABLED) \
85
+ TRACE_EVENT_BEGIN (TRACING_CATEGORY_NODE2(fs, sync), TRACE_NAME(syscall), \
86
+ ##__VA_ARGS__);
87
+ #define FS_SYNC_TRACE_END (syscall, ...) \
88
+ if (GET_TRACE_ENABLED) \
89
+ TRACE_EVENT_END (TRACING_CATEGORY_NODE2(fs, sync), TRACE_NAME(syscall), \
90
+ ##__VA_ARGS__);
78
91
79
92
// The FileHandle object wraps a file descriptor and will close it on garbage
80
93
// collection if necessary. If that happens, a process warning will be
@@ -316,7 +329,7 @@ int FileHandle::ReadStart() {
316
329
317
330
// ReadStart() checks whether current_read_ is set to determine whether
318
331
// a read is in progress. Moving it into a local variable makes sure that
319
- // the ReadStart() call below doesn’ t think we’ re still actively reading.
332
+ // the ReadStart() call below doesn' t think we' re still actively reading.
320
333
std::unique_ptr<FileHandleReadWrap> read_wrap =
321
334
std::move (handle->current_read_ );
322
335
@@ -683,7 +696,9 @@ void Access(const FunctionCallbackInfo<Value>& args) {
683
696
} else { // access(path, mode, undefined, ctx)
684
697
CHECK_EQ (argc, 4 );
685
698
FSReqWrapSync req_wrap_sync;
699
+ FS_SYNC_TRACE_BEGIN (access);
686
700
SyncCall (env, args[3 ], &req_wrap_sync, " access" , uv_fs_access, *path, mode);
701
+ FS_SYNC_TRACE_END (access);
687
702
}
688
703
}
689
704
@@ -704,7 +719,9 @@ void Close(const FunctionCallbackInfo<Value>& args) {
704
719
} else { // close(fd, undefined, ctx)
705
720
CHECK_EQ (argc, 3 );
706
721
FSReqWrapSync req_wrap_sync;
722
+ FS_SYNC_TRACE_BEGIN (close);
707
723
SyncCall (env, args[2 ], &req_wrap_sync, " close" , uv_fs_close, fd);
724
+ FS_SYNC_TRACE_END (close);
708
725
}
709
726
}
710
727
@@ -812,7 +829,9 @@ static void Stat(const FunctionCallbackInfo<Value>& args) {
812
829
} else { // stat(path, undefined, ctx)
813
830
CHECK_EQ (argc, 3 );
814
831
FSReqWrapSync req_wrap_sync;
832
+ FS_SYNC_TRACE_BEGIN (stat);
815
833
int err = SyncCall (env, args[2 ], &req_wrap_sync, " stat" , uv_fs_stat, *path);
834
+ FS_SYNC_TRACE_END (stat);
816
835
if (err == 0 ) {
817
836
node::FillGlobalStatsArray (env,
818
837
static_cast <const uv_stat_t *>(req_wrap_sync.req .ptr ));
@@ -836,8 +855,10 @@ static void LStat(const FunctionCallbackInfo<Value>& args) {
836
855
} else { // lstat(path, undefined, ctx)
837
856
CHECK_EQ (argc, 3 );
838
857
FSReqWrapSync req_wrap_sync;
858
+ FS_SYNC_TRACE_BEGIN (lstat);
839
859
int err = SyncCall (env, args[2 ], &req_wrap_sync, " lstat" , uv_fs_lstat,
840
860
*path);
861
+ FS_SYNC_TRACE_END (lstat);
841
862
if (err == 0 ) {
842
863
node::FillGlobalStatsArray (env,
843
864
static_cast <const uv_stat_t *>(req_wrap_sync.req .ptr ));
@@ -861,7 +882,9 @@ static void FStat(const FunctionCallbackInfo<Value>& args) {
861
882
} else { // fstat(fd, undefined, ctx)
862
883
CHECK_EQ (argc, 3 );
863
884
FSReqWrapSync req_wrap_sync;
885
+ FS_SYNC_TRACE_BEGIN (fstat);
864
886
int err = SyncCall (env, args[2 ], &req_wrap_sync, " fstat" , uv_fs_fstat, fd);
887
+ FS_SYNC_TRACE_END (fstat);
865
888
if (err == 0 ) {
866
889
node::FillGlobalStatsArray (env,
867
890
static_cast <const uv_stat_t *>(req_wrap_sync.req .ptr ));
@@ -890,8 +913,10 @@ static void Symlink(const FunctionCallbackInfo<Value>& args) {
890
913
} else { // symlink(target, path, flags, undefinec, ctx)
891
914
CHECK_EQ (argc, 5 );
892
915
FSReqWrapSync req_wrap_sync;
916
+ FS_SYNC_TRACE_BEGIN (symlink);
893
917
SyncCall (env, args[4 ], &req_wrap_sync, " symlink" ,
894
918
uv_fs_symlink, *target, *path, flags);
919
+ FS_SYNC_TRACE_END (symlink);
895
920
}
896
921
}
897
922
@@ -914,8 +939,10 @@ static void Link(const FunctionCallbackInfo<Value>& args) {
914
939
} else { // link(src, dest)
915
940
CHECK_EQ (argc, 4 );
916
941
FSReqWrapSync req_wrap_sync;
942
+ FS_SYNC_TRACE_BEGIN (link);
917
943
SyncCall (env, args[3 ], &req_wrap_sync, " link" ,
918
944
uv_fs_link, *src, *dest);
945
+ FS_SYNC_TRACE_END (link);
919
946
}
920
947
}
921
948
@@ -937,8 +964,10 @@ static void ReadLink(const FunctionCallbackInfo<Value>& args) {
937
964
} else {
938
965
CHECK_EQ (argc, 4 );
939
966
FSReqWrapSync req_wrap_sync;
967
+ FS_SYNC_TRACE_BEGIN (readlink);
940
968
int err = SyncCall (env, args[3 ], &req_wrap_sync, " readlink" ,
941
969
uv_fs_readlink, *path);
970
+ FS_SYNC_TRACE_END (readlink);
942
971
if (err < 0 ) {
943
972
return ; // syscall failed, no need to continue, error info is in ctx
944
973
}
@@ -978,8 +1007,10 @@ static void Rename(const FunctionCallbackInfo<Value>& args) {
978
1007
} else {
979
1008
CHECK_EQ (argc, 4 );
980
1009
FSReqWrapSync req_wrap_sync;
1010
+ FS_SYNC_TRACE_BEGIN (rename);
981
1011
SyncCall (env, args[3 ], &req_wrap_sync, " rename" , uv_fs_rename,
982
1012
*old_path, *new_path);
1013
+ FS_SYNC_TRACE_END (rename);
983
1014
}
984
1015
}
985
1016
@@ -1002,8 +1033,10 @@ static void FTruncate(const FunctionCallbackInfo<Value>& args) {
1002
1033
} else {
1003
1034
CHECK_EQ (argc, 4 );
1004
1035
FSReqWrapSync req_wrap_sync;
1036
+ FS_SYNC_TRACE_BEGIN (ftruncate);
1005
1037
SyncCall (env, args[3 ], &req_wrap_sync, " ftruncate" , uv_fs_ftruncate, fd,
1006
1038
len);
1039
+ FS_SYNC_TRACE_END (ftruncate);
1007
1040
}
1008
1041
}
1009
1042
@@ -1023,7 +1056,9 @@ static void Fdatasync(const FunctionCallbackInfo<Value>& args) {
1023
1056
} else {
1024
1057
CHECK_EQ (argc, 3 );
1025
1058
FSReqWrapSync req_wrap_sync;
1059
+ FS_SYNC_TRACE_BEGIN (fdatasync);
1026
1060
SyncCall (env, args[2 ], &req_wrap_sync, " fdatasync" , uv_fs_fdatasync, fd);
1061
+ FS_SYNC_TRACE_END (fdatasync);
1027
1062
}
1028
1063
}
1029
1064
@@ -1043,7 +1078,9 @@ static void Fsync(const FunctionCallbackInfo<Value>& args) {
1043
1078
} else {
1044
1079
CHECK_EQ (argc, 3 );
1045
1080
FSReqWrapSync req_wrap_sync;
1081
+ FS_SYNC_TRACE_BEGIN (fsync);
1046
1082
SyncCall (env, args[2 ], &req_wrap_sync, " fsync" , uv_fs_fsync, fd);
1083
+ FS_SYNC_TRACE_END (fsync);
1047
1084
}
1048
1085
}
1049
1086
@@ -1063,7 +1100,9 @@ static void Unlink(const FunctionCallbackInfo<Value>& args) {
1063
1100
} else {
1064
1101
CHECK_EQ (argc, 3 );
1065
1102
FSReqWrapSync req_wrap_sync;
1103
+ FS_SYNC_TRACE_BEGIN (unlink);
1066
1104
SyncCall (env, args[2 ], &req_wrap_sync, " unlink" , uv_fs_unlink, *path);
1105
+ FS_SYNC_TRACE_END (unlink);
1067
1106
}
1068
1107
}
1069
1108
@@ -1083,8 +1122,10 @@ static void RMDir(const FunctionCallbackInfo<Value>& args) {
1083
1122
} else { // rmdir(path, undefined, ctx)
1084
1123
CHECK_EQ (argc, 3 );
1085
1124
FSReqWrapSync req_wrap_sync;
1125
+ FS_SYNC_TRACE_BEGIN (rmdir);
1086
1126
SyncCall (env, args[2 ], &req_wrap_sync, " rmdir" ,
1087
1127
uv_fs_rmdir, *path);
1128
+ FS_SYNC_TRACE_END (rmdir);
1088
1129
}
1089
1130
}
1090
1131
@@ -1107,8 +1148,10 @@ static void MKDir(const FunctionCallbackInfo<Value>& args) {
1107
1148
} else { // mkdir(path, mode, undefined, ctx)
1108
1149
CHECK_EQ (argc, 4 );
1109
1150
FSReqWrapSync req_wrap_sync;
1151
+ FS_SYNC_TRACE_BEGIN (mkdir);
1110
1152
SyncCall (env, args[3 ], &req_wrap_sync, " mkdir" ,
1111
1153
uv_fs_mkdir, *path, mode);
1154
+ FS_SYNC_TRACE_END (mkdir);
1112
1155
}
1113
1156
}
1114
1157
@@ -1130,8 +1173,10 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
1130
1173
} else { // realpath(path, encoding, undefined, ctx)
1131
1174
CHECK_EQ (argc, 4 );
1132
1175
FSReqWrapSync req_wrap_sync;
1176
+ FS_SYNC_TRACE_BEGIN (realpath);
1133
1177
int err = SyncCall (env, args[3 ], &req_wrap_sync, " realpath" ,
1134
1178
uv_fs_realpath, *path);
1179
+ FS_SYNC_TRACE_END (realpath);
1135
1180
if (err < 0 ) {
1136
1181
return ; // syscall failed, no need to continue, error info is in ctx
1137
1182
}
@@ -1171,8 +1216,10 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
1171
1216
} else { // readdir(path, encoding, undefined, ctx)
1172
1217
CHECK_EQ (argc, 4 );
1173
1218
FSReqWrapSync req_wrap_sync;
1219
+ FS_SYNC_TRACE_BEGIN (readdir);
1174
1220
int err = SyncCall (env, args[3 ], &req_wrap_sync, " scandir" ,
1175
1221
uv_fs_scandir, *path, 0 /* flags*/ );
1222
+ FS_SYNC_TRACE_END (readdir);
1176
1223
if (err < 0 ) {
1177
1224
return ; // syscall failed, no need to continue, error info is in ctx
1178
1225
}
@@ -1255,8 +1302,10 @@ static void Open(const FunctionCallbackInfo<Value>& args) {
1255
1302
} else { // open(path, flags, mode, undefined, ctx)
1256
1303
CHECK_EQ (argc, 5 );
1257
1304
FSReqWrapSync req_wrap_sync;
1305
+ FS_SYNC_TRACE_BEGIN (open);
1258
1306
int result = SyncCall (env, args[4 ], &req_wrap_sync, " open" ,
1259
1307
uv_fs_open, *path, flags, mode);
1308
+ FS_SYNC_TRACE_END (open);
1260
1309
args.GetReturnValue ().Set (result);
1261
1310
}
1262
1311
}
@@ -1283,8 +1332,10 @@ static void OpenFileHandle(const FunctionCallbackInfo<Value>& args) {
1283
1332
} else { // openFileHandle(path, flags, mode, undefined, ctx)
1284
1333
CHECK_EQ (argc, 5 );
1285
1334
FSReqWrapSync req_wrap_sync;
1335
+ FS_SYNC_TRACE_BEGIN (open);
1286
1336
int result = SyncCall (env, args[4 ], &req_wrap_sync, " open" ,
1287
1337
uv_fs_open, *path, flags, mode);
1338
+ FS_SYNC_TRACE_END (open);
1288
1339
if (result < 0 ) {
1289
1340
return ; // syscall failed, no need to continue, error info is in ctx
1290
1341
}
@@ -1317,8 +1368,10 @@ static void CopyFile(const FunctionCallbackInfo<Value>& args) {
1317
1368
} else { // copyFile(src, dest, flags, undefined, ctx)
1318
1369
CHECK_EQ (argc, 5 );
1319
1370
FSReqWrapSync req_wrap_sync;
1371
+ FS_SYNC_TRACE_BEGIN (copyfile);
1320
1372
SyncCall (env, args[4 ], &req_wrap_sync, " copyfile" ,
1321
1373
uv_fs_copyfile, *src, *dest, flags);
1374
+ FS_SYNC_TRACE_END (copyfile);
1322
1375
}
1323
1376
}
1324
1377
@@ -1368,8 +1421,10 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
1368
1421
} else { // write(fd, buffer, off, len, pos, undefined, ctx)
1369
1422
CHECK_EQ (argc, 7 );
1370
1423
FSReqWrapSync req_wrap_sync;
1424
+ FS_SYNC_TRACE_BEGIN (write);
1371
1425
int bytesWritten = SyncCall (env, args[6 ], &req_wrap_sync, " write" ,
1372
1426
uv_fs_write, fd, &uvbuf, 1 , pos);
1427
+ FS_SYNC_TRACE_END (write, " bytesWritten" , bytesWritten);
1373
1428
args.GetReturnValue ().Set (bytesWritten);
1374
1429
}
1375
1430
}
@@ -1411,8 +1466,10 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& args) {
1411
1466
} else { // writeBuffers(fd, chunks, pos, undefined, ctx)
1412
1467
CHECK_EQ (argc, 5 );
1413
1468
FSReqWrapSync req_wrap_sync;
1469
+ FS_SYNC_TRACE_BEGIN (write);
1414
1470
int bytesWritten = SyncCall (env, args[4 ], &req_wrap_sync, " write" ,
1415
1471
uv_fs_write, fd, *iovs, iovs.length (), pos);
1472
+ FS_SYNC_TRACE_END (write, " bytesWritten" , bytesWritten);
1416
1473
args.GetReturnValue ().Set (bytesWritten);
1417
1474
}
1418
1475
}
@@ -1503,8 +1560,10 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
1503
1560
buf = *stack_buffer;
1504
1561
}
1505
1562
uv_buf_t uvbuf = uv_buf_init (buf, len);
1563
+ FS_SYNC_TRACE_BEGIN (write);
1506
1564
int bytesWritten = SyncCall (env, args[5 ], &req_wrap_sync, " write" ,
1507
1565
uv_fs_write, fd, &uvbuf, 1 , pos);
1566
+ FS_SYNC_TRACE_END (write, " bytesWritten" , bytesWritten);
1508
1567
args.GetReturnValue ().Set (bytesWritten);
1509
1568
}
1510
1569
}
@@ -1556,8 +1615,10 @@ static void Read(const FunctionCallbackInfo<Value>& args) {
1556
1615
} else { // read(fd, buffer, offset, len, pos, undefined, ctx)
1557
1616
CHECK_EQ (argc, 7 );
1558
1617
FSReqWrapSync req_wrap_sync;
1618
+ FS_SYNC_TRACE_BEGIN (read);
1559
1619
const int bytesRead = SyncCall (env, args[6 ], &req_wrap_sync, " read" ,
1560
1620
uv_fs_read, fd, &uvbuf, 1 , pos);
1621
+ FS_SYNC_TRACE_END (read, " bytesRead" , bytesRead);
1561
1622
args.GetReturnValue ().Set (bytesRead);
1562
1623
}
1563
1624
}
@@ -1585,8 +1646,10 @@ static void Chmod(const FunctionCallbackInfo<Value>& args) {
1585
1646
} else { // chmod(path, mode, undefined, ctx)
1586
1647
CHECK_EQ (argc, 4 );
1587
1648
FSReqWrapSync req_wrap_sync;
1649
+ FS_SYNC_TRACE_BEGIN (chmod);
1588
1650
SyncCall (env, args[3 ], &req_wrap_sync, " chmod" ,
1589
1651
uv_fs_chmod, *path, mode);
1652
+ FS_SYNC_TRACE_END (chmod);
1590
1653
}
1591
1654
}
1592
1655
@@ -1613,8 +1676,10 @@ static void FChmod(const FunctionCallbackInfo<Value>& args) {
1613
1676
} else { // fchmod(fd, mode, undefined, ctx)
1614
1677
CHECK_EQ (argc, 4 );
1615
1678
FSReqWrapSync req_wrap_sync;
1679
+ FS_SYNC_TRACE_BEGIN (fchmod);
1616
1680
SyncCall (env, args[3 ], &req_wrap_sync, " fchmod" ,
1617
1681
uv_fs_fchmod, fd, mode);
1682
+ FS_SYNC_TRACE_END (fchmod);
1618
1683
}
1619
1684
}
1620
1685
@@ -1644,8 +1709,10 @@ static void Chown(const FunctionCallbackInfo<Value>& args) {
1644
1709
} else { // chown(path, uid, gid, undefined, ctx)
1645
1710
CHECK_EQ (argc, 5 );
1646
1711
FSReqWrapSync req_wrap_sync;
1712
+ FS_SYNC_TRACE_BEGIN (chown);
1647
1713
SyncCall (env, args[4 ], &req_wrap_sync, " chown" ,
1648
1714
uv_fs_chown, *path, uid, gid);
1715
+ FS_SYNC_TRACE_END (chown);
1649
1716
}
1650
1717
}
1651
1718
@@ -1675,8 +1742,10 @@ static void FChown(const FunctionCallbackInfo<Value>& args) {
1675
1742
} else { // fchown(fd, uid, gid, undefined, ctx)
1676
1743
CHECK_EQ (argc, 5 );
1677
1744
FSReqWrapSync req_wrap_sync;
1745
+ FS_SYNC_TRACE_BEGIN (fchown);
1678
1746
SyncCall (env, args[4 ], &req_wrap_sync, " fchown" ,
1679
1747
uv_fs_fchown, fd, uid, gid);
1748
+ FS_SYNC_TRACE_END (fchown);
1680
1749
}
1681
1750
}
1682
1751
@@ -1703,8 +1772,10 @@ static void UTimes(const FunctionCallbackInfo<Value>& args) {
1703
1772
} else { // utimes(path, atime, mtime, undefined, ctx)
1704
1773
CHECK_EQ (argc, 5 );
1705
1774
FSReqWrapSync req_wrap_sync;
1775
+ FS_SYNC_TRACE_BEGIN (utimes);
1706
1776
SyncCall (env, args[4 ], &req_wrap_sync, " utime" ,
1707
1777
uv_fs_utime, *path, atime, mtime);
1778
+ FS_SYNC_TRACE_END (utimes);
1708
1779
}
1709
1780
}
1710
1781
@@ -1730,8 +1801,10 @@ static void FUTimes(const FunctionCallbackInfo<Value>& args) {
1730
1801
} else { // futimes(fd, atime, mtime, undefined, ctx)
1731
1802
CHECK_EQ (argc, 5 );
1732
1803
FSReqWrapSync req_wrap_sync;
1804
+ FS_SYNC_TRACE_BEGIN (futimes);
1733
1805
SyncCall (env, args[4 ], &req_wrap_sync, " futime" ,
1734
1806
uv_fs_futime, fd, atime, mtime);
1807
+ FS_SYNC_TRACE_END (futimes);
1735
1808
}
1736
1809
}
1737
1810
@@ -1753,8 +1826,10 @@ static void Mkdtemp(const FunctionCallbackInfo<Value>& args) {
1753
1826
} else { // mkdtemp(tmpl, encoding, undefined, ctx)
1754
1827
CHECK_EQ (argc, 4 );
1755
1828
FSReqWrapSync req_wrap_sync;
1829
+ FS_SYNC_TRACE_BEGIN (mkdtemp);
1756
1830
SyncCall (env, args[3 ], &req_wrap_sync, " mkdtemp" ,
1757
1831
uv_fs_mkdtemp, *tmpl);
1832
+ FS_SYNC_TRACE_END (mkdtemp);
1758
1833
const char * path = static_cast <const char *>(req_wrap_sync.req .path );
1759
1834
1760
1835
Local<Value> error;
0 commit comments