From 958c5073d70b920be7eda004efe695bbbe1ee456 Mon Sep 17 00:00:00 2001 From: Joakim Hassila Date: Tue, 11 Oct 2022 08:41:02 +0200 Subject: [PATCH 1/7] Don't ask for malloc/system stats unless needed for benchmark --- .../BenchmarkSupport/BenchmarkRunner.swift | 85 ++++++++++++++++++- 1 file changed, 81 insertions(+), 4 deletions(-) diff --git a/Sources/BenchmarkSupport/BenchmarkRunner.swift b/Sources/BenchmarkSupport/BenchmarkRunner.swift index f432fc86..d4e02fba 100644 --- a/Sources/BenchmarkSupport/BenchmarkRunner.swift +++ b/Sources/BenchmarkSupport/BenchmarkRunner.swift @@ -122,6 +122,8 @@ public struct BenchmarkRunner: AsyncParsableCommand, BenchmarkRunnerReadWrite { // Could make an array with raw value indexing on enum for // performance if needed instead of dictionary var statistics: [BenchmarkMetric: Statistics] = [:] + var operatingSystemStatsRequested = false + var mallocStatsRequested = false // Create metric statistics as needed benchmark.metrics.forEach { metric in @@ -134,6 +136,13 @@ public struct BenchmarkRunner: AsyncParsableCommand, BenchmarkRunnerReadWrite { prefersLarger: metric.polarity() == .prefersLarger) } } + if mallocStatsProducerNeeded(metric) { + mallocStatsRequested = true + } + + if operatingSystemsStatsProducerNeeded(metric) { + operatingSystemStatsRequested = true + } } var iterations = 0 @@ -150,8 +159,14 @@ public struct BenchmarkRunner: AsyncParsableCommand, BenchmarkRunnerReadWrite { // Hook that is called before the actual benchmark closure run, so we can capture metrics here benchmark.measurementPreSynchronization = { - startMallocStats = mallocStatsProducer.makeMallocStats() - startOperatingSystemStats = operatingSystemStatsProducer.makeOperatingSystemStats() + if mallocStatsRequested { + startMallocStats = mallocStatsProducer.makeMallocStats() + } + + if operatingSystemStatsRequested { + startOperatingSystemStats = operatingSystemStatsProducer.makeOperatingSystemStats() + } + startTime = TimeInstant.now // must be last in closure } @@ -159,9 +174,13 @@ public struct BenchmarkRunner: AsyncParsableCommand, BenchmarkRunnerReadWrite { benchmark.measurementPostSynchronization = { stopTime = TimeInstant.now // must be first in closure - stopOperatingSystemStats = operatingSystemStatsProducer.makeOperatingSystemStats() + if operatingSystemStatsRequested { + stopOperatingSystemStats = operatingSystemStatsProducer.makeOperatingSystemStats() + } - stopMallocStats = mallocStatsProducer.makeMallocStats() + if mallocStatsRequested { + stopMallocStats = mallocStatsProducer.makeMallocStats() + } var delta = 0 @@ -334,3 +353,61 @@ public struct BenchmarkRunner: AsyncParsableCommand, BenchmarkRunnerReadWrite { } } } + +extension BenchmarkRunner { + func mallocStatsProducerNeeded(_ metric: BenchmarkMetric) -> Bool { + switch metric { + case .mallocCountLarge: + return true + case .memoryLeaked: + return true + case .mallocCountSmall: + return true + case .mallocCountTotal: + return true + case .allocatedResidentMemory: + return true + default: + return false + } + } +} + +extension BenchmarkRunner { + func operatingSystemsStatsProducerNeeded(_ metric: BenchmarkMetric) -> Bool { + switch metric { + case .cpuUser: + return true + case .cpuSystem: + return true + case .cpuTotal: + return true + case .peakMemoryResident: + return true + case .peakMemoryVirtual: + return true + case .syscalls: + return true + case .contextSwitches: + return true + case .threads: + return true + case .threadsRunning: + return true + case .readSyscalls: + return true + case .writeSyscalls: + return true + case .readBytesLogical: + return true + case .writeBytesLogical: + return true + case .readBytesPhysical: + return true + case .writeBytesPhysical: + return true + default: + return false + } + } +} From 4a3a10c1f4075988e34b452189033567b2cea3aa Mon Sep 17 00:00:00 2001 From: Joakim Hassila Date: Tue, 11 Oct 2022 09:28:37 +0200 Subject: [PATCH 2/7] Only calculate stats when needed, decreases the overhead in the empty benchmark case with 10x. --- Benchmarks/Basic/BenchmarkRunner.swift | 8 +- .../BenchmarkSupport/BenchmarkRunner.swift | 89 ++++++++++--------- 2 files changed, 50 insertions(+), 47 deletions(-) diff --git a/Benchmarks/Basic/BenchmarkRunner.swift b/Benchmarks/Basic/BenchmarkRunner.swift index 0b7d1f64..3554e08d 100644 --- a/Benchmarks/Basic/BenchmarkRunner.swift +++ b/Benchmarks/Basic/BenchmarkRunner.swift @@ -17,13 +17,13 @@ func benchmarks() { Benchmark.defaultDesiredDuration = .milliseconds(10) Benchmark.defaultDesiredIterations = .giga(1) - Benchmark("Basic", // 8s runtime w/ current measurement overhead + Benchmark("Basic", metrics: [.wallClock, .throughput], - skip: true) { _ in + skip: false) { _ in } - Benchmark("All metrics", // 10.92 secs + Benchmark("All metrics", metrics: BenchmarkMetric.all, - skip: false) { _ in + skip: true) { _ in } } diff --git a/Sources/BenchmarkSupport/BenchmarkRunner.swift b/Sources/BenchmarkSupport/BenchmarkRunner.swift index d23c5ca5..a4c5f666 100644 --- a/Sources/BenchmarkSupport/BenchmarkRunner.swift +++ b/Sources/BenchmarkSupport/BenchmarkRunner.swift @@ -183,7 +183,6 @@ public struct BenchmarkRunner: AsyncParsableCommand, BenchmarkRunnerReadWrite { } var delta = 0 - let runningTime: TimeDuration = stopTime - startTime if runningTime > 0 { // macOS sometimes gives us identical timestamps in ns so let's skip those. @@ -200,69 +199,73 @@ public struct BenchmarkRunner: AsyncParsableCommand, BenchmarkRunnerReadWrite { if throughput > 0 { statistics[.throughput]?.add(throughput) } - } - delta = stopMallocStats.mallocCountTotal - startMallocStats.mallocCountTotal - statistics[.mallocCountTotal]?.add(Int(delta)) + accummulatedRuntime += runningTime + } - delta = stopMallocStats.mallocCountSmall - startMallocStats.mallocCountSmall - statistics[.mallocCountSmall]?.add(Int(delta)) + if mallocStatsRequested { + delta = stopMallocStats.mallocCountTotal - startMallocStats.mallocCountTotal + statistics[.mallocCountTotal]?.add(Int(delta)) - delta = stopMallocStats.mallocCountLarge - startMallocStats.mallocCountLarge - statistics[.mallocCountLarge]?.add(Int(delta)) + delta = stopMallocStats.mallocCountSmall - startMallocStats.mallocCountSmall + statistics[.mallocCountSmall]?.add(Int(delta)) - delta = stopMallocStats.allocatedResidentMemory - startMallocStats.allocatedResidentMemory - statistics[.memoryLeaked]?.add(Int(delta)) + delta = stopMallocStats.mallocCountLarge - startMallocStats.mallocCountLarge + statistics[.mallocCountLarge]?.add(Int(delta)) - delta = stopOperatingSystemStats.cpuUser - startOperatingSystemStats.cpuUser - statistics[.cpuUser]?.add(Int(delta)) + delta = stopMallocStats.allocatedResidentMemory - startMallocStats.allocatedResidentMemory + statistics[.memoryLeaked]?.add(Int(delta)) - delta = stopOperatingSystemStats.cpuSystem - startOperatingSystemStats.cpuSystem - statistics[.cpuSystem]?.add(Int(delta)) + statistics[.allocatedResidentMemory]?.add(Int(stopMallocStats.allocatedResidentMemory)) + } - delta = stopOperatingSystemStats.cpuTotal - startOperatingSystemStats.cpuTotal - statistics[.cpuTotal]?.add(Int(delta)) + if operatingSystemStatsRequested { + delta = stopOperatingSystemStats.cpuUser - startOperatingSystemStats.cpuUser + statistics[.cpuUser]?.add(Int(delta)) - delta = stopOperatingSystemStats.peakMemoryResident - statistics[.peakMemoryResident]?.add(Int(delta)) + delta = stopOperatingSystemStats.cpuSystem - startOperatingSystemStats.cpuSystem + statistics[.cpuSystem]?.add(Int(delta)) - delta = stopOperatingSystemStats.peakMemoryVirtual - statistics[.peakMemoryVirtual]?.add(Int(delta)) + delta = stopOperatingSystemStats.cpuTotal - startOperatingSystemStats.cpuTotal + statistics[.cpuTotal]?.add(Int(delta)) - delta = stopOperatingSystemStats.syscalls - startOperatingSystemStats.syscalls - statistics[.syscalls]?.add(Int(delta)) + delta = stopOperatingSystemStats.peakMemoryResident + statistics[.peakMemoryResident]?.add(Int(delta)) - delta = stopOperatingSystemStats.contextSwitches - startOperatingSystemStats.contextSwitches - statistics[.contextSwitches]?.add(Int(delta)) + delta = stopOperatingSystemStats.peakMemoryVirtual + statistics[.peakMemoryVirtual]?.add(Int(delta)) - delta = stopOperatingSystemStats.threads - statistics[.threads]?.add(Int(delta)) + delta = stopOperatingSystemStats.syscalls - startOperatingSystemStats.syscalls + statistics[.syscalls]?.add(Int(delta)) - delta = stopOperatingSystemStats.threadsRunning - statistics[.threadsRunning]?.add(Int(delta)) + delta = stopOperatingSystemStats.contextSwitches - startOperatingSystemStats.contextSwitches + statistics[.contextSwitches]?.add(Int(delta)) - delta = stopOperatingSystemStats.readSyscalls - startOperatingSystemStats.readSyscalls - statistics[.readSyscalls]?.add(Int(delta)) + delta = stopOperatingSystemStats.threads + statistics[.threads]?.add(Int(delta)) - delta = stopOperatingSystemStats.writeSyscalls - startOperatingSystemStats.writeSyscalls - statistics[.writeSyscalls]?.add(Int(delta)) + delta = stopOperatingSystemStats.threadsRunning + statistics[.threadsRunning]?.add(Int(delta)) - delta = stopOperatingSystemStats.readBytesLogical - startOperatingSystemStats.readBytesLogical - statistics[.readBytesLogical]?.add(Int(delta)) + delta = stopOperatingSystemStats.readSyscalls - startOperatingSystemStats.readSyscalls + statistics[.readSyscalls]?.add(Int(delta)) - delta = stopOperatingSystemStats.writeBytesLogical - startOperatingSystemStats.writeBytesLogical - statistics[.writeBytesLogical]?.add(Int(delta)) + delta = stopOperatingSystemStats.writeSyscalls - startOperatingSystemStats.writeSyscalls + statistics[.writeSyscalls]?.add(Int(delta)) - delta = stopOperatingSystemStats.readBytesPhysical - startOperatingSystemStats.readBytesPhysical - statistics[.readBytesPhysical]?.add(Int(delta)) + delta = stopOperatingSystemStats.readBytesLogical - startOperatingSystemStats.readBytesLogical + statistics[.readBytesLogical]?.add(Int(delta)) - delta = - stopOperatingSystemStats.writeBytesPhysical - startOperatingSystemStats.writeBytesPhysical - statistics[.writeBytesPhysical]?.add(Int(delta)) + delta = stopOperatingSystemStats.writeBytesLogical - startOperatingSystemStats.writeBytesLogical + statistics[.writeBytesLogical]?.add(Int(delta)) - statistics[.allocatedResidentMemory]?.add(Int(stopMallocStats.allocatedResidentMemory)) + delta = stopOperatingSystemStats.readBytesPhysical - startOperatingSystemStats.readBytesPhysical + statistics[.readBytesPhysical]?.add(Int(delta)) - accummulatedRuntime += runningTime + delta = + stopOperatingSystemStats.writeBytesPhysical - startOperatingSystemStats.writeBytesPhysical + statistics[.writeBytesPhysical]?.add(Int(delta)) + } } benchmark.customMetricMeasurement = { metric, value in From 393f366e0bbcd4a4dd9c005e3b0890a0b2798597 Mon Sep 17 00:00:00 2001 From: Joakim Hassila Date: Tue, 11 Oct 2022 09:51:34 +0200 Subject: [PATCH 3/7] Fix SwiftLint --- .../BenchmarkRunner+ReadWrite.swift | 65 +++++++++++++++++++ .../BenchmarkSupport/BenchmarkRunner.swift | 60 +++-------------- 2 files changed, 73 insertions(+), 52 deletions(-) create mode 100644 Sources/BenchmarkSupport/BenchmarkRunner+ReadWrite.swift diff --git a/Sources/BenchmarkSupport/BenchmarkRunner+ReadWrite.swift b/Sources/BenchmarkSupport/BenchmarkRunner+ReadWrite.swift new file mode 100644 index 00000000..26c23bcf --- /dev/null +++ b/Sources/BenchmarkSupport/BenchmarkRunner+ReadWrite.swift @@ -0,0 +1,65 @@ +// +// Copyright (c) 2022 Ordo One AB. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// + +// swiftlint disable: file_length type_body_length +import ArgumentParser +@_exported import Benchmark +import ExtrasJSON +@_exported import Statistics +import SystemPackage + +// For test dependency injection +protocol BenchmarkRunnerReadWrite { + func write(_ reply: BenchmarkCommandReply) throws + func read() throws -> BenchmarkCommandRequest +} + +extension BenchmarkRunner { + func write(_ reply: BenchmarkCommandReply) throws { + guard outputFD != nil else { + return + } + let bytesArray = try XJSONEncoder().encode(reply) + let count: Int = bytesArray.count + let output = FileDescriptor(rawValue: outputFD!) + + // Length header + try withUnsafeBytes(of: count) { (intPtr: UnsafeRawBufferPointer) in + _ = try output.write(intPtr) + } + + // JSON serialization + try bytesArray.withUnsafeBufferPointer { + _ = try output.write(UnsafeRawBufferPointer($0)) + } + } + + func read() throws -> BenchmarkCommandRequest { + guard inputFD != nil else { + return .end + } + let input = FileDescriptor(rawValue: inputFD!) + var bufferLength = 0 + + // Length header + try withUnsafeMutableBytes(of: &bufferLength) { (intPtr: UnsafeMutableRawBufferPointer) in + _ = try input.read(into: intPtr) + } + + // JSON serialization + let readBytes = try [UInt8](unsafeUninitializedCapacity: bufferLength) { buf, count in + count = try input.read(into: UnsafeMutableRawBufferPointer(buf)) + } + + let request = try XJSONDecoder().decode(BenchmarkCommandRequest.self, from: readBytes) + + return request + } +} diff --git a/Sources/BenchmarkSupport/BenchmarkRunner.swift b/Sources/BenchmarkSupport/BenchmarkRunner.swift index a4c5f666..13adf469 100644 --- a/Sources/BenchmarkSupport/BenchmarkRunner.swift +++ b/Sources/BenchmarkSupport/BenchmarkRunner.swift @@ -14,12 +14,6 @@ import ExtrasJSON @_exported import Statistics import SystemPackage -// For test dependency injection -protocol BenchmarkRunnerReadWrite { - func write(_ reply: BenchmarkCommandReply) throws - func read() throws -> BenchmarkCommandRequest -} - // @main must be done in actual benchmark to avoid linker errors unfortunately public struct BenchmarkRunner: AsyncParsableCommand, BenchmarkRunnerReadWrite { static var testReadWrite: BenchmarkRunnerReadWrite? @@ -34,47 +28,6 @@ public struct BenchmarkRunner: AsyncParsableCommand, BenchmarkRunnerReadWrite { var debug = false - func write(_ reply: BenchmarkCommandReply) throws { - guard outputFD != nil else { - return - } - let bytesArray = try XJSONEncoder().encode(reply) - let count: Int = bytesArray.count - let output = FileDescriptor(rawValue: outputFD!) - - // Length header - try withUnsafeBytes(of: count) { (intPtr: UnsafeRawBufferPointer) in - _ = try output.write(intPtr) - } - - // JSON serialization - try bytesArray.withUnsafeBufferPointer { - _ = try output.write(UnsafeRawBufferPointer($0)) - } - } - - func read() throws -> BenchmarkCommandRequest { - guard inputFD != nil else { - return .end - } - let input = FileDescriptor(rawValue: inputFD!) - var bufferLength = 0 - - // Length header - try withUnsafeMutableBytes(of: &bufferLength) { (intPtr: UnsafeMutableRawBufferPointer) in - _ = try input.read(into: intPtr) - } - - // JSON serialization - let readBytes = try [UInt8](unsafeUninitializedCapacity: bufferLength) { buf, count in - count = try input.read(into: UnsafeMutableRawBufferPointer(buf)) - } - - let request = try XJSONDecoder().decode(BenchmarkCommandRequest.self, from: readBytes) - - return request - } - // swiftlint:disable cyclomatic_complexity function_body_length public mutating func run() async throws { // We just run everything in debug mode to simplify workflow with debuggers/profilers @@ -253,17 +206,20 @@ public struct BenchmarkRunner: AsyncParsableCommand, BenchmarkRunnerReadWrite { delta = stopOperatingSystemStats.writeSyscalls - startOperatingSystemStats.writeSyscalls statistics[.writeSyscalls]?.add(Int(delta)) - delta = stopOperatingSystemStats.readBytesLogical - startOperatingSystemStats.readBytesLogical + delta = stopOperatingSystemStats.readBytesLogical - + startOperatingSystemStats.readBytesLogical statistics[.readBytesLogical]?.add(Int(delta)) - delta = stopOperatingSystemStats.writeBytesLogical - startOperatingSystemStats.writeBytesLogical + delta = stopOperatingSystemStats.writeBytesLogical - + startOperatingSystemStats.writeBytesLogical statistics[.writeBytesLogical]?.add(Int(delta)) - delta = stopOperatingSystemStats.readBytesPhysical - startOperatingSystemStats.readBytesPhysical + delta = stopOperatingSystemStats.readBytesPhysical - + startOperatingSystemStats.readBytesPhysical statistics[.readBytesPhysical]?.add(Int(delta)) - delta = - stopOperatingSystemStats.writeBytesPhysical - startOperatingSystemStats.writeBytesPhysical + delta = stopOperatingSystemStats.writeBytesPhysical - + startOperatingSystemStats.writeBytesPhysical statistics[.writeBytesPhysical]?.add(Int(delta)) } } From 5897f9a0e664508e0419ff4ac9b0d4b7cb1e6f0e Mon Sep 17 00:00:00 2001 From: Joakim Hassila Date: Tue, 11 Oct 2022 09:52:29 +0200 Subject: [PATCH 4/7] Fix SwiftLint --- .../BenchmarkRunner+ReadWrite.swift | 58 +++++++++++++++++++ .../BenchmarkSupport/BenchmarkRunner.swift | 57 ------------------ 2 files changed, 58 insertions(+), 57 deletions(-) diff --git a/Sources/BenchmarkSupport/BenchmarkRunner+ReadWrite.swift b/Sources/BenchmarkSupport/BenchmarkRunner+ReadWrite.swift index 26c23bcf..bf2db791 100644 --- a/Sources/BenchmarkSupport/BenchmarkRunner+ReadWrite.swift +++ b/Sources/BenchmarkSupport/BenchmarkRunner+ReadWrite.swift @@ -63,3 +63,61 @@ extension BenchmarkRunner { return request } } + +extension BenchmarkRunner { + func mallocStatsProducerNeeded(_ metric: BenchmarkMetric) -> Bool { + switch metric { + case .mallocCountLarge: + return true + case .memoryLeaked: + return true + case .mallocCountSmall: + return true + case .mallocCountTotal: + return true + case .allocatedResidentMemory: + return true + default: + return false + } + } +} + +extension BenchmarkRunner { + func operatingSystemsStatsProducerNeeded(_ metric: BenchmarkMetric) -> Bool { + switch metric { + case .cpuUser: + return true + case .cpuSystem: + return true + case .cpuTotal: + return true + case .peakMemoryResident: + return true + case .peakMemoryVirtual: + return true + case .syscalls: + return true + case .contextSwitches: + return true + case .threads: + return true + case .threadsRunning: + return true + case .readSyscalls: + return true + case .writeSyscalls: + return true + case .readBytesLogical: + return true + case .writeBytesLogical: + return true + case .readBytesPhysical: + return true + case .writeBytesPhysical: + return true + default: + return false + } + } +} diff --git a/Sources/BenchmarkSupport/BenchmarkRunner.swift b/Sources/BenchmarkSupport/BenchmarkRunner.swift index 13adf469..95fd91df 100644 --- a/Sources/BenchmarkSupport/BenchmarkRunner.swift +++ b/Sources/BenchmarkSupport/BenchmarkRunner.swift @@ -313,60 +313,3 @@ public struct BenchmarkRunner: AsyncParsableCommand, BenchmarkRunnerReadWrite { } } -extension BenchmarkRunner { - func mallocStatsProducerNeeded(_ metric: BenchmarkMetric) -> Bool { - switch metric { - case .mallocCountLarge: - return true - case .memoryLeaked: - return true - case .mallocCountSmall: - return true - case .mallocCountTotal: - return true - case .allocatedResidentMemory: - return true - default: - return false - } - } -} - -extension BenchmarkRunner { - func operatingSystemsStatsProducerNeeded(_ metric: BenchmarkMetric) -> Bool { - switch metric { - case .cpuUser: - return true - case .cpuSystem: - return true - case .cpuTotal: - return true - case .peakMemoryResident: - return true - case .peakMemoryVirtual: - return true - case .syscalls: - return true - case .contextSwitches: - return true - case .threads: - return true - case .threadsRunning: - return true - case .readSyscalls: - return true - case .writeSyscalls: - return true - case .readBytesLogical: - return true - case .writeBytesLogical: - return true - case .readBytesPhysical: - return true - case .writeBytesPhysical: - return true - default: - return false - } - } -} From f1a289393bb132c668515975b3cbd16ce85c1b42 Mon Sep 17 00:00:00 2001 From: Joakim Hassila Date: Tue, 11 Oct 2022 09:57:07 +0200 Subject: [PATCH 5/7] Fix SwiftLint --- Sources/BenchmarkSupport/BenchmarkRunner+ReadWrite.swift | 1 + Sources/BenchmarkSupport/BenchmarkRunner.swift | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/BenchmarkSupport/BenchmarkRunner+ReadWrite.swift b/Sources/BenchmarkSupport/BenchmarkRunner+ReadWrite.swift index bf2db791..7dbf0b4a 100644 --- a/Sources/BenchmarkSupport/BenchmarkRunner+ReadWrite.swift +++ b/Sources/BenchmarkSupport/BenchmarkRunner+ReadWrite.swift @@ -8,6 +8,7 @@ // http://www.apache.org/licenses/LICENSE-2.0 // +// swiftlint:disable cyclomatic_complexity // swiftlint disable: file_length type_body_length import ArgumentParser @_exported import Benchmark diff --git a/Sources/BenchmarkSupport/BenchmarkRunner.swift b/Sources/BenchmarkSupport/BenchmarkRunner.swift index 95fd91df..d606a92a 100644 --- a/Sources/BenchmarkSupport/BenchmarkRunner.swift +++ b/Sources/BenchmarkSupport/BenchmarkRunner.swift @@ -312,4 +312,3 @@ public struct BenchmarkRunner: AsyncParsableCommand, BenchmarkRunnerReadWrite { } } } - From 7ddc20191147263e01b831190480f5b273f29dca Mon Sep 17 00:00:00 2001 From: Joakim Hassila Date: Tue, 11 Oct 2022 10:25:34 +0200 Subject: [PATCH 6/7] Remove unnecssary jemalloc queries --- Benchmarks/Basic/BenchmarkRunner.swift | 6 ++-- .../MallocStatsProducer+jemalloc.swift | 32 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Benchmarks/Basic/BenchmarkRunner.swift b/Benchmarks/Basic/BenchmarkRunner.swift index 3554e08d..9daf099f 100644 --- a/Benchmarks/Basic/BenchmarkRunner.swift +++ b/Benchmarks/Basic/BenchmarkRunner.swift @@ -19,11 +19,11 @@ func benchmarks() { Benchmark("Basic", metrics: [.wallClock, .throughput], - skip: false) { _ in + skip: true) { _ in } Benchmark("All metrics", - metrics: BenchmarkMetric.all, - skip: true) { _ in + metrics: BenchmarkMetric.memory, + skip: false) { _ in } } diff --git a/Sources/BenchmarkSupport/MallocStats/MallocStatsProducer+jemalloc.swift b/Sources/BenchmarkSupport/MallocStats/MallocStatsProducer+jemalloc.swift index e8633ea7..eaa2a612 100644 --- a/Sources/BenchmarkSupport/MallocStats/MallocStatsProducer+jemalloc.swift +++ b/Sources/BenchmarkSupport/MallocStats/MallocStatsProducer+jemalloc.swift @@ -18,12 +18,12 @@ import jemalloc public class MallocStatsProducer { var threadCacheMIB: [Int] var epochMIB: [Int] - var smallNMallocMIB: [Int] - var largeNMallocMIB: [Int] - var smallNDallocMIB: [Int] - var largeNDallocMIB: [Int] - var smallAlloctedMIB: [Int] - var largeAllocatedMIB: [Int] +// var smallNMallocMIB: [Int] +// var largeNMallocMIB: [Int] +// var smallNDallocMIB: [Int] +// var largeNDallocMIB: [Int] +// var smallAlloctedMIB: [Int] +// var largeAllocatedMIB: [Int] var totalAllocatedMIB: [Int] var smallTMallocMIB: [Int] var largeTMallocMIB: [Int] @@ -60,12 +60,12 @@ public class MallocStatsProducer { epochMIB = [size_t](repeating: 0, count: 1) totalAllocatedMIB = [size_t](repeating: 0, count: 2) threadCacheMIB = [size_t](repeating: 0, count: 3) - smallNMallocMIB = [size_t](repeating: 0, count: 5) - largeNMallocMIB = [size_t](repeating: 0, count: 5) - smallNDallocMIB = [size_t](repeating: 0, count: 5) - largeNDallocMIB = [size_t](repeating: 0, count: 5) - smallAlloctedMIB = [size_t](repeating: 0, count: 5) - largeAllocatedMIB = [size_t](repeating: 0, count: 5) +// smallNMallocMIB = [size_t](repeating: 0, count: 5) +// largeNMallocMIB = [size_t](repeating: 0, count: 5) +// smallNDallocMIB = [size_t](repeating: 0, count: 5) +// largeNDallocMIB = [size_t](repeating: 0, count: 5) +// smallAlloctedMIB = [size_t](repeating: 0, count: 5) +// largeAllocatedMIB = [size_t](repeating: 0, count: 5) smallTMallocMIB = [size_t](repeating: 0, count: 5) largeTMallocMIB = [size_t](repeating: 0, count: 5) @@ -84,7 +84,7 @@ public class MallocStatsProducer { print("mallctlnametomib epochMIB returned \(result)") } } - +/* mibSize = smallNMallocMIB.count smallNMallocMIB.withUnsafeMutableBufferPointer { pointer in let result = mallctlnametomib("stats.arenas.\(MALLCTL_ARENAS_ALL).small.nmalloc", @@ -104,7 +104,7 @@ public class MallocStatsProducer { print("mallctlnametomib largeNMallocMIB returned \(result)") } } - +*/ // tcaches mibSize = smallTMallocMIB.count smallTMallocMIB.withUnsafeMutableBufferPointer { pointer in @@ -125,7 +125,7 @@ public class MallocStatsProducer { print("mallctlnametomib largeTMallocMIB returned \(result)") } } - +/* mibSize = smallNDallocMIB.count smallNDallocMIB.withUnsafeMutableBufferPointer { pointer in let result = mallctlnametomib("stats.arenas.\(MALLCTL_ARENAS_ALL).small.ndalloc", @@ -165,7 +165,7 @@ public class MallocStatsProducer { print("mallctlnametomib largeAllocatedMIB returned \(result)") } } - + */ mibSize = totalAllocatedMIB.count totalAllocatedMIB.withUnsafeMutableBufferPointer { pointer in let result = mallctlnametomib("stats.resident", pointer.baseAddress, &mibSize) From cf436ea3c69d1cb141a0a24bffc5af5b379dc132 Mon Sep 17 00:00:00 2001 From: Joakim Hassila Date: Tue, 11 Oct 2022 10:26:19 +0200 Subject: [PATCH 7/7] Fix SwiftLint. --- .../MallocStats/MallocStatsProducer+jemalloc.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sources/BenchmarkSupport/MallocStats/MallocStatsProducer+jemalloc.swift b/Sources/BenchmarkSupport/MallocStats/MallocStatsProducer+jemalloc.swift index eaa2a612..89851f9f 100644 --- a/Sources/BenchmarkSupport/MallocStats/MallocStatsProducer+jemalloc.swift +++ b/Sources/BenchmarkSupport/MallocStats/MallocStatsProducer+jemalloc.swift @@ -52,8 +52,6 @@ public class MallocStatsProducer { return epoch } - // swiftlint:disable function_body_length cyclomatic_complexity - // Basically just set up a number of cached MIB structures for // more efficient queries later of malloc statistics. public init() {