rc: implement core/memstats to print internal memory usage info
This commit is contained in:
parent
d36b80f587
commit
21a10e58c9
1 changed files with 45 additions and 0 deletions
|
@ -4,6 +4,7 @@ package rc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
@ -42,6 +43,22 @@ the commands response.`,
|
||||||
This returns PID of current process.
|
This returns PID of current process.
|
||||||
Useful for stopping rclone 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
|
// Echo the input to the ouput parameters
|
||||||
|
@ -67,3 +84,31 @@ func rcPid(in Params) (out Params, err error) {
|
||||||
out["pid"] = os.Getpid()
|
out["pid"] = os.Getpid()
|
||||||
return out, nil
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue