In order to profile memory leakage/heap growth in Swift on Linux, you need to a) run it on Linux b) use a profiling tool.
Docker and Valgrind to the rescue.
We're using the official Swift image here: FROM swift:4
.
The latest version of Valgrind that can be installed on Ubuntu 16.04 using the system package manager, apt-get
, is from 2015. Unsurprisingly, if you have a machine with a CPU more modern than that, it's likely Valgrind won't support the latest instruction sets.
... is remarkably painless. Either inside your container, or your Dockerfile, you'll need to apt-get install automake libc6-dbg
. Then, based on this webpage, you want to:
git clone git://sourceware.org/git/valgrind.git &&\
cd valgrind &&\
./autogen.sh &&\
./configure --prefix=/usr/local &&\
make &&\
make install
Double check you're on the latest version by running valgrind --version
. For me, it was 1.13.GIT
.
This is the easy part. Just ensure you've made a debug build, and then run valgrind --tool=TOOLHERE .build/debug/.../YourExecutable
. For more info on using massif
, the super awesome heap profiler, check out this page: http://valgrind.org/docs/manual/ms-manual.html