Add Close() for profile

Kubernetes-commit: 82c9d80295451dad4b9a5af89f34bb56b3a9904b
This commit is contained in:
sunzhaochang 2021-12-15 21:03:34 +08:00 committed by Kubernetes Publisher
parent 4a1c72da90
commit 16d7d99cc5
1 changed files with 7 additions and 1 deletions

View File

@ -37,11 +37,15 @@ func addProfilingFlags(flags *pflag.FlagSet) {
}
func initProfiling() error {
var (
f *os.File
err error
)
switch profileName {
case "none":
return nil
case "cpu":
f, err := os.Create(profileOutput)
f, err = os.Create(profileOutput)
if err != nil {
return err
}
@ -68,6 +72,7 @@ func initProfiling() error {
signal.Notify(c, os.Interrupt)
go func() {
<-c
f.Close()
flushProfiling()
os.Exit(0)
}()
@ -93,6 +98,7 @@ func flushProfiling() error {
if err != nil {
return err
}
defer f.Close()
profile.WriteTo(f, 0)
}