Commit dfb647c1 by 陶腾飞

2022年3月27日:加快CPU获取信息的速度

parent 4d99535a
...@@ -38,4 +38,6 @@ Get-PhysicalDisk ...@@ -38,4 +38,6 @@ Get-PhysicalDisk
2022年3月19日:修复无法找到内存总量信息,并行获取硬件信息 2022年3月19日:修复无法找到内存总量信息,并行获取硬件信息
2022年3月26日:增加内存的DDR信息 2022年3月26日:增加内存的DDR信息
\ No newline at end of file
2022年3月27日:加快CPU获取信息的速度
\ No newline at end of file
...@@ -83,19 +83,30 @@ func PSCommandOutputNoSplit(cmd string) (string, error) { ...@@ -83,19 +83,30 @@ func PSCommandOutputNoSplit(cmd string) (string, error) {
} }
func getHardwareCPUForPS() (string, string, string, string) { func getHardwareCPUForPS() (string, string, string, string) {
var c, j int
var cpuCount, cpuName, cpuCores, cpuLogicalProcessors string
cpuUN, _ := PSCommandOutputNoSplit("Get-WmiObject -Class Win32_Processor | select Name,NumberOfCores,NumberOfLogicalProcessors | format-list")
for _, line := range strings.Split(cpuUN, "\n") {
if strings.Index(line, "Name") != -1 {
mi := strings.TrimSpace(strings.Split(line, ":")[1])
cpuName = mi
c++
} else if strings.Index(line, "NumberOfCores") != -1 {
mi := strings.TrimSpace(strings.Split(line, ":")[1])
cpuCores = mi
c++
} else if strings.Index(line, "NumberOfLogicalProcessors") != -1 {
mi := strings.TrimSpace(strings.Split(line, ":")[1])
cpuLogicalProcessors = mi
c++
}
if c == 3 {
c = 0
j++
}
cpuNameUN, _ := PSCommandOutputNoSplit("Get-WmiObject -Class Win32_Processor | Select Name") cpuCount = strconv.Itoa(j)
cpuName := strings.TrimSpace(strings.Split(cpuNameUN, "\n")[3]) }
cpuCountUN, _ := PSCommandOutputNoSplit("Get-WmiObject -Class Win32_Processor | select Name |measure | select count")
cpuCount := strings.TrimSpace(strings.Split(cpuCountUN, "\n")[3])
cpuCoresUN, _ := PSCommandOutputNoSplit("Get-WmiObject -Class Win32_Processor | select NumberOfCores")
cpuCores := strings.TrimSpace(strings.Split(cpuCoresUN, "\n")[3])
cpuLogicalProcessorsUN, _ := PSCommandOutputNoSplit("Get-WmiObject -Class Win32_Processor | select NumberOfLogicalProcessors")
cpuLogicalProcessors := strings.TrimSpace(strings.Split(cpuLogicalProcessorsUN, "\n")[3])
return cpuCount, cpuName, cpuCores, cpuLogicalProcessors return cpuCount, cpuName, cpuCores, cpuLogicalProcessors
} }
func getHardwareMemoryForPS() ([]int, []string, []string, int) { func getHardwareMemoryForPS() ([]int, []string, []string, int) {
...@@ -222,7 +233,7 @@ func main() { ...@@ -222,7 +233,7 @@ func main() {
var ch = make(chan int) var ch = make(chan int)
var Memory, Disk string var Memory, Disk string
fmt.Println("查看硬件(CPU、内存、硬盘)小工具 -- made in 陶腾飞(2022年3月26日)") fmt.Println("查看硬件(CPU、内存、硬盘)小工具 -- made in 陶腾飞(2022年3月27日)")
// cpu // cpu
go func() { go func() {
<-ch <-ch
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment