shirou / gopsutil

psutil for golang
Other
10.56k stars 1.58k forks source link

cpu.Info error on v3 for windows 10 #982

Closed araoko closed 3 years ago

araoko commented 3 years ago

Describe the bug calling the cpu.Info function when the imported package is "github.com/shirou/gopsutil/v3/cpu" returns "Exception occurred. (Invalid class )" error while it worked with package "github.com/shirou/gopsutil/cpu". I have looked into the source code (common_wimndows.go, cpu_windows.go) for both packages but cannot find any difference in those files that could cause the error on v3.

To Reproduce

c, err := cpu.Info()
    if err != nil {
        fmt.Println("Could not retrieve CPU details.")
        log.Fatal(err)
    }

Environment (please complete the following information): Microsoft Windows [Version 10.0.18363.1139] 64bit CPU Model: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz

shirou commented 3 years ago

Thank you for the report! I found WMI require _ in a struct like win32_Processor . It will be fixed by #983. Could you check it on your local?

araoko commented 3 years ago

Thank you for the report! I found WMI require _ in a struct like win32_Processor . It will be fixed by #983. Could you check it on your local?

Yes its win32Processor in v3, I just didn't expect the struct name to cause the error since the compiler did not complain

Lomanic commented 3 years ago

github.com/StackEchange/wmi uses reflection at runtime to get struct names to infer the wmi types used in queries, the compiler didn't complain as the types were OK from its point of view at compile time.