//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) }