shirou / gopsutil

psutil for golang
Other
10.36k stars 1.57k forks source link

Increasing precision for virtual memory used percent on windows #1619

Open rayjanoka opened 4 months ago

rayjanoka commented 4 months ago

Hey! Nice library!!

I found that the virtualMemory.UsedPercent returned by windows is just a whole number and we lose some precision there. I computed it instead using total - available / total * 100 so we can get the same precision we see on linux.

virtMemTest - Old 28.000000 : New 28.606437
virtMemTest - Old 28.000000 : New 28.594666
virtMemTest - Old 28.000000 : New 28.637374
shirou commented 3 months ago

Good point. Thanks you for opening this PR.

However, I noticed that psutil uses PERFORMANCE_INFORMATION instead of MEMORYSTATUSEX. So I think we should change that. After the change, the precision issue will be solved.