summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/file.go
diff options
context:
space:
mode:
authorGoogler <noreply@google.com>2019-02-21 13:07:25 -0800
committerShentubot <shentubot@google.com>2019-02-21 13:08:34 -0800
commit532f4b2fbaf66382a3d9e118b5a7a3ee272c8edc (patch)
treef356c028a402945583c58dde367eba4f31953dfe /pkg/sentry/fs/file.go
parentb2a5ad047a26dbe06c16dfa5a4e150836b79fd7c (diff)
Internal change.
PiperOrigin-RevId: 235053594 Change-Id: Ie3d7b11843d0710184a2463886c7034e8f5305d1
Diffstat (limited to 'pkg/sentry/fs/file.go')
-rw-r--r--pkg/sentry/fs/file.go30
1 files changed, 29 insertions, 1 deletions
diff --git a/pkg/sentry/fs/file.go b/pkg/sentry/fs/file.go
index b66d2f265..d66813103 100644
--- a/pkg/sentry/fs/file.go
+++ b/pkg/sentry/fs/file.go
@@ -18,6 +18,7 @@ import (
"math"
"sync"
"sync/atomic"
+ "time"
"gvisor.googlesource.com/gvisor/pkg/amutex"
"gvisor.googlesource.com/gvisor/pkg/log"
@@ -33,7 +34,22 @@ import (
"gvisor.googlesource.com/gvisor/pkg/waiter"
)
-var reads = metric.MustCreateNewUint64Metric("/fs/reads", false /* sync */, "Number of file reads.")
+var (
+ // RecordWaitTime controls writing metrics for filesystem reads. Enabling this comes at a small
+ // CPU cost due to performing two monotonic clock reads per read call.
+ RecordWaitTime = false
+
+ reads = metric.MustCreateNewUint64Metric("/fs/reads", false /* sync */, "Number of file reads.")
+ readWait = metric.MustCreateNewUint64Metric("/fs/read_wait", false /* sync */, "Time waiting on file reads, in nanoseconds.")
+)
+
+// IncrementWait increments the given wait time metric, if enabled.
+func IncrementWait(m *metric.Uint64Metric, start time.Time) {
+ if !RecordWaitTime {
+ return
+ }
+ m.IncrementBy(uint64(time.Since(start)))
+}
// FileMaxOffset is the maximum possible file offset.
const FileMaxOffset = math.MaxInt64
@@ -236,7 +252,12 @@ func (f *File) Readdir(ctx context.Context, serializer DentrySerializer) error {
//
// Returns syserror.ErrInterrupted if reading was interrupted.
func (f *File) Readv(ctx context.Context, dst usermem.IOSequence) (int64, error) {
+ var start time.Time
+ if RecordWaitTime {
+ start = time.Now()
+ }
if !f.mu.Lock(ctx) {
+ IncrementWait(readWait, start)
return 0, syserror.ErrInterrupted
}
@@ -246,6 +267,7 @@ func (f *File) Readv(ctx context.Context, dst usermem.IOSequence) (int64, error)
atomic.AddInt64(&f.offset, n)
}
f.mu.Unlock()
+ IncrementWait(readWait, start)
return n, err
}
@@ -255,13 +277,19 @@ func (f *File) Readv(ctx context.Context, dst usermem.IOSequence) (int64, error)
//
// Otherwise same as Readv.
func (f *File) Preadv(ctx context.Context, dst usermem.IOSequence, offset int64) (int64, error) {
+ var start time.Time
+ if RecordWaitTime {
+ start = time.Now()
+ }
if !f.mu.Lock(ctx) {
+ IncrementWait(readWait, start)
return 0, syserror.ErrInterrupted
}
reads.Increment()
n, err := f.FileOperations.Read(ctx, f, dst, offset)
f.mu.Unlock()
+ IncrementWait(readWait, start)
return n, err
}