Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having problems profiling memory in Python program using Valgrind

I've looked at some questions about profiling memory usage in Python programs, but so far haven't been able to get anything to work. My program must run as root (it opens a TUN/TAP device).

First, I tried heapy; unfortunately this didn't work for me. Every time my code tried to execute hpy().heap() the program froze. Not wanting to waste too much timed I decided to try valgrind.

I tried valgrind with massif:

# valgrind --tool=massif ./my_prog.py --some-options value

I think the issue is related to profiling Python programs. I tried my program (which runs as root) and no massif output file was generated. I also wasn't able to generate an output file with another Python program (which doesn't run as root). However, a simple C test program worked fine and produced the massif file.

What are the issues preventing Valgrind and massif from working correctly with Python programs?

like image 511
Mr. Shickadance Avatar asked Feb 24 '23 20:02

Mr. Shickadance


1 Answers

Instead of having the script launch the interpreter, directly calling it as a parameter to Valgrind solves the problem.

valgrind --tool=massif python my_script.py
like image 148
Mr. Shickadance Avatar answered Feb 26 '23 08:02

Mr. Shickadance