The `ProcsTotal` in the `MiscStat` structure was very inaccurate. It was reading
a value which is the total number of kernel scheduling entities. This includes
both processes and threads significantly overcounting.
This instead uses an existing method already in common to count the number of
processes via the /proc filesystem where any directory is a number. This should
still be a single syscall to read that directory entry.
This fixes#1606.
Again, a simple benchmark:
Lomanics-iMac:~ lomanic$ time ./load_avg.old ; time ./load_avg
{load1:0.89,load5:0.99,load15:1.01} <nil>
real 0m0.019s
user 0m0.008s
sys 0m0.013s
{load1:0.8876953125,load5:0.98828125,load15:1.0146484375} <nil>
real 0m0.011s
user 0m0.004s
sys 0m0.006s
This is faster and yields more precise results.
The order of init function execution is dependant on the order that the
source files are passed to the compiler. This causes issues when
building under other build systems, such as bazel or buck, as they are
not guarenteed to maintain the same file order as the default go tool.
In order to improve performance and help prevent crashes due to the outstanding fork crash bug:
https://github.com/golang/go/issues/15658
Replace string parsed values from the sysctl command with native reads of sysctl values using unix.SysctlRaw and unix.SysctlUint32.
This also merges OpenBSD and FreeBSD load implementations which are identical.
This enables using gopsutil in a codebase that gets built on other OSes
than the ones supported. Instead of a build failure as before, due to
the build tags, gopsutil will now throw an "not implemented" runtime
error.
Fixes#234.