heapprof: A Logging Heap Profiler

https://img.shields.io/badge/python-3.7-blue.svg https://img.shields.io/badge/Contributor%20Covenant-v1.4%20adopted-ff69b4.svg https://img.shields.io/badge/License-MIT-yellow.svg https://circleci.com/gh/humu/heapprof/tree/master.svg?style=svg&circle-token=1557bfcabda0155d6505a45e3f00d4a71a005565

heapprof is a logging, sampling heap profiler for Python 3.7+.

  • “Logging” means that as the program runs, it steadily generates a log of memory allocation and release events. This means that you can easily look at memory usage as a function of time.

  • “Sampling” means that it can record only a statistically random sample of memory events. This improves performance dramatically while writing logs, and (with the right parameters) sacrifices almost no accuracy.

It comes with a suite of visualization and analysis tools (including time plots, flame graphs, and flow graphs), as well as an API for doing your own analyses of the results.

heapprof is complementary to tracemalloc, which is a snapshotting heap profiler. The difference is that tracemalloc keeps track of live memory internally, and only writes snapshots when its snapshot() function is called; this means it has slightly lower overhead, but you have to know the moments at which you’ll want a snapshot before the program starts. This makes it particularly useful for finding leaks (from the snapshot at program exit), but not as good for understanding events like memory spikes.