gopsutil icon indicating copy to clipboard operation
gopsutil copied to clipboard

[issue-1357] fix by calling NtQuerySystemInformation

Open elfrucool opened this issue 3 years ago • 2 comments

I use NtQuerySystemInformation instead of ProcessorQueueLengthCounter because the latter returns zero all time.

Additionally, I'm exposing procstats package so developers can walk through processes and threads getting their status and other data.

Additional methods/functions can be added.

Tested with this program:

//go:build windows
// +build windows

package main

import (
	"fmt"
	"os"
	"time"

	"github.com/shirou/gopsutil/v3/load"
)

func main() {
	var countdown int = 60 * 1

	avg, err := load.Avg()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error calculating load average: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("[%2d] average: %.2f %.2f %.2f\n", countdown, avg.Load1, avg.Load5, avg.Load15)

	for range time.Tick(2 * time.Second) {
		countdown = countdown - 2
		avg, err := load.Avg()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error calculating load average: %v\n", err)
			os.Exit(1)
		}
		fmt.Printf("[%2d] average: %.2f %.2f %.2f\n", countdown, avg.Load1, avg.Load5, avg.Load15)
		if countdown <= 0 {
			break
		}
	}
}

elfrucool avatar Sep 29 '22 07:09 elfrucool

related to #1357

Thank you for your contribution. However, the psutil uses "Processor Queue Length", and it works, gopsutil does has some issue. So I want to fix that instead of use other Win API.

And please do not add new package. We want to keep API and gopsutil aim to be multi-platform.

shirou avatar Sep 30 '22 08:09 shirou

related to #1357

Thank you for your contribution. However, the psutil uses "Processor Queue Length", and it works, gopsutil does has some issue. So I want to fix that instead of use other Win API.

And please do not add new package. We want to keep API and gopsutil aim to be multi-platform.

Removed the new package, Processor Queue Length call returns 0 on my computer Microsoft Windows [Versión 10.0.19044.1889] and other folks' too.

elfrucool avatar Oct 04 '22 18:10 elfrucool