ODU Research Computing Forum

Tracking memory usage of a running program

I have a Python program that uses a lot of memory while running. I’m interested in monitoring the memory usage through the program execution. How do I do this?

If you are using Python, please check out the psutil library and its memory stats capability:

https://psutil.readthedocs.io/en/latest/#memory

From the package’s description:

psutil (python system and process utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python. It is useful mainly for system monitoring, profiling, limiting process resources and the management of running processes.

This library provides much of the capabilities of tools under procps package in Linux, such as ps, top, free, etc.

As an alternative, you can also use tracemalloc for memory usage, which is part of standard library, but psutil is easier to use.

To install psutil in your own Python virtual environment in Wahab, please follow the instructions detailed in our Python documentation page, Install Additional Python Modules.