From d6309e9e8ff1cf377c537e2d0f15944be7efc572 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 29 May 2023 08:16:55 -0700 Subject: [PATCH] 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. --- .../SwiftDocC/Benchmark/Metrics/PeakMemory.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sources/SwiftDocC/Benchmark/Metrics/PeakMemory.swift b/Sources/SwiftDocC/Benchmark/Metrics/PeakMemory.swift index 3cb2569205..b434196fe4 100644 --- a/Sources/SwiftDocC/Benchmark/Metrics/PeakMemory.swift +++ b/Sources/SwiftDocC/Benchmark/Metrics/PeakMemory.swift @@ -9,6 +9,9 @@ */ import Foundation +#if os(Windows) +import WinSDK +#endif extension Benchmark { /// A peak memory footprint metric for the current process. @@ -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.size) + ) else { return nil } + return Int64(pmcStats.PeakWorkingSetSize) + } #endif public var result: MetricValue? {