Testing for linux cpuinfo
This commit is contained in:
1 parent
cbc9e4a0b4
commit
ea5e79a46a
8 files changed
+172
-20
No files matched your search
@@ -0,0 +1,48 @@
|
||||
//go:build windows
|
||||
|
||||
package processor
|
||||
|
||||
import (
|
||||
"rpi5-health/internal/windows_system"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
type DWORD uint32
|
||||
|
||||
type PFILETIME struct {
|
||||
dwLowDateTime DWORD
|
||||
dwHighDateTime DWORD
|
||||
}
|
||||
|
||||
func getWinCpuInfo(getSystemTimes *windows.LazyProc) ProcessorInformation {
|
||||
var lpIdleTime PFILETIME
|
||||
var lpKernelTime PFILETIME
|
||||
var lpUserTime PFILETIME
|
||||
|
||||
getSystemTimes.Call(
|
||||
uintptr(unsafe.Pointer(&lpIdleTime)),
|
||||
uintptr(unsafe.Pointer(&lpKernelTime)),
|
||||
uintptr(unsafe.Pointer(&lpUserTime)),
|
||||
)
|
||||
|
||||
timeSpentIdlingTicks := fileTimeToTicks(lpIdleTime)
|
||||
timeSpentByKernelTicks := fileTimeToTicks(lpKernelTime) - timeSpentIdlingTicks // kernel time includes idling by default
|
||||
timeSpentByUserTicks := fileTimeToTicks(lpUserTime)
|
||||
|
||||
return ProcessorInformation{
|
||||
IdleTimeSinceBoot: timeSpentIdlingTicks,
|
||||
KernelTimeSinceBoot: timeSpentByKernelTicks,
|
||||
UserTimeSinceBoot: timeSpentByUserTicks,
|
||||
}
|
||||
}
|
||||
|
||||
func fileTimeToTicks(filetime PFILETIME) uint64 {
|
||||
// 100 nanosecond intervals since 1601, january 1
|
||||
return (uint64(filetime.dwHighDateTime) << 32) | uint64(filetime.dwLowDateTime)
|
||||
}
|
||||
|
||||
func GetCPUInformation() ProcessorInformation {
|
||||
return getWinCpuInfo(windows_system.GetWindowsTools().SystemTimes)
|
||||
}
|
||||
Reference in new issue
Block a user