Skip to content

Commit

Permalink
Benchmark: implement memory query for Windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
compnerd committed May 30, 2023
1 parent 25c701c commit d6309e9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Sources/SwiftDocC/Benchmark/Metrics/PeakMemory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/

import Foundation
#if os(Windows)
import WinSDK
#endif

extension Benchmark {
/// A peak memory footprint metric for the current process.
Expand Down Expand Up @@ -55,6 +58,16 @@ extension Benchmark {

return Int64(peakMemory * 1024) // convert from KBytes to bytes
}
#elseif os(Windows)
private static func peakMemory() -> Int64? {
var pmcStats = PROCESS_MEMORY_COUNTERS()
guard K32GetProcessMemoryInfo(
GetCurrentProcess(),
&pmcStats,
DWORD(MemoryLayout<PROCESS_MEMORY_COUNTERS>.size)
) else { return nil }
return Int64(pmcStats.PeakWorkingSetSize)
}
#endif

public var result: MetricValue? {
Expand Down

0 comments on commit d6309e9

Please sign in to comment.