1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-24 13:48:56 +08:00

33 Commits

Author SHA1 Message Date
uubulb
9e6efdb991 update disk & cpu & process 2024-09-20 22:24:12 +08:00
uubulb
701a74be41 feat(cpu, mem, sensors)(darwin): cgo-free implementations 2024-09-04 23:23:10 +08:00
shirou
bc060cc227 add SPDX License, remove old build tag, and replace import 2024-05-28 22:27:17 +09:00
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
```
2023-03-27 21:17:12 -05:00
mmorel-35
1e6b445a8a gofumpt 2021-12-22 21:54:41 +00:00
shirou
bde422a2ff [cpu][mac] doesn't return error when cpu.frequency 2021-12-04 04:23:33 +00:00
shirou
0969c9436b delete v2 directory, move v3 to top #1078 2021-11-30 23:47:59 +00:00
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.
2021-02-19 12:20:10 +01:00
renaynay
d4985c9690
added check for CLK_TCK 2020-05-12 13:59:26 +02:00
Minje Park
caebe5dbe4 returning 0 and error if SysctlUint32 raises an error 2019-03-21 23:52:34 +09:00
Minje Park
ca1fcad2aa retrieve a cpu count depends on an boolean argument 2019-03-17 23:18:29 +09: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
shirou
145dca90f7 change to use CommandContext. 2018-03-31 21:35:53 +09:00
shirou
4c73494c78 Add WithContext functions. 2017-12-31 15:25:49 +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
Shirou WAKAYAMA
57f6aebc7e add Timeout to invoke command and use common.Invoke refs: #201 2016-05-20 17:59:41 +09:00
Shirou WAKAYAMA
d21ed2b40d search path via exec.LookPath before actual invoke. 2016-04-01 22:13:05 +09:00
Shirou WAKAYAMA
ea152ea901 [BREAKING CHANGE] rename functions to pass golint. ex) net.NetIOCounters -> net.IOCounters 2016-03-22 23:09:12 +09:00
Shirou WAKAYAMA
a95dde9672 cpu[darwin]: separetes cpu_darwin to cgo and nocgo to get CPUTimes. 2015-10-10 22:13:38 +09:00
Shirou WAKAYAMA
47f6760cf3 cpu[darwin]: use CGO to get CPUTimes. This is breaking. see #66. 2015-08-28 17:01:43 +09:00
Shirou WAKAYAMA
0d7ff2eb40 cpu[darwin]: convert cpu frequency to Mhz. 2015-08-27 15:50:35 +09:00
Chris Bednarski
d5fa4f880f Read Darwin CPU frequency from sysctl hw.cpufrequency 2015-08-26 11:45:09 -07:00
Shirou WAKAYAMA
cbe10d6761 cpu[darwin]: move helper path to under the HOME dir. 2015-07-29 22:25:42 +09:00
Shirou WAKAYAMA
c195d77ce3 cpu[darwin]: enable cpu helper only the environemnetal variable set. 2015-07-25 12:49:02 +09:00
Shirou WAKAYAMA
755d3a4119 cpu[darwin]: change default tick to 100. 2015-07-24 15:01:22 +09:00
Shirou WAKAYAMA
12843632ca cpu[darwin]: experimental implemtation to get CPU times on darwin. 2015-07-24 14:49:35 +09:00
WAKAYAMA shirou
4bc631921f cpu: fix command output trim problem. 2015-07-17 21:52:43 +09:00
Shirou WAKAYAMA
8c17a750c6 get CLOCK TICK by using getconf. 2015-07-17 21:46:26 +09:00
WAKAYAMA shirou
b8dc51929a forget to change float32 to float64 2015-02-15 20:48:29 +09:00
Shirou WAKAYAMA
4b5bf22b88 change CPUTimes type from float32 to float64 to resolve precision issue. 2015-02-13 22:45:12 +09:00
Shirou WAKAYAMA
13cd195a7e change package name. 2014-12-30 22:09:05 +09:00
Shirou WAKAYAMA
a4671fcc2a move subdirectories. refer to issue #24 2014-11-27 10:18:15 +09:00