Commit Graph

238 Commits (c0546fb392440dce7271930885241524709968d4)

Author SHA1 Message Date
shirou 4870f6f119
Merge pull request #1569 from scop/perf/regex-compile
Avoid repeated regexp compilations
Ville Skyttä 11bc5b3970 Avoid some uses of regexps
Ville Skyttä 362fa4b9c4 Avoid repeated regexp compilations
Jan De Dobbeleer a1eedcae8e
fix(linux): validate cpu fields length before accessing index
Justin Yang 826037fe4b Fix build_test on amd64 NetBSD
Justin Yang 7ffb24dbe3
Merge branch 'shirou:master' into feature/netbsd-arm64-port
Justin Yang def3572629 format the code
Justin Yang 4a46201e00 cpu && host: fix compile time errors
shirou 0665cafa1b chore: replace deprecated ioutil package to os and io
Justin Yang 6a4ec32f3b cpu: remove wrong info copied from openbsd
shirou febdeab871 chore: change CIRCLECI environment variable to CI.
Justin Yang 2684012ab2 Initial support for NetBSD.
Currently the changes are all copied from shirou/gopsutil#1364
Kishen V 63e0b63ab8 Enable setting of vendor and related information for all Power versions
Antoine Toulme 38b94668ea allow to pass context values to override environment variables
Matthieu MOREL 1fb1e3e3e6 ci(lint): correct gci linter
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
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
```
shirou f78f9a6bb8
Merge pull request #1414 from jeffweiss/bugfix/get_tests_working_on_s390x
get tests passing on s390x
shirou 852f455217 fix lint
Jeff Weiss f850a69ba1 get tests passing on s390x
Guoqi Chen b055174e9e cpu: Add the matching rule "Model Name" when parsing cpuinfo
This is to fix the error of running TestCpuInfo on Linux/long64. In loong64
/proc/cpuinfo, the model name is capitalize the first letter

Reference:
  https://github.com/torvalds/linux/blob/master/arch/loongarch/kernel/proc.c

Signed-off-by: Guoqi Chen <chenguoqi@loongson.cn>
Eng Zer Jun 37894e9b28
test: use `T.Setenv` to set env vars in tests
This commit replaces `os.Setenv` with `t.Setenv` in tests. The
environment variable is automatically restored to its original value
when the test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.Setenv
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
shirou 835767a611
Merge pull request #1389 from sgthammer/feature/fix-arm-modelname
fill modelName for all cores in arm64 devices
Tobias Klauser f2bf9a480a
cpu: use windows.GetActiveProcessorCount
Use GetActiveProcessorCount and the ALL_PROCESSOR_GROUPS const provided
in golang.org/x/sys/windows. The function is available on Windows 7 and
later. Go requires Windows 7, see https://go.dev/doc/go1.11#ports
sgthammer 83256398be fill modelName for all cores in arm64 devices
Yalcin Ozbek 8bf7f37fca
the code has been moved before append
Signed-off-by: Yalcin Ozbek <yalcinozbekceng@gmail.com>
Yalcin Ozbek 4314a0567b
the code has been moved outside the loop.
Signed-off-by: Yalcin Ozbek <yalcinozbekceng@gmail.com>
Yalcin Ozbek 13f00fde46
code review fix
Signed-off-by: Yalcin Ozbek <yalcinozbekceng@gmail.com>
Yalcin Ozbek 102439862e
feat: Setting the model name for arm based CPUs
- Added arm model and model name as map.
- The modelName is set again according to the model value when the model name is empty.
- Based on lscpu source code.. https://github.com/util-linux/util-linux/blob/master/sys-utils/lscpu-arm.c

---

Signed-off-by: Yalcin Ozbek <yalcinozbekceng@gmail.com>
shirou d1cc7d2125 fix(cpu): fix cpu total and busy calc
xca1075 3d643b9b73 parse cpu values as float
xca1075 b3ab1561bc more aix nocgo implementations
xca1075 d4f012c565 fix aix nocgo compile
xca1075 d177019851 fix go build flags for aix/cpu
xca1075 e24e72062b aix: split code, that uses perfstat, to _cgo and _nocgo files
Martin Reindl 1d89235f34 host: add support for OpenBSD/armv7
martin 414ada919c Fix telegraf 1.22.0 build on OpenBSD/arm64:
../../../go/pkg/mod/github.com/shirou/gopsutil/v3@v3.22.2/cpu/cpu_openbsd.go:63:14: undefined: cpuTimes
Ville Skyttä f7e1f36418 refactor: remove unnecessary exec.LookPath calls
Executing the command does the lookup if needed and returns the same
error when not found, no need to do it separately.
shirou d33b2dfda5
Merge pull request #1244 from omar-polo/master
fix cpu_openbsd.go once and for all
Omar Polo 73f9c8dfd5 avoid cgo for cpu_openbsd
Even thought OpenBSD often breaks the ABI compatibility and doesn't make
*any* promise of "stability", this project aims to be "pure go" so avoid
doing inter-op at the cost of artificially reducing the number of
supported architectures down to amd64 and i386.

To add support for another architecture (e.g. arm), add another file
cpu_openbsd_${arch}.go like done for 386 and amd64.  The fields are
declared as `long' in C, so pick the appropriate size when declaring the
struct.
Omar Polo 3c3c017f23 avoid copying kernCPUStats
Omar Polo 57d5711d44 refactor TimesWithContext
don't make assumptions on which CPUs are online and wich aren't based
on hw.smt and hw.ncpuonline.  Rather, use KERN_CPUSTATS to get the CPU
statistics, which includes a flag field that can tell us if that CPU
is online or not.
Omar Polo 16cc7d7d73 improve sysctl parsing: use native byte order
We can't use unix.Sysctl* for some sysctls, so we're on our own with
converting data from C arrays.

Don't assume that the byte order is little endian but do the right
thing.  Moreover, there's a little distinction in the sizes reported
by KERN_CPTIME (long[cpustates]) and KERN_CPTIME2
(u_int64_t[cpustates]) so account for that too.
Omar Polo 73db061652 some typos + rename smt to smtEnabled for readability
Omar Polo 9203029aae drop compatibilty with OpenBSD < 6.4
6.3 was EOL'd more than three years ago!
Matthieu MOREL 8ba220d241 enable contextcheck linter
mmorel-35 1e6b445a8a gofumpt
mmorel-35 eb5f6203d8 gofmt
Matthieu MOREL c8fd8c7b1f
enable unparam linter
shirou 69ea4bfdae
Merge pull request #1194 from mmorel-35/master
Enable errorlint and gci linters
Matthieu MOREL b673968d5d
enable errorlint linter