Add memtest command for debugging purposes
This commit is contained in:
parent
ae56df7d4f
commit
520ded60e3
1 changed files with 37 additions and 1 deletions
38
rclone.go
38
rclone.go
|
@ -13,6 +13,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -81,7 +82,7 @@ func init() {
|
||||||
rootCmd.AddCommand(copyCmd, syncCmd, moveCmd, lsCmd, lsdCmd,
|
rootCmd.AddCommand(copyCmd, syncCmd, moveCmd, lsCmd, lsdCmd,
|
||||||
lslCmd, md5sumCmd, sha1sumCmd, sizeCmd, mkdirCmd,
|
lslCmd, md5sumCmd, sha1sumCmd, sizeCmd, mkdirCmd,
|
||||||
rmdirCmd, purgeCmd, deleteCmd, checkCmd, dedupeCmd,
|
rmdirCmd, purgeCmd, deleteCmd, checkCmd, dedupeCmd,
|
||||||
configCmd, authorizeCmd, cleanupCmd, versionCmd)
|
configCmd, authorizeCmd, cleanupCmd, memtestCmd, versionCmd)
|
||||||
dedupeCmd.Flags().VarP(&dedupeMode, "dedupe-mode", "", "Dedupe mode interactive|skip|first|newest|oldest|rename.")
|
dedupeCmd.Flags().VarP(&dedupeMode, "dedupe-mode", "", "Dedupe mode interactive|skip|first|newest|oldest|rename.")
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
}
|
}
|
||||||
|
@ -489,6 +490,41 @@ old file versions. Not supported by all remotes.`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var memtestCmd = &cobra.Command{
|
||||||
|
Use: "memtest remote:path",
|
||||||
|
Short: `Load all the objects at remote:path and report memory stats.`,
|
||||||
|
Hidden: true,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
checkArgs(1, 1, cmd, args)
|
||||||
|
fsrc := newFsSrc(args)
|
||||||
|
run(false, cmd, func() error {
|
||||||
|
objects, _, err := fs.Count(fsrc)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
objs := make([]fs.Object, 0, objects)
|
||||||
|
var before, after runtime.MemStats
|
||||||
|
runtime.GC()
|
||||||
|
runtime.ReadMemStats(&before)
|
||||||
|
var mu sync.Mutex
|
||||||
|
err = fs.ListFn(fsrc, func(o fs.Object) {
|
||||||
|
mu.Lock()
|
||||||
|
objs = append(objs, o)
|
||||||
|
mu.Unlock()
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
runtime.GC()
|
||||||
|
runtime.ReadMemStats(&after)
|
||||||
|
usedMemory := after.Alloc - before.Alloc
|
||||||
|
fs.Log(nil, "%d objects took %d bytes, %.1f bytes/object", len(objs), usedMemory, float64(usedMemory)/float64(len(objs)))
|
||||||
|
fs.Log(nil, "System memory changed from %d to %d bytes a change of %d bytes", before.Sys, after.Sys, after.Sys-before.Sys)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var versionCmd = &cobra.Command{
|
var versionCmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: `Show the version number.`,
|
Short: `Show the version number.`,
|
||||||
|
|
Loading…
Add table
Reference in a new issue