Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue-1357] fix by calling NtQuerySystemInformation #1358

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

elfrucool
Copy link

@elfrucool elfrucool commented Sep 29, 2022

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

@shirou
Copy link
Owner

shirou commented Sep 30, 2022

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.

@elfrucool
Copy link
Author

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 added a commit to CloudSoda/gopsutil that referenced this pull request Mar 25, 2024
Use the same logic as in Linux[^1] but with
`NtQuerySystemInformation` Windows API call.[^2]

[^1]: https://www.brendangregg.com/blog/2017-08-08/linux-load-averages.html

[^2]: see shirou#1358
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants