Skip to content

Commit d6309e9

Browse files
committed
Benchmark: implement memory query for Windows
Implement support for querying the high water mark for the working set for the current process. This is accomplished with the PSAPI (Version 2) API from Windows.
1 parent 25c701c commit d6309e9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Sources/SwiftDocC/Benchmark/Metrics/PeakMemory.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010

1111
import Foundation
12+
#if os(Windows)
13+
import WinSDK
14+
#endif
1215

1316
extension Benchmark {
1417
/// A peak memory footprint metric for the current process.
@@ -55,6 +58,16 @@ extension Benchmark {
5558

5659
return Int64(peakMemory * 1024) // convert from KBytes to bytes
5760
}
61+
#elseif os(Windows)
62+
private static func peakMemory() -> Int64? {
63+
var pmcStats = PROCESS_MEMORY_COUNTERS()
64+
guard K32GetProcessMemoryInfo(
65+
GetCurrentProcess(),
66+
&pmcStats,
67+
DWORD(MemoryLayout<PROCESS_MEMORY_COUNTERS>.size)
68+
) else { return nil }
69+
return Int64(pmcStats.PeakWorkingSetSize)
70+
}
5871
#endif
5972

6073
public var result: MetricValue? {

0 commit comments

Comments
 (0)