Commit Graph

261 Commits (master)

Author SHA1 Message Date
Lomanic a901d160ca
Merge pull request #870 from renaynay/naming-consistency
Renamed variables storing `CLK_TCK` value for consistency across OSs
5 years ago
renaynay 5e1b882e37
updated docs for TimesStat with correct time unit 5 years ago
renaynay 0e9462eed2
renamed CLK_TCK variables for consistency across OSs 5 years ago
renaynay d4985c9690
added check for CLK_TCK 5 years ago
Dmitri Goutnik 270f6afc22
Add support for freebsd/arm64 5 years ago
shirou b0025409e9 [cpu][linux]: add cpuinfo parse check. 5 years ago
alialaee b8f51de8f6 Fix #777 cpu.Total should not add Guest and GuestNice 5 years ago
shirou e4d2c2f87a
Merge pull request #749 from Lomanic/issue628windows
[cpu][windows] Add support for logical arg in Counts #640 #628
6 years ago
Lomanic 71adb75383 [cpu][windows] Add support for logical arg in Counts #640 #628 6 years ago
Lomanic e6aa38bec2 [cpu][windows] WIP Add support for logical arg in Counts #640 #628 6 years ago
shirou 86fdae99e1 [cpu]: return 100 instead 1 if t1 are bigger than t2 6 years ago
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
6 years ago
Lomanic 35f21af98a
Merge pull request #699 from harpchad/solaris_cpu
Add support fo Solaris cpu times (idle, sys, user, iowait) in cpu_solaris
6 years ago
Chad Harp 8c6072d111 Cast bytes to string 6 years ago
Chad Harp 16b37cc9c2 Modify cpu_solaris to support Sorlais 10 6 years ago
Chad Harp 354718bdd8 Add support for Solaris CPU times 6 years ago
shirou 4b629897d2
Merge pull request #647 from omar-polo/master
[OpenBSD][CPU] fix per-cpu
6 years ago
shirou e146c2e08a
Merge pull request #677 from shirou/feature/remove_stolen_from_cpu
[cpu]: remove unused field Stolen
6 years ago
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.
6 years ago
Omar Polo 3cbb0873de
int32 is enough -- don't waste space 6 years ago
shirou cae8efcffa [cpu]: remove unused field Stolen
see #676
6 years ago
Minje Park caebe5dbe4 returning 0 and error if SysctlUint32 raises an error 6 years ago
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
6 years ago
Omar Polo c28fe78291
forget to take addr 6 years ago
Minje Park ca1fcad2aa retrieve a cpu count depends on an boolean argument 6 years ago
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.
6 years ago
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.
6 years ago
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.
6 years ago
Lomanic 200e5fbeab [cpu][linux] Remove regexp in Counts
Also remove some remaining debug print and unnecessary strings.Split
6 years ago
Lomanic c0ca431bf1 [cpu][linux] Add support for logical arg in Counts #640 #628 6 years ago
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
6 years ago
nikita-vanyasin 59b002e5c2 Fix function naming 6 years ago
nikita-vanyasin 4ef0ddafc7 Eliminate WMI queries when calling cpu.Times with percpu=True
based on e89f2c5fad/internal/monitors/cpu/cpu_windows.go
6 years ago
shirou 64d607539e add FreeBSD ARM support. copied from i386 6 years ago
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).
6 years ago
Antoine Jacoutot 7276e963eb cpu: implement Mhz and Cores
Adapted from the FreeBSD code.
Successfully tested with Nomad.
6 years ago
Lomanic 5f8353c741 [cpu][openbsd] Fix #621, define CPU states according to OpenBSD version 6 years ago
marcospedreiro f0ebb60b86 handle pr comments: use assert.InEpsilon 6 years ago
marcospedreiro d47801b68b revert imports 6 years ago
marcospedreiro 3cc34ebf18 windows cpu time (true) should return cpu time not percentages 6 years ago
marcospedreiro 45aeaebda5 test windows cpu.Time(true) returning time instead of percentages 6 years ago
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.
6 years ago
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.
6 years ago
shirou a11c78ba2c
Merge pull request #581 from CMGS/master
get docker container cpu usage from cpuacct.usage
7 years ago
Iskander Sharipov f3d4342c30 cpu,process: remove commented-out code
Found using https://go-critic.github.io/overview#commentedOutCode-ref
7 years ago
CMGS d93c01e54d get docker container cpu usage from cpuacct.usage 7 years ago
Michal Rostecki 7c7dec96c6 cpu: Check for error object 7 years ago
shirou 145dca90f7 change to use CommandContext. 7 years ago
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.
7 years ago
shirou 32a44bdc39
Merge pull request #488 from sadag/master
windows: fix WithContext functions
7 years ago
shirou 9a74b6fe2e [cpu]windows: fix retrun value. 7 years ago
sada 8dd42707e2 windows: fix WithContext functions
set timeout only if parent context doesn't set.
7 years ago
Jaime Fullaondo 178e5ce997 [host] fix race condition to ret 7 years ago
shirou 4c73494c78 Add WithContext functions. 7 years ago
Adam Medzinski 22f3299fd7
Add missing doc for cpu.TimesStat structure 7 years ago
leaf 65598d98cc To prevent hang if wmi.Query hangs, add a context-aware wrapper for it. 7 years ago
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.
8 years ago
WAKAYAMA Shirou 4c9fd1f200 [cpu]linux: add testcode with testdata. 8 years ago
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
8 years ago
Andrew Danforth 484470889f Only read /proc/stat once when cpu.Times(true) is called on Linux 8 years ago
shirou 3dd8bd46d9 Merge pull request #376 from ContinuumLLC/win_percpu_feature
Windows: Read processor performance metrics overall, per cpu and per core
8 years ago
Rajkumar Gupta b657e83fed Added comments for structs and functions 8 years ago
Rajkumar Gupta 2d2db4203f Change to adapt current cpu.Times API for per cpu and core time stats 8 years ago
Sean Chittenden 635b971c0e
Move from the `syscall` package to the `golang.org/x/sys/{unix,windows}` 8 years ago
Rajkumar Gupta ea683cd370 Read processor performance metrics per cpu and per core 8 years ago
WAKAYAMA shirou b6da2bd76e [freebsd] cpu: fix CPUInfo on 10.3R
Related: #307
8 years ago
WAKAYAMA Shirou dfbb3e40da fix build bugs. 8 years ago
Jakob Gillich facb241c12 clarify return value of cpu.Percent() 8 years ago
WAKAYAMA Shirou 3499dec5c0 [cpu]linux: handle hz values by tmm1 8 years ago
WAKAYAMA Shirou a63f1aeeec use Processor entry as model name fallback by @tmm1 8 years ago
WAKAYAMA Shirou 36b408780c cpu[linux]: ignore cpufreq/cpuinfo_max_freq error 8 years ago
WAKAYAMA Shirou bad1ce0748 fix typo 8 years ago
WAKAYAMA Shirou 30ebb9ca3a rename expected dir to testdata. 8 years ago
WAKAYAMA Shirou f8ef680a47 error strings change to lowercase 8 years ago
shirou d4c8874c19 Merge pull request #328 from jen20/solaris-cpu
cpu: Implement Solaris support for Info()
8 years ago
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.
8 years ago
Simarpreet Singh 5a4c90ad5f cpu: Expose CPU microcode information
This commit exposes the CPU microcode information.

Signed-off-by: Simarpreet Singh <simar@opendns.com>
8 years ago
Sam Kleinman 915d1e930e fix panic in starvation situations 8 years ago
shirou 77b5d0080a Merge pull request #311 from sparrc/cpu-times-panic
fix panic when /proc/stat is empty
8 years ago
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
8 years ago
Cameron Sparr a213bf5e6d
run go fmt ./... 8 years ago
WAKAYAMA shirou dc8102185d separate freebsd specific test code. 8 years ago
WAKAYAMA shirou a54f700f00 fix test other than freebsd. 8 years ago
WAKAYAMA shirou eb5bfca902 [cpu]freebsd: cpu.Info() now returns CPUInfos same number as CPU nums. 8 years ago
WAKAYAMA shirou 7783018b9d [cpu]freebsd: CPU.CPU now indicates CPU num instead of MHz. 8 years ago
Marco Pfatschbacher b4846b445b Add support for OpenBSD/amd64
This code is based on the FreeBSD version
and implements roughly the same feature set.
8 years ago
Shirou WAKAYAMA ae251eb6a2 cpu[darwin]: fix Go arrays panic in cgo #279 8 years ago
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.
9 years ago
Andreas Henriksson 9d51bfe3bb Allow clock field in /proc/cpuinfo as cpu MHz fallback value
Needed on ppc64le debian porter boxes atleast.

See #230
9 years ago
Hilko Bengen 832dcb96c8 cpu.Percent (Windows): Use the same implementation as on Unix
WMI is way too slow.
9 years ago
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`
9 years ago
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`
9 years ago
shirou a8e24d70f9 Merge pull request #247 from lfittl/fallback-for-unsupported-architectures
Add fallback code for all unsupported operating systems
9 years ago
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)
9 years ago
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.
9 years ago
Lukas Fittl 74541ba4a5 CPU: Fix linter warning on OSX. 9 years ago
shirou 5c1bfed855 Merge pull request #219 from sean-/freebsd-cpu-info
Improve FreeBSD's CPU InfoStat collection
9 years ago
Sean Chittenden 14b2ce8b81
Don't be lossy re: CPU model number. 9 years ago
Sean Chittenden 606680edc5
Improve the accuracy of CPU detection on FreeBSD. 9 years ago
Ben Aldrich 9dbebcf46e rename ALL to all 9 years ago
Ben Aldrich a76195e088 fixed imports and spelling error 9 years ago
Ben Aldrich c36f7ac8b0 rename var 9 years ago
Ben Aldrich fcc1747d9f Merge branch 'master' of https://github.com/shirou/gopsutil into calc_cpu_percent
Conflicts:
	cpu/cpu.go
9 years ago
Ben Aldrich c389989453 calculate cpu percentage compared to last call if 0 interval is given 9 years ago
Sean Chittenden d2ca7e8d2c
Remove redundant build tag 9 years ago
Shirou WAKAYAMA 57f6aebc7e add Timeout to invoke command and use common.Invoke refs: #201 9 years ago
Aaron Zinman 4041e7d31e Fix compile errors for iOS/arm64
- 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).
9 years ago
Shirou WAKAYAMA 5daf090513 [cpu]linux: vendorId in cpuinfo is sometimes vendor_id. 9 years ago
Shirou WAKAYAMA bce9212def fix build bugs. 9 years ago
Shirou WAKAYAMA d21ed2b40d search path via exec.LookPath before actual invoke. 9 years ago
Shirou WAKAYAMA 613a8a90e1 fixed by golint. 9 years ago
Shirou WAKAYAMA 4bb84648bf JSON representation is renamed to fit Google JSON style, camelCase. 9 years ago
Shirou WAKAYAMA ea152ea901 [BREAKING CHANGE] rename functions to pass golint. ex) net.NetIOCounters -> net.IOCounters 9 years ago
Shirou WAKAYAMA 7f22150707 CPU num is different on the CircleCI environemnt, so we skip it. 9 years ago
Johan Walles ebaa641e63 Make a public function for computing total CPU time
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.
9 years ago
Ryan J. O'Neil 4d7275adf7 Rebrandoning back. 9 years ago
Ryan J. O'Neil 2434a327b9 Removing race condition in CPUPercent calculation. 9 years ago
Ryan J. O'Neil 1b9883dc76 Rebrandoning so we can patch this library and have it work in our Godeps. 9 years ago
Daniel Theophanes fa7f8ba4e8 cpu: CPUInfo returns one item per physical thread. Fix "Cores" to 1 on Linux.
Fixes #104
10 years ago
Daniel Theophanes bc6481f7e0 Merge branch 'master' of https://github.com/shirou/gopsutil into cpu_test 10 years ago
Shirou WAKAYAMA 7288e9a5af common[all]: add internal 10 years ago
Daniel Theophanes 726e7c6406 cpu: fix cpu test on small ARM device where CPU can be at 100%+rounding.
Fixes #99
10 years ago
Daniel Theophanes 0af895258e common: rename package common to internal/common. Add ENV helper funcs.
Package common wasn't used for public functions. Place it in an
internal directory to prevent other packages from using.

Remove the distributed references to "HOST_PROC" and "HOST_SYS"
consts and combine into a common function. This also helps so that
if a env var is defined with a trailing slash all will continue to
work as expected.

Fixes #100
10 years ago
Daniel Theophanes 69221741e8 cpu: allow override of /sys dir. Fix CPUInfo /proc + cpuinfo combine. 10 years ago
Daniel Theophanes ab2cba55ee Merge branch 'master' of https://github.com/shirou/gopsutil into cpu_arm 10 years ago
Daniel Theophanes 9f2e6a74cc cpu: support ARM CPUs.
ARM CPUs don't include the same fields as  x86 and amd64 CPUs in
the /proc/cpuinfo list. Pull information from the /sys/...
device tree as well as updating when a CPU is done in cpuinfo.

Fixes #88
10 years ago
Jonathan Chauncey 0461c50666 chore(*): Fixes #94
Added the ability to fetch an alternative location for /proc via an
environment variable. If the env var is not set it will return /proc as
the default value.
10 years ago
Shirou WAKAYAMA a95dde9672 cpu[darwin]: separetes cpu_darwin to cgo and nocgo to get CPUTimes. 10 years ago
Ben Aldrich a4ec4177a6 Fix cpu percent on windows
Tested on windows 7:

When divided by 100 you get cpu percentage of  %0.14 when task manager shows %14. Once this is removed they match.
10 years ago
WAKAYAMA Shirou 4696985e84 cpu[windows]: skip if could not get cpu.LoadPercentage. 10 years ago
Shirou WAKAYAMA 47f6760cf3 cpu[darwin]: use CGO to get CPUTimes. This is breaking. see #66. 10 years ago
shirou 3c958a8ee6 Merge pull request #60 from mayowa/master
Bug fix and HostStatInfo.Platform* windows implementation
10 years ago
mayowa 6fa0704dbf fixed: ProcessorId doesnt return a value 10 years ago
Shirou WAKAYAMA 0d7ff2eb40 cpu[darwin]: convert cpu frequency to Mhz. 10 years ago
Chris Bednarski d5fa4f880f Read Darwin CPU frequency from sysctl hw.cpufrequency 10 years ago
mayowa 7889ce3e03 changed ProccessorId type to *string, cause wmi sometimes returns nil for it 10 years ago
mayowa 6a2bc5afe8 removed l2CacheSize as its not present in all wmi databases 10 years ago
Shirou WAKAYAMA cbe10d6761 cpu[darwin]: move helper path to under the HOME dir. 10 years ago
Shirou WAKAYAMA c195d77ce3 cpu[darwin]: enable cpu helper only the environemnetal variable set. 10 years ago
Shirou WAKAYAMA 755d3a4119 cpu[darwin]: change default tick to 100. 10 years ago
Shirou WAKAYAMA 12843632ca cpu[darwin]: experimental implemtation to get CPU times on darwin. 10 years ago
Shirou WAKAYAMA 5854011870 cpu: Steal, Guest, and GuestNice are not divided by CPU_TICK. 10 years ago
WAKAYAMA shirou 4bc631921f cpu: fix command output trim problem. 10 years ago
Shirou WAKAYAMA 8c17a750c6 get CLOCK TICK by using getconf. 10 years ago
gwind a750762737 Fix interpretation error about /proc/stat 10 years ago
WAKAYAMA shirou 64357f04e7 use StackExchange/wmi instead of invoking wmic process.
Note: This may not work on some old Windows XP.
10 years ago
WAKAYAMA Shirou 5f8b99aa65 windows: GetWmic returns [][]string where string split by "," 10 years ago
Shirou WAKAYAMA 170390c0df cpu: fix build option on unix. 10 years ago
WAKAYAMA Shirou ead8393137 cpu: use wmic to get CPU usage on Windows. 10 years ago
WAKAYAMA Shirou ec2b509dda cpu: skip percpu percent test if windows. Windows can only get one CPU info currently. 10 years ago