<br>"A person with one watch knows what time it is.  A person with two is never sure."<br><br>You're probably best off just picking one or more measures that work for your purposes, and going with them.  Don't concern yourself overmuch with finding "the" amount.<br>
<br>Memory can actually contract on some modern systems, due to garbage collection and the relatively new ability of some malloc's to mmap away no-longer-needed pages.<br><br>Going directly to /proc is fine, though it might be a little more common (and portable) to run ps and let it sift through /proc.  But of course, running ps over and over is less efficient.<br>
<br><div class="gmail_quote">On Thu, Aug 18, 2011 at 8:08 AM, Jack Bates <span dir="ltr"><<a href="mailto:ms419@freezone.co.uk">ms419@freezone.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I wrote a content filter for Postfix with Python,<br>
<a href="https://github.com/jablko/cookie" target="_blank">https://github.com/jablko/cookie</a><br>
<br>
It should get started once, and hopefully run for a long time - so I'm<br>
interested in how it uses memory:<br>
<br>
 1) How does the amount of memory used change as it runs?<br>
<br>
 2) How does the amount of memory used change as I continue to hack on<br>
it, and change the code?<br>
<br>
My naive thought was that I'd periodically append to a file, the virtual<br>
memory size from /proc/[pid]/stat and a timestamp. From this a could<br>
make a graph of the amount of memory used as my content filter runs, and<br>
I could compare two graphs to get a clue whether this amount changed as<br>
I continue to hack<br>
<br>
 - but some Googling quickly revealed that measuring memory is actually<br>
quite complicated? Neither the virtual memory size nor the "resident set<br>
size" accurately measure the amount of memory used by a process<br>
<br>
Has anyone else measured the memory used by a Python program? How did<br>
you do it?<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>