From 21a10e58c9d8331fe6d3b2f3291be56fc5d467fc Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 23 Apr 2018 20:10:28 +0100 Subject: [PATCH] rc: implement core/memstats to print internal memory usage info --- fs/rc/internal.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) 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 +}