1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-05-10 19:29:14 +08:00

226 Commits

Author SHA1 Message Date
Kishen V
63e0b63ab8 Enable setting of vendor and related information for all Power versions 2023-07-25 09:59:38 +05:30
Antoine Toulme
38b94668ea allow to pass context values to override environment variables 2023-06-02 01:31:05 -07:00
Matthieu MOREL
1fb1e3e3e6 ci(lint): correct gci linter
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-04-04 18:07:22 +00: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
shirou
f78f9a6bb8
Merge pull request #1414 from jeffweiss/bugfix/get_tests_working_on_s390x
get tests passing on s390x
2023-02-12 18:58:26 +09:00
shirou
852f455217 fix lint 2023-02-12 09:24:52 +00:00
Jeff Weiss
f850a69ba1 get tests passing on s390x 2023-02-07 14:12:31 -08:00
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>
2023-01-14 07:05:49 +08:00
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>
2022-12-20 13:13:01 +08:00
shirou
835767a611
Merge pull request #1389 from sgthammer/feature/fix-arm-modelname
fill modelName for all cores in arm64 devices
2022-12-19 22:14:07 +09:00
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
2022-12-07 13:51:29 +01:00
sgthammer
83256398be fill modelName for all cores in arm64 devices 2022-12-06 14:56:51 +03:00
Yalcin Ozbek
8bf7f37fca
the code has been moved before append
Signed-off-by: Yalcin Ozbek <yalcinozbekceng@gmail.com>
2022-11-05 16:40:39 +03:00
Yalcin Ozbek
4314a0567b
the code has been moved outside the loop.
Signed-off-by: Yalcin Ozbek <yalcinozbekceng@gmail.com>
2022-11-05 16:37:04 +03:00
Yalcin Ozbek
13f00fde46
code review fix
Signed-off-by: Yalcin Ozbek <yalcinozbekceng@gmail.com>
2022-11-05 15:06:30 +03:00
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>
2022-11-05 02:36:48 +03:00
shirou
d1cc7d2125 fix(cpu): fix cpu total and busy calc 2022-07-09 02:13:44 +00:00
xca1075
3d643b9b73 parse cpu values as float 2022-06-17 15:10:37 +02:00
xca1075
b3ab1561bc more aix nocgo implementations 2022-06-17 14:53:16 +02:00
xca1075
d4f012c565 fix aix nocgo compile 2022-06-03 17:43:52 +02:00
xca1075
d177019851 fix go build flags for aix/cpu 2022-06-03 17:09:11 +02:00
xca1075
e24e72062b aix: split code, that uses perfstat, to _cgo and _nocgo files 2022-06-03 17:01:36 +02:00
Martin Reindl
1d89235f34 host: add support for OpenBSD/armv7 2022-04-15 21:11:36 +02:00
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
2022-03-24 17:55:48 +01:00
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.
2022-03-04 18:56:33 +02:00
shirou
d33b2dfda5
Merge pull request #1244 from omar-polo/master
fix cpu_openbsd.go once and for all
2022-02-25 23:25:27 +09:00
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.
2022-02-24 15:05:18 +01:00
Omar Polo
3c3c017f23 avoid copying kernCPUStats 2022-02-08 11:41:54 +00:00
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.
2022-02-06 23:47:17 +00:00
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.
2022-02-06 23:47:17 +00:00
Omar Polo
73db061652 some typos + rename smt to smtEnabled for readability 2022-02-06 23:47:17 +00:00
Omar Polo
9203029aae drop compatibilty with OpenBSD < 6.4
6.3 was EOL'd more than three years ago!
2022-02-06 23:47:16 +00:00
Matthieu MOREL
8ba220d241 enable contextcheck linter 2022-01-24 09:26:50 +01:00
mmorel-35
1e6b445a8a gofumpt 2021-12-22 21:54:41 +00:00
mmorel-35
eb5f6203d8 gofmt 2021-12-22 21:46:33 +00:00
Matthieu MOREL
c8fd8c7b1f
enable unparam linter 2021-12-22 19:53:14 +01:00
shirou
69ea4bfdae
Merge pull request #1194 from mmorel-35/master
Enable errorlint and gci linters
2021-12-22 21:43:03 +09:00
Matthieu MOREL
b673968d5d
enable errorlint linter 2021-12-04 22:29:38 +01:00
shirou
bde422a2ff [cpu][mac] doesn't return error when cpu.frequency 2021-12-04 04:23:33 +00:00
shirou
d2e27c1712 fix dependabot v2 deletion. 2021-12-01 00:12:55 +00:00
shirou
0969c9436b delete v2 directory, move v3 to top #1078 2021-11-30 23:47:59 +00:00
shirou
0fdf65fa3e Change to use yusufpapurcu/wmi from StackExchange/wmi. 2021-11-20 11:36:30 +00:00
Huan Wang
6a572952f0 fix slow cpuinfo on multisocket config
updated win32_Processor struct to exclude loadpercentage field.
The loadpercentage takes linearly more time as the # of sockets
increases. By default vSphere maps 1 vCPU to 1 socket, resulting in very
poor performance when getting CPU info against, saying, 40 vCPU VM
(basically 40 sockets as seen by the VM).
2021-06-14 22:00:22 -06:00
Ville Skyttä
47f2f0eee5 [cpu][linux] add more ARM hw implementers 2021-05-30 15:39:19 +03:00
Ville Skyttä
b8ac60acc1 [cpu][linux] more info for ARM processors
https://developer.arm.com/documentation/ddi0337/h/system-control/register-descriptions/cpuid-base-register--cpuid
2021-05-20 19:35:01 +03:00
Ville Skyttä
2278747969 [v2][cpu][solaris] psrinfo parsing fixes 2021-05-08 16:41:03 +03:00
Lomanic
d447f9f7ed
Merge pull request #1039 from Lomanic/issue1037
[cpu][linux] Fix #1037 only count logical cores where 2nd field is a number
2021-04-14 00:58:15 +02:00
Ivan Babrou
19ac85b504 Add missing TargetConditionals.h include, closes #976 2021-03-01 09:41:31 -08:00
Lomanic
6589c5c274 [cpu][linux] Fix #1037 only count logical cores where 2nd field is a number 2021-02-22 00:28:56 +01: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