Date
1 - 1 of 1
Reporting your app's memory usage while testing.
Alex Zavatone
For those who actually want to be able to monitor and log iOS app memory being used while running tests.
toggle quoted messageShow quoted text
This is a method/function based off of some Quinn advice posted on the Apple Dev Forum. I modified it to return readable output and updated it to Swift 4.1. It’s been helpful tracking down excessive memory usage while solving our leaks and excess allocations. This method actually matches what is listed in the Activity Monitor and in Xcode’s memory window while running our app in the Simulator. Swift file enclosed. And here’s how I use it within XCTest override func invokeTest() { let formattedPhysicalMemoryUsedBeforeTests = Memory.formattedMemoryFootprint() // let totalPhysicalMemoryUsedBeforeTests: Int = Int(exactly: Memory.memoryFootprint() ?? 0) ?? 0 TestLog().write("####█████ Physical memory used before starting test: \(formattedPhysicalMemoryUsedBeforeTests)") TestLog().write("####█████ Test: \(self.name)") TestLog().write("––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––") print() super.invokeTest() } And here’s some sample output (text bolded for emphasis. 2019-10-03 17:34:04.655 ####█████ Physical memory used before starting test: 490.4609375 MB 2019-10-03 17:34:04.655 ####█████ Test: -[UserViewsLegacyLoanOverview testShowLoanSelector] 2019-10-03 17:34:04.657 –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– 2019-10-03 17:34:36.650 ####█████ Physical memory used before starting test: 500.41015625 MB 2019-10-03 17:34:36.650 ####█████ Test: -[UserViewsLegacyLoanOverview testShowsLenderExpenses] 2019-10-03 17:34:36.652 –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– 2019-10-03 17:34:41.820 ####█████ Physical memory used before starting test: 498.359375 MB 2019-10-03 17:34:41.820 ####█████ Test: -[UserViewsLegacyLoanOverview testShowsNoLenderExpenses] 2019-10-03 17:34:41.822 ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
|
|