Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

Add memtest command for debugging purposes

Nick Craig-Wood520ded60e388
diff --git a/rclone.go b/rclone.go
index 3592a0035..07718f563 100644
--- a/rclone.go
+++ b/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.`,