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?
-
2does it make a difference if you call the python bin and pass the script as an argument?tMC– tMC2011年06月20日 16:12:21 +00:00Commented Jun 20, 2011 at 16:12
-
@tMC, before I even read your comment I was thinking the same thing. It does in fact make a difference.Mr. Shickadance– Mr. Shickadance2011年06月20日 16:41:36 +00:00Commented Jun 20, 2011 at 16:41
1 Answer 1
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