This commit adds Solaris(^1) support for the Info() function of package
cpu, with the exception of the L2 cache size which is not trivially
available(^2).
Support is implemented by parsing the output of `isainfo -b -v` (for the
instruction set flags), and `psr-info -p -v` for other information.
Example outputs from a range of different size VMs and Joyent containers
are included as part of the tests.
(^1): This has only been tested with Illumos in the form of SmartOS. I
believe it to be portable to other Illumos distributions but have not
tested on Oracle Solaris.
(^2): Enough support is added here to be usable for my port of
HashiCorp's Nomad to SmartOS.
Currently gopsutils fails to indentify the POWER processors family,
returning an almost empty Info() structure.
This patch improves the POWER identification without changing what is
available for x86.
* on virtualized host, this may happen.
* but we may have a value from parsing `/proc/cpuinfo`
* in this case, we do not return the error if we fail to extra
a value from `cpufreq/cpuinfo_max_freq`
* resolve#249
* in `cpu_windows.go`, `Mhz` is the value of `MaxClockSpeed`
* on Linux platform, the `Mhz` value is extracted from `/proc/cpuinfo`
which reflects the current clock speed; treat this as the fallback
value instead
* read from `cpufreq/cpuinfo_max_freq` under sysfs to get the
maximum clock speed for `Mhz`, just like for Windows platform
* also fix the path to `cpu.CoreID` value; the filename is `core_id`
* for Darwin, it is a minor tweak for readability: the value
returned is in Hz, so using a variable named 'hz' makes more
sense than 'mhz'
* for Linux, the unit is in kHz so we need to divide the value
from `cpuinfo_max_freq` by 10^3 to get MHz (see
cpu-freq/user-guide.txt of the kernel documentation)
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.
- Added conditional preprocessor guard on cpu_darwin_cgo.go
- Duplicated disk_darwin_amd64 for arm64 (after confirming
that sys/mount.h are the same between the two platforms, hence the
constants should be valid).
This function used to be a private part of process.go.
Since I needed that functionality however I think it's better to make it public
than for me to copy it into my own code.
As a side effect of this change, I also fixed a bug in the function where Stolen
was not part of the sum. Having the function close to the CPUTimesStat
declaration will make problems like this less likely to re-occur in the future.