"mprof run <executable>": What does each output column represent?

memory-profiling, python

Solution

1st column: "MEM" is just a label.

2nd column: RSS (resident set size) in megabytes. So your process ended up using 8.8 MB.

3rd column: Unix time stamp:

>>> import time
>>> print(time.ctime(1424769615.1960))
Tue Feb 24 01:20:15 2015

It looks like `mprof` just logs the process size over time. If you want more specific details about the internals of your program (line-by-line) it looks like you can use `mprof run --python file.py` to get that information (you also need to decorate your functions with `@profile`, see the Usage section in the documentation).

Edit: In response to the ImportError & traceback you posted: You are getting that error because you're running the file as `"../myfile.py"`. Since you're outside of the `bsite` directory it can't find the `config.py` file.

You need to run the program like this:

 $ cd /home/vikas/bsite/
 $ /home/vikask/memory_profiler-0.32/mprof run --python myfile.py

This way you're in the correct directory for the `import` to work.

Another way to get it to work is to build your project as a python package. When you do this your files can be properly imported from anywhere. This is a little complicated to get set up, but it's a pretty good idea.

The other more hacky option is to modify `PYTHONPATH` or `sys.path` to get the imports to work. For example like this:

$ cd /home/vikask/memory_profiler-0.32/
$ PYTHONPATH=/home/vikas/bsite/ ./mprof run --python ../myfile.py

Finally, it looks like you're running the `mprof` command directly from the memory_profiler source. You can install the package by doing "`python setup.py install`" in that directory (or by using `pip install memory_profiler`). Then you should have the `mprof` command on your PATH and can run it from any directory.

Problem

I ran `mprof run some-executable` and it produced a `*.dat` file. What does each column of the `*.dat` file signify? ``` vikas@some-host$ cat mprofile_20150224012014.dat CMDLINE python ../asl MEM 0.332031 1424769614.8950 MEM 7.593750 1424769614.9954 MEM 8.816406 1424769615.0957 MEM 8.816406 1424769615.1960 ``` What do those 1st/2nd/3rd columns represent? [EDIT]: Also I am not able to run mprof run --python. Here is the error(importerror) I am getting.... looks like it is not able to get the definition of config (virtualenv)vikas@host:$ ./mprof run --python ../myfile.py mprof: Sampling memory every 0.1s running as a Python program... ``` Traceback (most recent call last): File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib64/python2.6/runpy.py", line 34, in _run_code exec code in run_globals File "/home/vikask/memory_profiler-0.32/memory_profiler.py", line 853, in <module> execfile(__file__, ns, ns) File "../myfile.py", line 19, in <module> from bsite import models, security File "/home/vikas/bsite/models.py", line 12, in <module> from bsite import config ImportError: cannot import name config ```

Original source