mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 15:20:38 +08:00
Add memtest command for debugging purposes
This commit is contained in:
parent
ae56df7d4f
commit
520ded60e3
38
rclone.go
38
rclone.go
|
@ -13,6 +13,7 @@ import (
|
|||
"path"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -81,7 +82,7 @@ func init() {
|
|||
rootCmd.AddCommand(copyCmd, syncCmd, moveCmd, lsCmd, lsdCmd,
|
||||
lslCmd, md5sumCmd, sha1sumCmd, sizeCmd, mkdirCmd,
|
||||
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.")
|
||||
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{
|
||||
Use: "version",
|
||||
Short: `Show the version number.`,
|
||||
|
|
Loading…
Reference in New Issue
Block a user