Skip to content

Commit 6ddab40

Browse files
committed
Incorporate PR Feedback
1 parent 4d46e16 commit 6ddab40

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

psapi.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,27 @@ func EnumProcesses() (pids []uint32, err error) {
100100
}
101101
}
102102

103-
// PerformanceInformation represents the PERFORMANCE_INFORMATION structure
103+
// PerformanceInformation represents the [PERFORMANCE_INFORMATION] structure
104+
//
105+
// [PERFORMANCE_INFORMATION]: https://learn.microsoft.com/en-us/windows/win32/api/psapi/ns-psapi-performance_information
104106
type PerformanceInformation struct {
105107
CB uint32
106-
CommitTotal uintptr
107-
CommitLimit uintptr
108-
CommitPeak uintptr
109-
PhysicalTotal uintptr
110-
PhysicalAvailable uintptr
111-
SystemCache uintptr
112-
KernelTotal uintptr
113-
KernelPaged uintptr
114-
KernelNonpaged uintptr
115-
PageSize uintptr
116-
HandleCount uint32
117-
ProcessCount uint32
118-
ThreadCount uint32
108+
CommitTotal uintptr // The number of pages currently committed by the system. Note that committing pages (using VirtualAlloc with MEM_COMMIT) changes this value immediately; however, the physical memory is not charged until the pages are accessed.
109+
CommitLimit uintptr // The current maximum number of pages that can be committed by the system without extending the paging file(s). This number can change if memory is added or deleted, or if pagefiles have grown, shrunk, or been added. If the paging file can be extended, this is a soft limit.
110+
CommitPeak uintptr // The maximum number of pages that were simultaneously in the committed state since the last system reboot.
111+
PhysicalTotal uintptr // The amount of actual physical memory, in pages.
112+
PhysicalAvailable uintptr // The amount of physical memory currently available, in pages. This is the amount of physical memory that can be immediately reused without having to write its contents to disk first. It is the sum of the size of the standby, free, and zero lists.
113+
SystemCache uintptr // The amount of system cache memory, in pages. This is the size of the standby list plus the system working set.
114+
KernelTotal uintptr // The sum of the memory currently in the paged and nonpaged kernel pools, in pages.
115+
KernelPaged uintptr // The memory currently in the paged kernel pool, in pages.
116+
KernelNonpaged uintptr // The memory currently in the nonpaged kernel pool, in pages.
117+
PageSize uintptr // The size of a page, in bytes.
118+
HandleCount uint32 // The current number of open handles.
119+
ProcessCount uint32 // The current number of processes.
120+
ThreadCount uint32 // The current number of threads.
119121
}
120122

121-
// GetPerformanceInfo retrieves performance information for the system
123+
// GetPerformanceInfo retrieves performance information for the system.
122124
// https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getperformanceinfo
123125
func GetPerformanceInfo() (PerformanceInformation, error) {
124126
var pi PerformanceInformation

psapi_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package windows
2222

2323
import (
24+
"slices"
2425
"syscall"
2526
"testing"
2627
"unsafe"
@@ -120,12 +121,6 @@ func TestEnumProcesses(t *testing.T) {
120121

121122
// Verify that the current process is in the list
122123
currentPID := uint32(syscall.Getpid())
123-
found := false
124-
for _, pid := range pids {
125-
if pid == currentPID {
126-
found = true
127-
break
128-
}
129-
}
124+
found := slices.Contains(pids, currentPID)
130125
assert.True(t, found, "Current process PID should be in the returned list")
131126
}

0 commit comments

Comments
 (0)