diff options
author | Rahat Mahmood <rahat@google.com> | 2018-12-06 11:14:57 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-12-06 11:15:47 -0800 |
commit | 685eaf119ffa6c44c4dcaec0e083bbdc0271231a (patch) | |
tree | 5d76cf5b1dec2b40e7be26a8ceca614bed7f5578 /pkg | |
parent | 4d8c7ae869a4e9bf60c7ea9aff79a0bee551fbc9 (diff) |
Add counters for memory events.
Also ensure an event is emitted at startup.
PiperOrigin-RevId: 224372065
Change-Id: I5f642b6d6b13c6468ee8f794effe285fcbbf29cf
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/sentry/kernel/memevent/BUILD | 1 | ||||
-rw-r--r-- | pkg/sentry/kernel/memevent/memory_events.go | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/pkg/sentry/kernel/memevent/BUILD b/pkg/sentry/kernel/memevent/BUILD index e903badd3..dfd8dd062 100644 --- a/pkg/sentry/kernel/memevent/BUILD +++ b/pkg/sentry/kernel/memevent/BUILD @@ -12,6 +12,7 @@ go_library( ":memory_events_go_proto", "//pkg/eventchannel", "//pkg/log", + "//pkg/metric", "//pkg/sentry/kernel", "//pkg/sentry/usage", ], diff --git a/pkg/sentry/kernel/memevent/memory_events.go b/pkg/sentry/kernel/memevent/memory_events.go index f05ef1b64..1a8e86827 100644 --- a/pkg/sentry/kernel/memevent/memory_events.go +++ b/pkg/sentry/kernel/memevent/memory_events.go @@ -22,11 +22,15 @@ import ( "gvisor.googlesource.com/gvisor/pkg/eventchannel" "gvisor.googlesource.com/gvisor/pkg/log" + "gvisor.googlesource.com/gvisor/pkg/metric" "gvisor.googlesource.com/gvisor/pkg/sentry/kernel" pb "gvisor.googlesource.com/gvisor/pkg/sentry/kernel/memevent/memory_events_go_proto" "gvisor.googlesource.com/gvisor/pkg/sentry/usage" ) +var totalTicks = metric.MustCreateNewUint64Metric("/memory_events/ticks", false /*sync*/, "Total number of memory event periods that have elapsed since startup.") +var totalEvents = metric.MustCreateNewUint64Metric("/memory_events/events", false /*sync*/, "Total number of memory events emitted.") + // MemoryEvents describes the configuration for the global memory event emitter. type MemoryEvents struct { k *kernel.Kernel @@ -71,6 +75,10 @@ func (m *MemoryEvents) Start() { func (m *MemoryEvents) run() { m.done.Add(1) + // Emit the first event immediately on startup. + totalTicks.Increment() + m.emit() + ticker := time.NewTicker(m.period) defer ticker.Stop() @@ -80,6 +88,7 @@ func (m *MemoryEvents) run() { m.done.Done() return case <-ticker.C: + totalTicks.Increment() m.emit() } } @@ -94,6 +103,7 @@ func (m *MemoryEvents) emit() { snapshot, _ := usage.MemoryAccounting.Copy() total := totalPlatform + snapshot.Mapped + totalEvents.Increment() eventchannel.Emit(&pb.MemoryUsageEvent{ Mapped: snapshot.Mapped, Total: total, |