Create a usage command that outputs the read wait times from the sentry.

PiperOrigin-RevId: 413167721
This commit is contained in:
gVisor bot
2021-11-30 09:20:41 -08:00
parent afd549d79c
commit 68bb74d77a
2 changed files with 27 additions and 0 deletions
+1
View File
@@ -35,6 +35,7 @@ go_library(
"//pkg/sentry/fs/host",
"//pkg/sentry/fs/user",
"//pkg/sentry/fsimpl/host",
"//pkg/sentry/fsmetric",
"//pkg/sentry/kernel",
"//pkg/sentry/kernel/auth",
"//pkg/sentry/kernel/time",
+26
View File
@@ -15,11 +15,13 @@
package control
import (
"encoding/json"
"fmt"
"os"
"runtime"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/sentry/fsmetric"
"gvisor.dev/gvisor/pkg/sentry/kernel"
"gvisor.dev/gvisor/pkg/sentry/usage"
"gvisor.dev/gvisor/pkg/urpc"
@@ -168,6 +170,30 @@ func NewMemoryUsageRecord(usageFile, platformFile os.File) (*MemoryUsageRecord,
return &m, nil
}
// GetFileIoStats writes the read times in nanoseconds to out.
func (*Usage) GetFileIoStats(_ *struct{}, out *string) error {
fileIoStats := struct {
// The total amount of time spent reading. The map maps gopher prefixes
// to the total time spent reading. Times not included in a known prefix
// are placed in the "/" prefix.
ReadWait map[string]uint64 `json:"ReadWait"`
// The total amount of time spent reading. The map maps gopher prefixes
// to the total time spent reading. Times not included in a known prefix
// are placed in the "/" prefix.
ReadWait9P map[string]uint64 `json:"ReadWait9P"`
}{
ReadWait: map[string]uint64{"/": fsmetric.ReadWait.Value()},
ReadWait9P: map[string]uint64{"/": fsmetric.GoferReadWait9P.Value()},
}
m, err := json.Marshal(fileIoStats)
if err != nil {
return err
}
*out = string(m)
return nil
}
func finalizer(m *MemoryUsageRecord) {
unix.RawSyscall(unix.SYS_MUNMAP, m.mmap, usage.RTMemoryStatsSize, 0)
}