|
|
|
@ -3,7 +3,9 @@
|
|
|
|
|
package gopsutil
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"regexp"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// sys/resource.h
|
|
|
|
@ -48,3 +50,38 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
|
|
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns only one CPUInfoStat on FreeBSD
|
|
|
|
|
func CPUInfo() ([]CPUInfoStat, error) {
|
|
|
|
|
filename := "/var/run/dmesg.boot"
|
|
|
|
|
lines, _ := readLines(filename)
|
|
|
|
|
|
|
|
|
|
var ret []CPUInfoStat
|
|
|
|
|
|
|
|
|
|
c := CPUInfoStat{}
|
|
|
|
|
for _, line := range lines {
|
|
|
|
|
if matches := regexp.MustCompile(`CPU:\s+(.+) \(([\d.]+).+\)`).FindStringSubmatch(line); matches != nil {
|
|
|
|
|
c.ModelName = matches[1]
|
|
|
|
|
c.Mhz = parseFloat64(matches[2])
|
|
|
|
|
} else if matches := regexp.MustCompile(`Origin = "(.+)" Id = (.+) Family = (.+) Model = (.+) Stepping = (.+)`).FindStringSubmatch(line); matches != nil {
|
|
|
|
|
c.VendorID = matches[1]
|
|
|
|
|
c.Family = matches[3]
|
|
|
|
|
c.Model = matches[4]
|
|
|
|
|
c.Stepping = parseInt32(matches[5])
|
|
|
|
|
} else if matches := regexp.MustCompile(`Features=.+<(.+)>`).FindStringSubmatch(line); matches != nil {
|
|
|
|
|
for _, v := range strings.Split(matches[1], ",") {
|
|
|
|
|
c.Flags = append(c.Flags, strings.ToLower(v))
|
|
|
|
|
}
|
|
|
|
|
} else if matches := regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`).FindStringSubmatch(line); matches != nil {
|
|
|
|
|
for _, v := range strings.Split(matches[1], ",") {
|
|
|
|
|
c.Flags = append(c.Flags, strings.ToLower(v))
|
|
|
|
|
}
|
|
|
|
|
} else if matches := regexp.MustCompile(`Logical CPUs per core: (\d+)`).FindStringSubmatch(line); matches != nil {
|
|
|
|
|
// FIXME: no this line?
|
|
|
|
|
c.Cores = parseInt32(matches[1])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return append(ret, c), nil
|
|
|
|
|
}
|
|
|
|
|