Add weirdness sentry metric.

Weirdness metric contains fields to track the number of clock fallback,
partial result and vsyscalls. This metric will avoid the overhead of
having three different metrics (fallbackMetric, partialResultMetric,
vsyscallCount).

PiperOrigin-RevId: 369970218
This commit is contained in:
Nayana Bidari
2021-04-22 16:07:15 -07:00
committed by gVisor bot
parent d93907110e
commit 0a6eaed50b
8 changed files with 29 additions and 0 deletions
+18
View File
@@ -35,6 +35,11 @@ var (
// ErrInitializationDone indicates that the caller tried to create a
// new metric after initialization.
ErrInitializationDone = errors.New("metric cannot be created after initialization is complete")
// WeirdnessMetric is a metric with fields created to track the number
// of weird occurrences such as clock fallback, partial_result and
// vsyscall count.
WeirdnessMetric *Uint64Metric
)
// Uint64Metric encapsulates a uint64 that represents some kind of metric to be
@@ -380,3 +385,16 @@ func EmitMetricUpdate() {
eventchannel.Emit(&m)
}
// CreateSentryMetrics creates the sentry metrics during kernel initialization.
func CreateSentryMetrics() {
if WeirdnessMetric != nil {
return
}
WeirdnessMetric = MustCreateNewUint64Metric("/weirdness", true /* sync */, "Increment for weird occurrences of problems such as clock fallback, partial result and vsyscalls invoked in the sandbox",
Field{
name: "weirdness_type",
allowedValues: []string{"fallback", "partial_result", "vsyscall_count"},
})
}
+1
View File
@@ -17,6 +17,7 @@ go_library(
"//pkg/fspath",
"//pkg/hostarch",
"//pkg/memutil",
"//pkg/metric",
"//pkg/sentry/fsbridge",
"//pkg/sentry/fsimpl/tmpfs",
"//pkg/sentry/kernel",
+3
View File
@@ -25,6 +25,7 @@ import (
"gvisor.dev/gvisor/pkg/cpuid"
"gvisor.dev/gvisor/pkg/fspath"
"gvisor.dev/gvisor/pkg/memutil"
"gvisor.dev/gvisor/pkg/metric"
"gvisor.dev/gvisor/pkg/sentry/fsbridge"
"gvisor.dev/gvisor/pkg/sentry/fsimpl/tmpfs"
"gvisor.dev/gvisor/pkg/sentry/kernel"
@@ -62,6 +63,8 @@ func Boot() (*kernel.Kernel, error) {
return nil, fmt.Errorf("creating platform: %v", err)
}
metric.CreateSentryMetrics()
kernel.VFS2Enabled = true
k := &kernel.Kernel{
Platform: plat,
+1
View File
@@ -285,6 +285,7 @@ func (*runSyscallExit) execute(t *Task) taskRunState {
// task's next run state.
func (t *Task) doVsyscall(addr hostarch.Addr, sysno uintptr) taskRunState {
vsyscallCount.Increment()
metric.WeirdnessMetric.Increment("vsyscall_count")
// Grab the caller up front, to make sure there's a sensible stack.
caller := t.Arch().Native(uintptr(0))
+1
View File
@@ -39,6 +39,7 @@ var (
// takes a variadic number of arguments.
func incrementPartialResultMetric() {
partialResultMetric.Increment()
metric.WeirdnessMetric.Increment("partial_result")
}
// HandleIOErrorVFS2 handles special error cases for partial results. For some
+1
View File
@@ -103,6 +103,7 @@ func (c *CalibratedClock) resetLocked(str string, v ...interface{}) {
c.ready = false
c.ref.Reset()
fallbackMetric.Increment()
metric.WeirdnessMetric.Increment("fallback")
}
// updateParams updates the timekeeping parameters based on the passed
+1
View File
@@ -38,6 +38,7 @@ go_library(
"//pkg/fspath",
"//pkg/log",
"//pkg/memutil",
"//pkg/metric",
"//pkg/rand",
"//pkg/refs",
"//pkg/refsvfs2",
+3
View File
@@ -34,6 +34,7 @@ import (
"gvisor.dev/gvisor/pkg/fd"
"gvisor.dev/gvisor/pkg/log"
"gvisor.dev/gvisor/pkg/memutil"
"gvisor.dev/gvisor/pkg/metric"
"gvisor.dev/gvisor/pkg/rand"
"gvisor.dev/gvisor/pkg/refs"
"gvisor.dev/gvisor/pkg/refsvfs2"
@@ -217,6 +218,8 @@ func New(args Args) (*Loader, error) {
return nil, fmt.Errorf("setting up memory usage: %v", err)
}
metric.CreateSentryMetrics()
// Is this a VFSv2 kernel?
if args.Conf.VFS2 {
kernel.VFS2Enabled = true