1
0
mirror of https://github.com/rclone/rclone.git synced 2026-01-04 17:43:50 +00:00

fs: add --dump goroutines and --dump openfiles

These are developer flags useful for tracking down resource leaks.
This commit is contained in:
Nick Craig-Wood
2018-04-11 14:16:55 +01:00
parent 37be78705d
commit dcf8334673
3 changed files with 37 additions and 0 deletions

View File

@@ -10,10 +10,12 @@ import (
"fmt"
"log"
"os"
"os/exec"
"path"
"regexp"
"runtime"
"runtime/pprof"
"strconv"
"time"
"github.com/pkg/errors"
@@ -322,6 +324,26 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
accounting.Stats.Log()
}
fs.Debugf(nil, "%d go routines active\n", runtime.NumGoroutine())
// dump all running go-routines
if fs.Config.Dump&fs.DumpGoRoutines != 0 {
err = pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
if err != nil {
fs.Errorf(nil, "Failed to dump goroutines: %v", err)
}
}
// dump open files
if fs.Config.Dump&fs.DumpOpenFiles != 0 {
c := exec.Command("lsof", "-p", strconv.Itoa(os.Getpid()))
c.Stdout = os.Stdout
c.Stderr = os.Stderr
err = c.Run()
if err != nil {
fs.Errorf(nil, "Failed to list open files: %v", err)
}
}
if accounting.Stats.Errored() {
resolveExitCode(accounting.Stats.GetLastError())
}