mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #107050 from sunzhaochang/add-close-profiling
Add Close() for profile
This commit is contained in:
commit
eb43b41cfd
@ -37,11 +37,15 @@ func addProfilingFlags(flags *pflag.FlagSet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initProfiling() error {
|
func initProfiling() error {
|
||||||
|
var (
|
||||||
|
f *os.File
|
||||||
|
err error
|
||||||
|
)
|
||||||
switch profileName {
|
switch profileName {
|
||||||
case "none":
|
case "none":
|
||||||
return nil
|
return nil
|
||||||
case "cpu":
|
case "cpu":
|
||||||
f, err := os.Create(profileOutput)
|
f, err = os.Create(profileOutput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -68,6 +72,7 @@ func initProfiling() error {
|
|||||||
signal.Notify(c, os.Interrupt)
|
signal.Notify(c, os.Interrupt)
|
||||||
go func() {
|
go func() {
|
||||||
<-c
|
<-c
|
||||||
|
f.Close()
|
||||||
flushProfiling()
|
flushProfiling()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
@ -93,6 +98,7 @@ func flushProfiling() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer f.Close()
|
||||||
profile.WriteTo(f, 0)
|
profile.WriteTo(f, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user