Command-line tool for tracing memory usage of an arbitrary process.

I needed a small command-line tool, so I wrote it based on your module. The name is mprofile. 
Typical usage:

    mprofile longrunningcommand <arg1> ... <argn>

The script just write a file called "mprofile_&lt;timestamp&gt;.dat" in the current directory. The memory is sampled twice every second.
There is currently no options (no way to change sampling rate or name of output files).

I had to slightly generalise memory_usage(). The "proc" argument can now take a Popen object. This is required for a simple thing: being able to detect when the process terminates (the timeout parameter is functional though).