From 222de612f4e68f8d8320df53af4b3999a208e715 Mon Sep 17 00:00:00 2001 From: Etienne Perot Date: Mon, 13 May 2024 12:00:54 -0700 Subject: [PATCH] Stop profiling metrics in the same step as other profiles in `runsc`. This is part of a series of changes to add metric charts in performance benchmarks. This change stops profiling metrics whenever we also stop CPU/heap/mutex profiles, rather than at `runsc boot` exit. This helps flushing the metrics data at the right time. PiperOrigin-RevId: 633287428 --- runsc/boot/BUILD | 1 + runsc/boot/loader.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/runsc/boot/BUILD b/runsc/boot/BUILD index b557aa849..a3ffe7508 100644 --- a/runsc/boot/BUILD +++ b/runsc/boot/BUILD @@ -50,6 +50,7 @@ go_library( "//pkg/hostos", "//pkg/log", "//pkg/memutil", + "//pkg/metric", "//pkg/rand", "//pkg/refs", "//pkg/sentry/arch", diff --git a/runsc/boot/loader.go b/runsc/boot/loader.go index f2c56f435..34193e7aa 100644 --- a/runsc/boot/loader.go +++ b/runsc/boot/loader.go @@ -36,6 +36,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/sentry/control" @@ -372,7 +373,11 @@ func getRootCredentials(spec *specs.Spec, conf *config.Config, userNs *auth.User // New initializes a new kernel loader configured by spec. // New also handles setting up a kernel for restoring a container. func New(args Args) (*Loader, error) { - stopProfiling := profile.Start(args.ProfileOpts) + stopProfilingRuntime := profile.Start(args.ProfileOpts) + stopProfiling := func() { + stopProfilingRuntime() + metric.StopProfilingMetrics() + } // Initialize seccheck points. seccheck.Initialize()