Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory profiling of a running python application

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?

like image 338
Ahmad Siavashi Avatar asked Jan 29 '17 10:01

Ahmad Siavashi


People also ask

How do you run a memory profiling in Python?

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.

How does memory profiler work Python?

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.

How do you do profiling in Python?

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.

What is memory profiling?

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).


1 Answers

Scalene is able to generate profiling output every N seconds.

like image 78
Ahmad Siavashi Avatar answered Oct 13 '22 23:10

Ahmad Siavashi