shirou / gopsutil

psutil for golang
Other
10.63k stars 1.59k forks source link

Interesting result of cpu.Info() on Linux (20.04.3 Ubuntu in my case) #1165

Open mykolq opened 3 years ago

mykolq commented 3 years ago

Problem cpu.Info() shows theads count array, not physical cpu

How to reproduce

import (
  "fmt"
  "github.com/shirou/gopsutil/v3/cpu"
)

func main() {
  cpuAllInfo, err := cpu.Info()
  if err != nil {

  }
  fmt.Println(cpuAllInfo)
  fmt.Println(len(cpuAllInfo))
}

but i have two cpu physically. 32 threads

cat /proc/cpuinfo | grep -E  'physical id' | sort | uniq
physical id     : 0
physical id     : 1
cat /proc/cpuinfo | grep -E  'core id' | wc -l
32

Expected behavior cpu.Info() shows physical cpu info. like in windows or freebsd

Environment (please complete the following information):

cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
uname -a
Linux srvnamehere 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

In windows:

[{"cpu":0,"vendorId":"GenuineIntel","family":"7681","model":"","stepping":0,"physicalId":"BFEBFBFF000206D7","coreId":"","cores":12,"modelName":"Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz","mhz":2001,"cacheSize":0,"flags":[],"microcode":""} {"cpu":1,"vendorId":"GenuineIntel","family":"7681","model":"","stepping":0,"physicalId":"BFEBFBFF000206D7","coreId":"","cores":12,"modelName":"Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz","mhz":2001,"cacheSize":0,"flags":[],"microcode":""}]
2

In windows cores equal theads, but it is another story =)

Lomanic commented 2 years ago

Can you share the content of /proc/cpuinfo?

Your post is missing the result of your test program, can you add it back there?