Ctrl K
ComunidadGuías…

utils/stall/cputime_windows.go

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
//go:build windows

package stall

import (
	"time"

	"golang.org/x/sys/windows"
)

// ProcessCPUTime is the CPU time this process has used, user and kernel, all
// threads. ok is false when it cannot be read.
func ProcessCPUTime() (time.Duration, bool) {
	var creation, exit, kernel, user windows.Filetime
	if err := windows.GetProcessTimes(windows.CurrentProcess(), &creation, &exit, &kernel, &user); err != nil {
		return 0, false
	}
	// Filetime counts 100 ns intervals.
	ticks := int64(kernel.HighDateTime)<<32 | int64(kernel.LowDateTime)
	ticks += int64(user.HighDateTime)<<32 | int64(user.LowDateTime)
	return time.Duration(ticks * 100), true
}