summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-08-21 08:13:36 -0400
committerGitHub <noreply@github.com>2021-08-21 08:13:36 -0400
commitb644e37abcaac7a93a2e33e300fa0f91498c56fc (patch)
tree5f38dfc0ba0cf5a331db463d0522cde61e3a7e1e /cmd/podman
parentc53e351d0e6516049a11230365d36eaa58948f5e (diff)
parent33fee83deabd0cc7040758406a830158f8708b84 (diff)
downloadpodman-b644e37abcaac7a93a2e33e300fa0f91498c56fc.tar.gz
podman-b644e37abcaac7a93a2e33e300fa0f91498c56fc.tar.bz2
podman-b644e37abcaac7a93a2e33e300fa0f91498c56fc.zip
Merge pull request #11296 from vrothberg/memory-profile
add flag to record memory profiles
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/root.go29
1 files changed, 23 insertions, 6 deletions
diff --git a/cmd/podman/root.go b/cmd/podman/root.go
index dc4ebb952..1275f5631 100644
--- a/cmd/podman/root.go
+++ b/cmd/podman/root.go
@@ -224,14 +224,29 @@ func persistentPostRunE(cmd *cobra.Command, args []string) error {
return nil
}
- if !registry.IsRemote() {
- if cmd.Flag("cpu-profile").Changed {
- pprof.StopCPUProfile()
+ registry.ImageEngine().Shutdown(registry.Context())
+ registry.ContainerEngine().Shutdown(registry.Context())
+
+ if registry.IsRemote() {
+ return nil
+ }
+
+ // CPU and memory profiling.
+ if cmd.Flag("cpu-profile").Changed {
+ pprof.StopCPUProfile()
+ }
+ if cmd.Flag("memory-profile").Changed {
+ f, err := os.Create(registry.PodmanConfig().MemoryProfile)
+ if err != nil {
+ return errors.Wrap(err, "creating memory profile")
+ }
+ defer f.Close()
+ runtime.GC() // get up-to-date GC statistics
+ if err := pprof.WriteHeapProfile(f); err != nil {
+ return errors.Wrap(err, "writing memory profile")
}
}
- registry.ImageEngine().Shutdown(registry.Context())
- registry.ContainerEngine().Shutdown(registry.Context())
return nil
}
@@ -294,7 +309,8 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
pFlags.StringVar(&cfg.Engine.CgroupManager, cgroupManagerFlagName, cfg.Engine.CgroupManager, "Cgroup manager to use (\"cgroupfs\"|\"systemd\")")
_ = cmd.RegisterFlagCompletionFunc(cgroupManagerFlagName, common.AutocompleteCgroupManager)
- pFlags.StringVar(&opts.CPUProfile, "cpu-profile", "", "Path for the cpu profiling results")
+ pFlags.StringVar(&opts.CPUProfile, "cpu-profile", "", "Path for the cpu-profiling results")
+ pFlags.StringVar(&opts.MemoryProfile, "memory-profile", "", "Path for the memory-profiling results")
conmonFlagName := "conmon"
pFlags.StringVar(&opts.ConmonPath, conmonFlagName, "", "Path of the conmon binary")
@@ -354,6 +370,7 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
"cpu-profile",
"default-mounts-file",
"max-workers",
+ "memory-profile",
"registries-conf",
"trace",
} {