I have a flask
application that uses pony
as its ORM. The application incrementally increases its memory usage with every request to the service. I need to measure the memory usage of different parts of the program to find the problem.
Unfortunately, as the program does not return its execution and is always running I could not use memory profiling tools such as memory_profiler. How can I profile memory usage of a continuously running application?
The easiest way to profile a single method or function is the open source memory-profiler package. It's similar to line_profiler , which I've written about before . You can use it by putting the @profile decorator around any function or method and running python -m memory_profiler myscript.
Memory Profiler is an open-source Python module that uses psutil module internally, to monitor the memory consumption of Python functions. It performs a line-by-line memory consumption analysis of the function.
Python includes a profiler called cProfile. It not only gives the total running time, but also times each function separately, and tells you how many times each function was called, making it easy to determine where you should make optimizations.
Specifically, the Memory Profiler can show you the following about object allocations: What types of objects were allocated and how much space they use. The stack trace of each allocation, including in which thread. When the objects were deallocated (only when using a device with Android 8.0 or higher).
Scalene is able to generate profiling output every N
seconds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With