Skip to content

Commit

Permalink
fs: trace more fs api
Browse files Browse the repository at this point in the history
PR-URL: #45095
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
  • Loading branch information
theanarkh authored and RafaelGSS committed Nov 10, 2022
1 parent 8d56822 commit d89ca1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/node_dir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ void DirHandle::MemoryInfo(MemoryTracker* tracker) const {
inline void DirHandle::GCClose() {
if (closed_) return;
uv_fs_t req;
FS_DIR_SYNC_TRACE_BEGIN(closedir);
int ret = uv_fs_closedir(nullptr, &req, dir_, nullptr);
FS_DIR_SYNC_TRACE_END(closedir);
uv_fs_req_cleanup(&req);
closing_ = false;
closed_ = true;
Expand Down
17 changes: 15 additions & 2 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ FileHandle::TransferData::~TransferData() {
if (fd_ > 0) {
uv_fs_t close_req;
CHECK_NE(fd_, -1);
FS_SYNC_TRACE_BEGIN(close);
CHECK_EQ(0, uv_fs_close(nullptr, &close_req, fd_, nullptr));
FS_SYNC_TRACE_END(close);
uv_fs_req_cleanup(&close_req);
}
}
Expand All @@ -327,7 +329,9 @@ inline void FileHandle::Close() {
if (closed_ || closing_) return;
uv_fs_t req;
CHECK_NE(fd_, -1);
FS_SYNC_TRACE_BEGIN(close);
int ret = uv_fs_close(env()->event_loop(), &req, fd_, nullptr);
FS_SYNC_TRACE_END(close);
uv_fs_req_cleanup(&req);

struct err_detail { int ret; int fd; };
Expand Down Expand Up @@ -460,7 +464,10 @@ MaybeLocal<Promise> FileHandle::ClosePromise() {

CloseReq* req = new CloseReq(env(), close_req_obj, promise, object());
auto AfterClose = uv_fs_callback_t{[](uv_fs_t* req) {
BaseObjectPtr<CloseReq> close(CloseReq::from_req(req));
CloseReq* req_wrap = CloseReq::from_req(req);
FS_ASYNC_TRACE_END1(
req->fs_type, req_wrap, "result", static_cast<int>(req->result))
BaseObjectPtr<CloseReq> close(req_wrap);
CHECK(close);
close->file_handle()->AfterClose();
if (!close->env()->can_call_into_js()) return;
Expand All @@ -474,6 +481,7 @@ MaybeLocal<Promise> FileHandle::ClosePromise() {
}
}};
CHECK_NE(fd_, -1);
FS_ASYNC_TRACE_BEGIN0(UV_FS_CLOSE, req)
int ret = req->Dispatch(uv_fs_close, fd_, AfterClose);
if (ret < 0) {
req->Reject(UVException(isolate, ret, "close"));
Expand Down Expand Up @@ -569,7 +577,7 @@ int FileHandle::ReadStart() {
read_wrap->buffer_ = EmitAlloc(recommended_read);

current_read_ = std::move(read_wrap);

FS_ASYNC_TRACE_BEGIN0(UV_FS_READ, current_read_.get())
current_read_->Dispatch(uv_fs_read,
fd_,
&current_read_->buffer_,
Expand All @@ -579,6 +587,8 @@ int FileHandle::ReadStart() {
FileHandle* handle;
{
FileHandleReadWrap* req_wrap = FileHandleReadWrap::from_req(req);
FS_ASYNC_TRACE_END1(
req->fs_type, req_wrap, "result", static_cast<int>(req->result))
handle = req_wrap->file_handle_;
CHECK_EQ(handle->current_read_.get(), req_wrap);
}
Expand Down Expand Up @@ -652,9 +662,12 @@ int FileHandle::DoShutdown(ShutdownWrap* req_wrap) {
FileHandleCloseWrap* wrap = static_cast<FileHandleCloseWrap*>(req_wrap);
closing_ = true;
CHECK_NE(fd_, -1);
FS_ASYNC_TRACE_BEGIN0(UV_FS_CLOSE, wrap)
wrap->Dispatch(uv_fs_close, fd_, uv_fs_callback_t{[](uv_fs_t* req) {
FileHandleCloseWrap* wrap = static_cast<FileHandleCloseWrap*>(
FileHandleCloseWrap::from_req(req));
FS_ASYNC_TRACE_END1(
req->fs_type, wrap, "result", static_cast<int>(req->result))
FileHandle* handle = static_cast<FileHandle*>(wrap->stream());
handle->AfterClose();

Expand Down

0 comments on commit d89ca1b

Please sign in to comment.