Question: I want to find out what the maximum amount of RAM allocated during the call to a function is (in Python). There are other questions on SO related to tracking RAM usage:

[Which Python memory profiler is recommended?](https://stackoverflow.com/questions/110259/python-memory-profiler)

[How do I profile memory usage in Python?](https://stackoverflow.com/questions/552744/how-do-i-profile-memory-usage-in-python)

but those seem to allow you more to track memory usage at the time the `heap()` method (in the case of guppy) is called. However, what I want to track is a function in an external library which I can't modify, and which grows to use a lot of RAM but then frees it once the execution of the function is complete. Is there any way to find out what the total amount of RAM used during the function call was?

Answer: 
You can use python library resource to get memory usage.

```
import resource
resource.getrusage(resource.RUSAGE_SELF).ru_maxrss

```

It will give memory usage in kilobytes, to convert in MB divide by 1000.
Standard Unix utility `time` tracks maximum memory usage of the process as well as other useful statistics for your program.

Example output (`maxresident` is max memory usage, in Kilobytes.):

```
> time python ./scalabilty_test.py
45.31user 1.86system 0:47.23elapsed 99%CPU (0avgtext+0avgdata 369824maxresident)k
0inputs+100208outputs (0major+99494minor)pagefaults 0swaps

```