mirror of
https://github.com/containers/podman.git
synced 2025-06-20 09:03:43 +08:00
Merge pull request #11296 from vrothberg/memory-profile
add flag to record memory profiles
This commit is contained in:
@ -224,14 +224,29 @@ func persistentPostRunE(cmd *cobra.Command, args []string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !registry.IsRemote() {
|
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 {
|
if cmd.Flag("cpu-profile").Changed {
|
||||||
pprof.StopCPUProfile()
|
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
|
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\")")
|
pFlags.StringVar(&cfg.Engine.CgroupManager, cgroupManagerFlagName, cfg.Engine.CgroupManager, "Cgroup manager to use (\"cgroupfs\"|\"systemd\")")
|
||||||
_ = cmd.RegisterFlagCompletionFunc(cgroupManagerFlagName, common.AutocompleteCgroupManager)
|
_ = 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"
|
conmonFlagName := "conmon"
|
||||||
pFlags.StringVar(&opts.ConmonPath, conmonFlagName, "", "Path of the conmon binary")
|
pFlags.StringVar(&opts.ConmonPath, conmonFlagName, "", "Path of the conmon binary")
|
||||||
@ -354,6 +370,7 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
|
|||||||
"cpu-profile",
|
"cpu-profile",
|
||||||
"default-mounts-file",
|
"default-mounts-file",
|
||||||
"max-workers",
|
"max-workers",
|
||||||
|
"memory-profile",
|
||||||
"registries-conf",
|
"registries-conf",
|
||||||
"trace",
|
"trace",
|
||||||
} {
|
} {
|
||||||
|
@ -39,6 +39,7 @@ type PodmanConfig struct {
|
|||||||
EngineMode EngineMode // ABI or Tunneling mode
|
EngineMode EngineMode // ABI or Tunneling mode
|
||||||
Identity string // ssh identity for connecting to server
|
Identity string // ssh identity for connecting to server
|
||||||
MaxWorks int // maximum number of parallel threads
|
MaxWorks int // maximum number of parallel threads
|
||||||
|
MemoryProfile string // Hidden: Should memory profile be taken
|
||||||
RegistriesConf string // allows for specifying a custom registries.conf
|
RegistriesConf string // allows for specifying a custom registries.conf
|
||||||
Remote bool // Connection to Podman API Service will use RESTful API
|
Remote bool // Connection to Podman API Service will use RESTful API
|
||||||
RuntimePath string // --runtime flag will set Engine.RuntimePath
|
RuntimePath string // --runtime flag will set Engine.RuntimePath
|
||||||
|
Reference in New Issue
Block a user