mirror of
https://github.com/rclone/rclone.git
synced 2025-12-06 00:03:32 +00:00
Introduce AtExit to fix --cpuprofile and --memprofile to write profiles at end of run
This commit is contained in:
11
cmd/cmd.go
11
cmd/cmd.go
@@ -69,6 +69,9 @@ and configuration walkthroughs.
|
||||
|
||||
* http://rclone.org/
|
||||
`,
|
||||
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
||||
runAtExitFunctions()
|
||||
},
|
||||
}
|
||||
|
||||
// runRoot implements the main rclone command with no subcommands
|
||||
@@ -341,12 +344,14 @@ func initConfig() {
|
||||
fs.Stats.Error()
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer pprof.StopCPUProfile()
|
||||
AtExit(func() {
|
||||
pprof.StopCPUProfile()
|
||||
})
|
||||
}
|
||||
|
||||
// Setup memory profiling if desired
|
||||
if *memProfile != "" {
|
||||
defer func() {
|
||||
AtExit(func() {
|
||||
fs.Infof(nil, "Saving Memory profile %q\n", *memProfile)
|
||||
f, err := os.Create(*memProfile)
|
||||
if err != nil {
|
||||
@@ -363,7 +368,7 @@ func initConfig() {
|
||||
fs.Stats.Error()
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
if m, _ := regexp.MatchString("^(bits|bytes)$", *dataRateUnit); m == false {
|
||||
|
||||
Reference in New Issue
Block a user