From 685eaf119ffa6c44c4dcaec0e083bbdc0271231a Mon Sep 17 00:00:00 2001 From: Rahat Mahmood Date: Thu, 6 Dec 2018 11:14:57 -0800 Subject: Add counters for memory events. Also ensure an event is emitted at startup. PiperOrigin-RevId: 224372065 Change-Id: I5f642b6d6b13c6468ee8f794effe285fcbbf29cf --- pkg/sentry/kernel/memevent/BUILD | 1 + pkg/sentry/kernel/memevent/memory_events.go | 10 ++++++++++ 2 files changed, 11 insertions(+) (limited to 'pkg/sentry') 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, -- cgit v1.2.3