MimirMemoryLogger is a memory logging framework (Swift & Objective-C) that is intended to help developers better debug memory issues when connecting the device to Xcode is not possible.
What this framework does is basically takes a snapshot of the iOS device's heap and saves it to disk as a json file. This json file can then be used alongside a python script i wrote (please don't judge my python code π ) that loops over all the memory instances in the json file and sorts them accordingly in terminal.
- Trigger saving memory heap snapshot whenever you want (e.g when the app receives
applicationDidReceiveMemoryWarning
) - MimirMemoryLogger saves the memory snapshot to disk
- User sends memory snapshot (automatically or manually) to developer
- Developer runs python script with the json memory snapshot as a parameter
- Script shows the memory heap usage of your app which allows the developer to look into the reason of heavy memory usage
These are 2 samples of what the result of using the heap snapshot json file with the python script (included in the repo)
Samples of json memory snapshots are in ./Resources/snapshot-samples
import MimirMemoryLogger // Do not forget this
MimirMemoryLogger.saveCurrentSnapshotToFile { (url) -> (Void) in
if let url = url {
print("Memory snapshot location: \(url.absoluteString)")
}
}
if let urls = MimirMemoryLogger.getSavedSnapshots() {
print("URLS of all saved snapshots: \(urls)")
}
You can set the maximum number of snapshots that persist on disk. Default is 5
MimirMemoryLogger.maxNumberOfSnapshots = 3
If you want more details on what is happening while saving and getting snapshots, you can set verbose to true in MimirMemoryLogger. This will print to console added details and information such as time it takes to save a snapshot or if there are any errors.
MimirMemoryLogger.verbose = true
This project relies on one Python script that sorts and prettifies the results in a json snapshot file just like in the sample images at the beginning of this readme. This script is located here: ./PythonScripts/MimirMemoryLogger.py
This script was written with the help of BeautifulTable.
Just call this script with the json file as an argument (samples of json snapshots are in ./Resources/snapshot-samples).
For example:
python3 MimirMemoryLogger sample-snapshot.json
This framework is still in the early phases and will keep evolving.
If you use this framework and happen to like it, feel free to let me know π
Mimir is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'MimirMemoryLogger'
Amer Eid, [email protected]
Mimir is available under the MIT license. See the LICENSE file for more info.