-
Notifications
You must be signed in to change notification settings - Fork 3
/
info.go
84 lines (68 loc) · 1.87 KB
/
info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package cpuKit
import (
"github.com/klauspost/cpuid/v2"
"github.com/richelieu-yang/chimera/v3/src/core/sliceKit"
"github.com/sirupsen/logrus"
"runtime"
)
// GetCpuNumber returns the number of logical CPUs usable by the current process.
var GetCpuNumber func() int = runtime.NumCPU
// HasFeature CPU是否支持特定指令集?
/*
@param id e.g. cpuid.AVX
*/
func HasFeature(id cpuid.FeatureID) bool {
return cpuid.CPU.Has(id)
}
// InVirtualMachine 是否在虚拟机中?
var InVirtualMachine func() bool = cpuid.CPU.VM
func GetVendorID() cpuid.Vendor {
return cpuid.CPU.VendorID
}
// GetVendorString CPU供应商
/*
@return e.g."Apple"
*/
func GetVendorString() string {
return cpuid.CPU.VendorString
}
// GetBrandName CPU品牌名称
/*
@return e.g."Apple M1 Pro"
*/
func GetBrandName() string {
return cpuid.CPU.BrandName
}
func GetPhysicalCores() int {
return cpuid.CPU.PhysicalCores
}
func GetThreadsPerCore() int {
return cpuid.CPU.ThreadsPerCore
}
func GetLogicalCores() int {
return cpuid.CPU.LogicalCores
}
// GetFeatureSet 获取CPU支持的指令集s.
/*
Linux命令: cat /proc/cpuinfo
*/
var GetFeatureSet func() []string = cpuid.CPU.FeatureSet
func GetFamily() int {
return cpuid.CPU.Family
}
func GetModel() int {
return cpuid.CPU.Model
}
func GetFrequency() int64 {
return cpuid.CPU.Hz
}
func PrintBasicDetails(logger *logrus.Logger) {
logger.Infof("[CHIMERA, CPU] in a virtual machine? [%t].", InVirtualMachine())
logger.Infof("[CHIMERA, CPU] vendor id: [%s].", GetVendorID())
logger.Infof("[CHIMERA, CPU] vendor string: [%s].", GetVendorString())
logger.Infof("[CHIMERA, CPU] brand name: [%s].", GetBrandName())
logger.Infof("[CHIMERA, CPU] CPU number: [%d].", GetCpuNumber())
logger.Infof("[CHIMERA, CPU] features: [%s].", sliceKit.Join(GetFeatureSet(), ","))
logger.Infof("[CHIMERA, CPU] frequency: [%d]hz.", GetFrequency())
printBasicDetails(logger)
}