@@ -6,7 +6,9 @@ package fs
66import (
77 "os"
88 "syscall"
9+ "time"
910
11+ "github.com/Meesho/BharatMLStack/flashring/pkg/metrics"
1012 "golang.org/x/sys/unix"
1113)
1214
@@ -72,10 +74,13 @@ func (r *WrapAppendFile) Pwrite(buf []byte) (currentPhysicalOffset int64, err er
7274 return 0 , ErrBufNoAlign
7375 }
7476 }
77+ startTime := time .Now ()
7578 n , err := syscall .Pwrite (r .WriteFd , buf , r .PhysicalWriteOffset )
79+ metrics .Timing (metrics .KEY_PWRITE_LATENCY , time .Since (startTime ), []string {})
7680 if err != nil {
7781 return 0 , err
7882 }
83+
7984 r .PhysicalWriteOffset += int64 (n )
8085 if r .PhysicalWriteOffset >= r .MaxFileSize {
8186 r .wrapped = true
@@ -126,7 +131,9 @@ func (r *WrapAppendFile) Pread(fileOffset int64, buf []byte) (int32, error) {
126131 return 0 , ErrFileOffsetOutOfRange
127132 }
128133
134+ startTime := time .Now ()
129135 n , err := syscall .Pread (r .ReadFd , buf , fileOffset )
136+ metrics .Timing (metrics .KEY_PREAD_LATENCY , time .Since (startTime ), []string {})
130137 // flags := unix.RWF_HIPRI // optionally: | unix.RWF_NOWAIT
131138 // n, err := preadv2(r.ReadFd, buf, fileOffset, flags)
132139 if err != nil {
@@ -137,6 +144,8 @@ func (r *WrapAppendFile) Pread(fileOffset int64, buf []byte) (int32, error) {
137144}
138145
139146func (r * WrapAppendFile ) TrimHead () (err error ) {
147+
148+ startTime := time .Now ()
140149 if r .WriteDirectIO {
141150 if ! isAlignedOffset (r .PhysicalStartOffset , r .blockSize ) {
142151 return ErrOffsetNotAligned
@@ -151,6 +160,7 @@ func (r *WrapAppendFile) TrimHead() (err error) {
151160 r .PhysicalStartOffset = 0
152161 }
153162 r .Stat .PunchHoleCount ++
163+ metrics .Timing (metrics .KEY_TRIM_HEAD_LATENCY , time .Since (startTime ), []string {})
154164 return nil
155165}
156166
0 commit comments