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

rc: implement core/memstats to print internal memory usage info

Nick Craig-Wood21a10e58c9d8
diff --git a/fs/rc/internal.go b/fs/rc/internal.go
index c3d36f816..70a579c8e 100644
--- a/fs/rc/internal.go
+++ b/fs/rc/internal.go
@@ -4,6 +4,7 @@ package rc
import (
"os"
+ "runtime"
"github.com/pkg/errors"
)
@@ -42,6 +43,22 @@ the commands response.`,
This returns PID of current process.
Useful for stopping rclone process.`,
})
+ Add(Call{
+ Path: "core/memstats",
+ Fn: rcMemStats,
+ Title: "Returns the memory statistics of the running program",
+ Help: `
+This returns the memory statistics of the running program. What the values mean
+are explained in the go docs: https://golang.org/pkg/runtime/#MemStats
+
+The most interesting values for most people are:
+
+* HeapAlloc: This is the amount of memory rclone is actually using
+* HeapSys: This is the amount of memory rclone has obtained from the OS
+* Sys: this is the total amount of memory requested from the OS
+ * It is virtual memory so may include unused memory
+`,
+ })
}
// Echo the input to the ouput parameters
@@ -67,3 +84,31 @@ func rcPid(in Params) (out Params, err error) {
out["pid"] = os.Getpid()
return out, nil
}
+
+// Return the memory statistics
+func rcMemStats(in Params) (out Params, err error) {
+ out = make(Params)
+ var m runtime.MemStats
+ runtime.ReadMemStats(&m)
+ out["Alloc"] = m.Alloc
+ out["TotalAlloc"] = m.TotalAlloc
+ out["Sys"] = m.Sys
+ out["Mallocs"] = m.Mallocs
+ out["Frees"] = m.Frees
+ out["HeapAlloc"] = m.HeapAlloc
+ out["HeapSys"] = m.HeapSys
+ out["HeapIdle"] = m.HeapIdle
+ out["HeapInuse"] = m.HeapInuse
+ out["HeapReleased"] = m.HeapReleased
+ out["HeapObjects"] = m.HeapObjects
+ out["StackInuse"] = m.StackInuse
+ out["StackSys"] = m.StackSys
+ out["MSpanInuse"] = m.MSpanInuse
+ out["MSpanSys"] = m.MSpanSys
+ out["MCacheInuse"] = m.MCacheInuse
+ out["MCacheSys"] = m.MCacheSys
+ out["BuckHashSys"] = m.BuckHashSys
+ out["GCSys"] = m.GCSys
+ out["OtherSys"] = m.OtherSys
+ return out, nil
+}