Commit Graph

33 Commits (e6d16e985ab90c542b0eb0d43677c18dec46c887)

Author SHA1 Message Date
uubulb 9e6efdb991 update disk & cpu & process 6 months ago
uubulb 701a74be41 feat(cpu, mem, sensors)(darwin): cgo-free implementations 6 months ago
shirou bc060cc227 add SPDX License, remove old build tag, and replace import 10 months ago
Seth Hoenig 8617ff654a cpu: add frequency support for apple silicon m1/m2 cpus
This PR adds support for reading the frequency of Apple Silicon
M1/M2 CPUs. We do so by reading the values out of the IOKit
framework, as a few other projects have now demonstrated to be
possible. This requires the use of CGO. The library provides a
convenience IsAppleSilicon() guard to detect whether the values
can be read.

Currently gopsutil does not support the big.LITTLE CPU architectures
(i think?) - in fact the P and E cores have different max frequencies.
For now, just read the P core frequency. The E core data is readily
available if we want to read it in the future.

Closes #1000

Small example program

```go
package main

import (
        "fmt"

        "github.com/shoenig/go-m1cpu"

        "github.com/shirou/gopsutil/v3/cpu"
)

func main() {
        fmt.Println("is Apple Silicon:", m1cpu.IsAppleSilicon())
        fmt.Println("model name", m1cpu.ModelName())
        fmt.Println("pCore GHz", m1cpu.PCoreGHz())
        fmt.Println("eCore GHz", m1cpu.ECoreGHz())
        fmt.Println("pCore Hz", m1cpu.PCoreHz())
        fmt.Println("eCore Hz", m1cpu.ECoreHz())

        fmt.Println("----- gopsutil ----")

        infos, err := cpu.Info()
        if err != nil {
                panic(err)
        }

        for _, info := range infos {
                fmt.Println("info.Mhz", info.Mhz)
        }
}
```

```shell
go run main.go
is Apple Silicon: true
model name Apple M2 Pro
pCore GHz 3.504
eCore GHz 2.424
pCore Hz 3504000000
eCore Hz 2424000000
----- gopsutil ----
info.Mhz 3.504e+09
```
2 years ago
mmorel-35 1e6b445a8a gofumpt 3 years ago
shirou bde422a2ff [cpu][mac] doesn't return error when cpu.frequency 3 years ago
shirou 0969c9436b delete v2 directory, move v3 to top #1078 3 years ago
Tobias Klauser ee12f66e4d cpu, v3/cpu: use sysconf package instead of exec'ing getconf
Currently, ClocksPerSec is determined by exec'ing getconf in func init,
i.e. on startup of every program importing the package. getconf might
not be present on some systems or is not executable by the current user.
To avoid this hard to control dependency, use the
github.com/tklauser/go-sysconf package which implements sysconf(3)
entirely in Go without cgo. The package is supported on all platforms
currently supported by the cpu and v3/cpu package of gopsutil.
4 years ago
renaynay d4985c9690
added check for CLK_TCK 5 years ago
Minje Park caebe5dbe4 returning 0 and error if SysctlUint32 raises an error 6 years ago
Minje Park ca1fcad2aa retrieve a cpu count depends on an boolean argument 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
shirou 145dca90f7 change to use CommandContext. 7 years ago
shirou 4c73494c78 Add WithContext functions. 7 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
Shirou WAKAYAMA 57f6aebc7e add Timeout to invoke command and use common.Invoke refs: #201 9 years ago
Shirou WAKAYAMA d21ed2b40d search path via exec.LookPath before actual invoke. 9 years ago
Shirou WAKAYAMA ea152ea901 [BREAKING CHANGE] rename functions to pass golint. ex) net.NetIOCounters -> net.IOCounters 9 years ago
Shirou WAKAYAMA a95dde9672 cpu[darwin]: separetes cpu_darwin to cgo and nocgo to get CPUTimes. 10 years ago
Shirou WAKAYAMA 47f6760cf3 cpu[darwin]: use CGO to get CPUTimes. This is breaking. see #66. 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
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
WAKAYAMA shirou 4bc631921f cpu: fix command output trim problem. 10 years ago
Shirou WAKAYAMA 8c17a750c6 get CLOCK TICK by using getconf. 10 years ago
WAKAYAMA shirou b8dc51929a forget to change float32 to float64 10 years ago
Shirou WAKAYAMA 4b5bf22b88 change CPUTimes type from float32 to float64 to resolve precision issue. 10 years ago
Shirou WAKAYAMA 13cd195a7e change package name. 10 years ago
Shirou WAKAYAMA a4671fcc2a move subdirectories. refer to issue #24 10 years ago