1 | memlog - A Memory-Allocation Logging Tool |
---|
2 | |
---|
3 | This tool attempts to help you answer the question: |
---|
4 | Why is my application using so much memory? |
---|
5 | |
---|
6 | ** LINKING ** |
---|
7 | |
---|
8 | How to use it depends on how your application is linked: |
---|
9 | |
---|
10 | For dynamically-linked applications, you can: |
---|
11 | |
---|
12 | 1. Use LD_PRELOAD: Set LD_PRELOAD=/path/to/memlog/libmemlog.so when you run |
---|
13 | your application. |
---|
14 | |
---|
15 | 2. Link directly: Add the following to your linker flags: |
---|
16 | -L/path/to/memlog -Wl,-rpath,/path/to/memlog -lmemlog |
---|
17 | |
---|
18 | For statically-linked applications, add the following to your linker flags: |
---|
19 | |
---|
20 | -Wl,--wrap,malloc,--wrap,valloc,--wrap,realloc,--wrap,calloc,--wrap,memalign,--wrap,free \ |
---|
21 | -Wl,--wrap,posix_memalign,--wrap,mmap,--wrap,mmap64,--wrap,munmap \ |
---|
22 | /path/to/memlog/memlog_s.o -lpthread -ldl |
---|
23 | |
---|
24 | ** RUNNING ** |
---|
25 | |
---|
26 | When your application runs, you should find in your current directory files |
---|
27 | named 'HOST.PID.memlog', one for each process. These contain the raw tracing |
---|
28 | information, and are only somewhat human readable. You can create a ps/pdf |
---|
29 | file detailing the memory allocated when each process reached its peak memory |
---|
30 | use by running: |
---|
31 | |
---|
32 | /path/to/memlog/memlog_analyze /path/to/HOST.PID.memlog |
---|
33 | |
---|
34 | this will generate files named HOST.PID.memlog.dot, HOST.PID.memlog.ps and |
---|
35 | HOST.PID.memlog.pdf. You'll probably find the pdf file most convenient for |
---|
36 | viewing. HOST.PID.memlog.txt is also generated, providing the same information |
---|
37 | in textual form. |
---|
38 | |
---|
39 | If you pass the --leaks option to memlog_analyze, it will provide data on |
---|
40 | allocations active at the end of the program (leaks) instead of those active |
---|
41 | when the peak memory usage is first reached. |
---|
42 | |
---|
43 | You might have many runs of the same application (or output from many ranks of |
---|
44 | an MPI job), and you'd like to pick the one for analysis with the highest |
---|
45 | memory usage. If you provide a glob pattern to memlog_analyze it will do this |
---|
46 | for you. Make sure you quote the glob pattern so that your shell does not |
---|
47 | expand it. |
---|
48 | |
---|
49 | /path/to/memlog/memlog_analyze "/path/to/*.memlog" |
---|
50 | |
---|
51 | When running under common batch systems, the files are named |
---|
52 | JOB_ID.HOST.PID.memlog, and when running under the BG/Q CNK, the process's rank |
---|
53 | is used instead of the node-local PID. |
---|
54 | |
---|
55 | Note that te peak memory usage is determined by monitoring the processes's |
---|
56 | maximum resident set size, not just the total allocated heap memory. |
---|
57 | |
---|
58 | memlog_analyze takes, as a second optional parameter, the name of the output |
---|
59 | directory (the current directory is the default). If the directory does not |
---|
60 | exist, it will be created. |
---|
61 | |
---|
62 | memlog_analyze depends on dot (from the graphviz package) and ps2pdf (from the |
---|
63 | ghostscript package), plus various tools from the binutils package. |
---|
64 | |
---|
65 | ** RELATED WORK ** |
---|
66 | |
---|
67 | Why was memlog created? There are several other tools that can support this use |
---|
68 | case, but none of them would work in our environment properly. They were |
---|
69 | either too slow, not runnable under the BG/Q CNK, not thread safe, did not |
---|
70 | properly support big-endian PPC64, supported only either static or dynamic |
---|
71 | linking, did not collect full backtraces, or just did not produce |
---|
72 | sufficiently-informative peak-usage output. |
---|
73 | |
---|
74 | That having been said, some other tools that might interest you: |
---|
75 | Valgrind Massif - http://valgrind.org/docs/manual/ms-manual.html |
---|
76 | Google Performance Tools - http://google-perftools.googlecode.com/svn/trunk/doc/heapprofile.html |
---|
77 | memtrail - https://github.com/jrfonseca/memtrail |
---|
78 | LeakTracer - http://www.andreasen.org/LeakTracer/ |
---|
79 | glibc mtrace - http://www.gnu.org/s/hello/manual/libc/Allocation-Debugging.html |
---|
80 | Heaptrack - http://milianw.de/blog/heaptrack-a-heap-memory-profiler-for-linux |
---|
81 | MemProf - http://www.secretlabs.de/projects/memprof/ |
---|
82 | |
---|
83 | The dot/pdf output produced by memlog was definitely inspired by that produced |
---|
84 | by Google's pprof tool in the aforementioned package. |
---|
85 | |
---|