Commit Graph

210 Commits

Author SHA1 Message Date
renaynay 5e1b882e37
updated docs for TimesStat with correct time unit 2020-05-13 11:21:01 +02:00
renaynay 0e9462eed2
renamed CLK_TCK variables for consistency across OSs 2020-05-12 15:36:18 +02:00
renaynay d4985c9690
added check for CLK_TCK 2020-05-12 13:59:26 +02:00
Dmitri Goutnik 270f6afc22
Add support for freebsd/arm64 2019-12-17 03:12:29 -05:00
shirou b0025409e9 [cpu][linux]: add cpuinfo parse check. 2019-11-14 21:47:42 +09:00
alialaee b8f51de8f6 Fix #777 cpu.Total should not add Guest and GuestNice 2019-10-15 19:19:12 +03:30
shirou e4d2c2f87a
Merge pull request #749 from Lomanic/issue628windows
[cpu][windows] Add support for logical arg in Counts #640 #628
2019-08-16 09:34:56 +09:00
Lomanic 71adb75383 [cpu][windows] Add support for logical arg in Counts #640 #628 2019-08-14 23:52:41 +02:00
Lomanic e6aa38bec2 [cpu][windows] WIP Add support for logical arg in Counts #640 #628 2019-08-14 23:35:31 +02:00
shirou 86fdae99e1 [cpu]: return 100 instead 1 if t1 are bigger than t2 2019-07-06 11:24:35 +09:00
Lomanic 946c9ce6ea [cpu] Fix #599 cap percent values returned by Percent() between 0 and 100
See https://github.com/shirou/gopsutil/issues/599#issuecomment-491942842 for a repoduction case
2019-06-23 16:14:27 +02:00
Lomanic 35f21af98a
Merge pull request #699 from harpchad/solaris_cpu
Add support fo Solaris cpu times (idle, sys, user, iowait) in cpu_solaris
2019-06-08 19:53:38 +02:00
Chad Harp 8c6072d111 Cast bytes to string 2019-06-07 07:39:57 -05:00
Chad Harp 16b37cc9c2 Modify cpu_solaris to support Sorlais 10 2019-06-02 09:58:35 -05:00
Chad Harp 354718bdd8 Add support for Solaris CPU times 2019-06-01 15:05:46 -05:00
shirou 4b629897d2
Merge pull request #647 from omar-polo/master
[OpenBSD][CPU] fix per-cpu
2019-06-01 10:24:59 +09:00
shirou e146c2e08a
Merge pull request #677 from shirou/feature/remove_stolen_from_cpu
[cpu]: remove unused field Stolen
2019-05-12 18:43:21 +09:00
Segflow 86c7289ccc Fix: use filename in exec.LookPath instead of full path
exec.LookPath searches for the file in the $PATH, which mean giving it an absolute path is against it's own purposes.
2019-05-05 20:45:07 +01:00
Omar Polo 3cbb0873de
int32 is enough -- don't waste space 2019-05-02 12:24:16 +02:00
shirou cae8efcffa [cpu]: remove unused field Stolen
see #676
2019-04-27 13:45:12 +09:00
Minje Park caebe5dbe4 returning 0 and error if SysctlUint32 raises an error 2019-03-21 23:52:34 +09:00
Omar Polo 53ce014b14
handle EOPNOTSUPP when checking for hw.smt
if hw.smt is not applicable for the current platform (e.g. i386),
pretend it's enabled
2019-03-19 20:06:12 +01:00
Omar Polo c28fe78291
forget to take addr 2019-03-18 19:58:50 +01:00
Minje Park ca1fcad2aa retrieve a cpu count depends on an boolean argument 2019-03-17 23:18:29 +09:00
Omar Polo 932f2f6049
Fix cpu stats when hw.smt is enabled
When hw.smt is enabled, and it's enabled by default from 6.4, the
number of cpus given by `runtime.NumCPU()` is half of the total: only
the cpuN with N = 0,2,4,... are used by the system. We need to detect
that and ask for the correct stats.
2019-03-16 12:26:03 +01:00
Omar Polo 12d92847cf
Get hw.ncpuonline without unix.SysctlUint32
unix.Sysctl always return an error when asking for hw.ncpuonline, so
revert to a direct unix.Syscall6 to get the cpu count.
2019-03-13 11:03:17 +01:00
Omar Polo c2c7893509
fix logic error + little refactor
Fix: get cptime of n-th cpu when `percpu` instead of the average.

While there, rearrange the last if statement to make the code a bit
more homogeneous.
2019-03-12 21:29:10 +01:00
Lomanic 200e5fbeab [cpu][linux] Remove regexp in Counts
Also remove some remaining debug print and unnecessary strings.Split
2019-03-06 19:41:26 +01:00
Lomanic c0ca431bf1 [cpu][linux] Add support for logical arg in Counts #640 #628 2019-03-03 14:44:21 +01:00
Lomanic 2ec35609d2 [cpu][darwin] Remove calls to sysctl binary in cpu/cpu_darwin.go #639
Empirical benchmark (calling to cpu.Info):

Lomanics-iMac:~ lomanic$ time ./cpu_info
info 0: {"cpu":0,"vendorId":"GenuineIntel","family":"6","model":"30","stepping":5,"physicalId":"","coreId":"","cores":2,"modelName":"Intel(R) Core(TM) i5-6440HQ CPU @ 2.60GHz","mhz":2590,"cacheSize":256,"flags":["syscall","xd","em64t","lahf","lzcnt","prefetchw","rdtscp","tsci","fpu","vme","de","pse","tsc","msr","pae","mce","cx8","apic","sep","mtrr","pge","mca","cmov","pat","pse36","clfsh","mmx","fxsr","sse","sse2","htt","sse3","ssse3","cx16","sse4.1","sse4.2","popcnt","vmm"],"microcode":""}

real    0m0.049s
user    0m0.023s
sys     0m0.041s
Lomanics-iMac:~ lomanic$ time ./cpu_info.fixed
info 0: {"cpu":0,"vendorId":"GenuineIntel","family":"6","model":"30","stepping":5,"physicalId":"","coreId":"","cores":2,"modelName":"Intel(R) Core(TM) i5-6440HQ CPU @ 2.60GHz","mhz":2590,"cacheSize":256,"flags":["fpu","vme","de","pse","tsc","msr","pae","mce","cx8","apic","sep","mtrr","pge","mca","cmov","pat","pse36","clfsh","mmx","fxsr","sse","sse2","htt","sse3","ssse3","cx16","sse4.1","sse4.2","popcnt","vmm","syscall","xd","em64t","lahf","lzcnt","prefetchw","rdtscp","tsci"],"microcode":""}

real    0m0.010s
user    0m0.004s
sys     0m0.006s
2019-03-02 23:22:53 +01:00
nikita-vanyasin 59b002e5c2 Fix function naming 2019-02-22 11:19:56 +03:00
nikita-vanyasin 4ef0ddafc7 Eliminate WMI queries when calling cpu.Times with percpu=True
based on e89f2c5fad/internal/monitors/cpu/cpu_windows.go
2019-02-22 09:51:24 +03:00
shirou 64d607539e add FreeBSD ARM support. copied from i386 2019-01-17 16:49:20 +09:00
Antoine Jacoutot 67297c8791 cpu: prefer cpuonline on OpenBSD
This gives us the value of actual online CPUs (as opposed to the
found ones which may not be able active).
2019-01-02 17:10:02 +01:00
Antoine Jacoutot 7276e963eb cpu: implement Mhz and Cores
Adapted from the FreeBSD code.
Successfully tested with Nomad.
2019-01-02 17:06:46 +01:00
Lomanic 5f8353c741 [cpu][openbsd] Fix #621, define CPU states according to OpenBSD version 2018-12-29 15:24:52 +01:00
marcospedreiro f0ebb60b86 handle pr comments: use assert.InEpsilon 2018-11-20 13:25:17 -08:00
marcospedreiro d47801b68b revert imports 2018-11-19 22:06:05 -08:00
marcospedreiro 3cc34ebf18 windows cpu time (true) should return cpu time not percentages 2018-11-19 21:51:27 -08:00
marcospedreiro 45aeaebda5 test windows cpu.Time(true) returning time instead of percentages 2018-11-18 22:30:47 -08:00
Lomanic 4254ce2081
Merge pull request #601 from Lomanic/issue551
Fix #551 Filter out '_Total' results from PerfInfoWithContext and unexport this function.

Also propagate context in perCPUTimes (renamed to perCPUTimesWithContext) and unexport Win32_PerfFormattedData_Counters_ProcessorInformation type.
2018-11-06 14:56:13 +01:00
Lomanic 79f8a73e23 Fix #551 Filter out '_Total' results from PerfInfoWithContext and unexport this function
Also propagate context in perCPUTimes (renamed to perCPUTimesWithContext)
and unexport Win32_PerfFormattedData_Counters_ProcessorInformation.
2018-11-05 12:28:39 +01:00
shirou a11c78ba2c
Merge pull request #581 from CMGS/master
get docker container cpu usage from cpuacct.usage
2018-09-27 21:43:08 +09:00
Iskander Sharipov f3d4342c30 cpu,process: remove commented-out code
Found using https://go-critic.github.io/overview#commentedOutCode-ref
2018-09-13 23:56:24 +03:00
CMGS d93c01e54d get docker container cpu usage from cpuacct.usage 2018-09-11 15:29:13 +08:00
Michal Rostecki 7c7dec96c6 cpu: Check for error object 2018-06-21 16:42:49 +02:00
shirou 145dca90f7 change to use CommandContext. 2018-03-31 21:35:53 +09:00
Laurie Clark-Michalek 413cb32b6c Use static initialisation for invoke instances, instead of init funcs
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.
2018-03-21 14:08:39 +00:00
shirou 32a44bdc39
Merge pull request #488 from sadag/master
windows: fix WithContext functions
2018-02-14 21:00:39 +09:00
shirou 9a74b6fe2e [cpu]windows: fix retrun value. 2018-02-13 22:21:27 +09:00
sada 8dd42707e2 windows: fix WithContext functions
set timeout only if parent context doesn't set.
2018-02-12 13:26:17 -08:00
Jaime Fullaondo 178e5ce997 [host] fix race condition to ret 2018-02-12 15:46:11 +01:00
shirou 4c73494c78 Add WithContext functions. 2017-12-31 15:25:49 +09:00
Adam Medzinski 22f3299fd7
Add missing doc for cpu.TimesStat structure 2017-11-27 12:17:18 +01:00
leaf 65598d98cc To prevent hang if wmi.Query hangs, add a context-aware wrapper for it. 2017-11-20 10:13:27 -08:00
Steven Hartland 6450c60b61 Eliminate use of sysctl command on FreeBSD
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.
2017-10-05 08:45:56 +01:00
WAKAYAMA Shirou 4c9fd1f200 [cpu]linux: add testcode with testdata. 2017-09-20 15:58:30 +09:00
HeChuan c818f7b647 set win cpu total name to "cpu-total"
set the name of windows cpu total percent to "cpu-total"
keep the same with Linux, Freebsd system
2017-07-20 11:47:15 +08:00
Andrew Danforth 484470889f Only read /proc/stat once when cpu.Times(true) is called on Linux 2017-06-09 22:34:58 -04:00
shirou 3dd8bd46d9 Merge pull request #376 from ContinuumLLC/win_percpu_feature
Windows: Read processor performance metrics overall, per cpu and per core
2017-06-05 22:30:45 +09:00
Rajkumar Gupta b657e83fed Added comments for structs and functions 2017-06-05 15:46:35 +05:30
Rajkumar Gupta 2d2db4203f Change to adapt current cpu.Times API for per cpu and core time stats 2017-06-05 14:18:20 +05:30
Sean Chittenden 635b971c0e
Move from the `syscall` package to the `golang.org/x/sys/{unix,windows}` 2017-06-02 13:51:00 -07:00
Rajkumar Gupta ea683cd370 Read processor performance metrics per cpu and per core 2017-05-25 17:54:43 +05:30
WAKAYAMA shirou b6da2bd76e [freebsd] cpu: fix CPUInfo on 10.3R
Related: #307
2017-05-10 11:47:26 +09:00
WAKAYAMA Shirou dfbb3e40da fix build bugs. 2017-04-10 22:24:36 +09:00
Jakob Gillich facb241c12 clarify return value of cpu.Percent() 2017-03-31 16:07:44 +02:00
WAKAYAMA Shirou 3499dec5c0 [cpu]linux: handle hz values by tmm1 2017-03-23 21:36:54 +09:00
WAKAYAMA Shirou a63f1aeeec use Processor entry as model name fallback by @tmm1 2017-03-23 21:35:50 +09:00
WAKAYAMA Shirou 36b408780c cpu[linux]: ignore cpufreq/cpuinfo_max_freq error 2017-03-21 00:55:21 +09:00
WAKAYAMA Shirou bad1ce0748 fix typo 2017-03-15 23:32:55 +09:00
WAKAYAMA Shirou 30ebb9ca3a rename expected dir to testdata. 2017-03-15 23:01:06 +09:00
WAKAYAMA Shirou f8ef680a47 error strings change to lowercase 2017-03-15 22:43:20 +09:00
shirou d4c8874c19 Merge pull request #328 from jen20/solaris-cpu
cpu: Implement Solaris support for Info()
2017-03-14 01:51:04 +09:00
James Nugent 49ed700c0d cpu: Implement Solaris support for Info()
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.
2017-03-12 21:19:42 -05:00
Simarpreet Singh 5a4c90ad5f cpu: Expose CPU microcode information
This commit exposes the CPU microcode information.

Signed-off-by: Simarpreet Singh <simar@opendns.com>
2017-03-07 16:18:20 -08:00
Sam Kleinman 915d1e930e fix panic in starvation situations 2017-02-15 11:25:49 -05:00
shirou 77b5d0080a Merge pull request #311 from sparrc/cpu-times-panic
fix panic when /proc/stat is empty
2017-02-02 09:16:45 +09:00
Cameron Sparr 0c9a1d33cb
fix panic when /proc/stat is empty
don't really know why this would be the case, but I suppose there are
always edge-cases.

see https://github.com/influxdata/telegraf/issues/2356
2017-02-01 23:13:59 +00:00
Cameron Sparr a213bf5e6d
run go fmt ./... 2017-02-01 23:05:29 +00:00
WAKAYAMA shirou dc8102185d separate freebsd specific test code. 2017-01-29 01:43:24 +09:00
WAKAYAMA shirou a54f700f00 fix test other than freebsd. 2017-01-29 01:38:52 +09:00
WAKAYAMA shirou eb5bfca902 [cpu]freebsd: cpu.Info() now returns CPUInfos same number as CPU nums. 2017-01-29 01:23:21 +09:00
WAKAYAMA shirou 7783018b9d [cpu]freebsd: CPU.CPU now indicates CPU num instead of MHz. 2017-01-22 22:31:05 +09:00
Marco Pfatschbacher b4846b445b Add support for OpenBSD/amd64
This code is based on the FreeBSD version
and implements roughly the same feature set.
2016-11-24 22:30:29 +01:00
Shirou WAKAYAMA ae251eb6a2 cpu[darwin]: fix Go arrays panic in cgo #279 2016-11-15 00:53:20 +09:00
Breno Leitao 286927a039 Improve CPU identification for POWER processors
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.
2016-10-24 14:11:12 -04:00
Andreas Henriksson 9d51bfe3bb Allow clock field in /proc/cpuinfo as cpu MHz fallback value
Needed on ppc64le debian porter boxes atleast.

See #230
2016-10-14 14:05:32 +02:00
Hilko Bengen 832dcb96c8 cpu.Percent (Windows): Use the same implementation as on Unix
WMI is way too slow.
2016-09-27 18:15:05 +02:00
K.C. Wong 3dc4e52844 Handle the case when the `cpufreq` sysfs does not exist
* 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`
2016-08-29 16:21:17 -07:00
K.C. Wong 10a1ae2123 Standardize `Mhz` to mean maximum CPU frequency on Linux platform
* 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`
2016-08-29 10:11:30 -07:00
shirou a8e24d70f9 Merge pull request #247 from lfittl/fallback-for-unsupported-architectures
Add fallback code for all unsupported operating systems
2016-08-27 00:58:16 +09:00
K.C. Wong 123a6c9b0d Addressing frequency unit discrepancies
* 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)
2016-08-23 17:21:30 -07:00
Lukas Fittl da9fa1162b Add fallback code for all unsupported operating systems.
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.
2016-08-22 15:31:26 -07:00
Lukas Fittl 74541ba4a5 CPU: Fix linter warning on OSX. 2016-08-22 14:20:29 -07:00
shirou 5c1bfed855 Merge pull request #219 from sean-/freebsd-cpu-info
Improve FreeBSD's CPU InfoStat collection
2016-06-17 17:26:08 +09:00
Sean Chittenden 14b2ce8b81
Don't be lossy re: CPU model number. 2016-06-16 19:32:49 -07:00
Sean Chittenden 606680edc5
Improve the accuracy of CPU detection on FreeBSD. 2016-06-16 19:25:27 -07:00
Ben Aldrich 9dbebcf46e rename ALL to all 2016-06-01 16:03:11 -06:00
Ben Aldrich a76195e088 fixed imports and spelling error 2016-06-01 15:53:54 -06:00