The Memory Analysis tool

The main system allocator keeps track of statistics associated with allocating and freeing memory such that the memory statistics module can unobtrusively inspect any process's memory usage. To extract the most information from your program, launch it with the Memory Analysis tool enabled, and then your program will use the debug version of the malloc library (librcheck.so).

If your binary is instrumented with Mudflap, you can't run Memory Analysis on it because there will be a conflict (trying to overload the same functions), and it will cause the program to crash.

Analyze a running program

Once the program is running, you can attach the Memory Analysis perspective and gather your data. For more information, see Attach to a running process in this chapter.
To disable the control thread option for memory analysis:
  1. From an existing launch configuration, select the Tools tab.
  2. If the Memory Analysis tool is not currently enabled, select Add/Delete Tool, select Memory Analysis, then click OK.
  3. Expand Advanced Settings.
  4. Disable the Create control thread option if it is currently enabled.
  5. Click Apply.
  6. Click Run.

For information about the Create control thread option, see Memory analysis of shared objects in this chapter.

Memory analysis of shared objects

To see symbol information for shared libraries used by your application, you must add the Shared Libraries tab in your launch configuration, and add the shared libraries search path like this:

  1. Open a Run or Debug launch configuration that is configured for memory analysis (see Launch your program with Memory Analysis).
  2. In the Create, manage, and run configurations dialog, click the Tools tab.
  3. Click Add/Delete Tool.
  4. In the Tools Selection dialog, select Shared Libraries.
  5. Click OK.
  6. Click the Shared Libraries tab.

    Shared Libraries

  7. Click Add… to add a path to the shared libraries, which is located on your host.

If you're importing an existing trace file, you have to specify the search libraries path in the Import dialog. See Import event information.

To be able to see file names and line numbers in the backtrace, shared libraries have to be compiled with debug information and not stripped on the host. It has to be equivalent to the target library, except debug symbols section. Otherwise, the backtrace would appear to be showing random locations. If the shared library isn't found on the host, the backtrace would contain only binary addresses.

In the Session View, you can expand your session, expand your process, and then select a shared object to view its memory events and traces in an editor or views.

Memory Analysis Tool options and environment variables

The following table shows a summary of Memory Analysis Tool (MAT) graphical user interface options (flags) and their corresponding environment variables:

Environment variable Where to find in Memory Analysis Tool GUI What option to set Additional information
LD_PRELOAD= librcheck.so Memory Analysis > Advanced Settings Runtime library The newer library file is librcheck.so, and the older file is libmalloc_g.so. A supported option for the rcheck library.
MALLOC_ACTION=<number> Memory Analysis > Memory Errors When an error is detected Set the error action behavior to: 0 to ignore, 1 to abort, 2 to exit, 3 for core, and 4 to stop. A supported option for the rcheck library.
MALLOC_CKACCESS=1 Memory Analysis > Memory Errors Verify parameters in string and memory functions Check strings and memory functions for errors. A supported option for the rcheck library.
MALLOC_CKBOUNDS=1 Memory Analysis > Memory Errors Enable bounds checking (where possible) Check for out of bounds errors. A supported option for the rcheck library.
MALLOC_CKALLOC=1 Memory Analysis > Memory Errors Enable check on realloc()/free() argument Check alloc and free functions for errors. A supported option for the rcheck library.
MALLOC_CKCHAIN=1 Memory Analysis > Memory Errors Perform a full heap integrity check on every allocation/deallocation Check the allocator chain integrity for every allocation/deallocation. A supported option for the rcheck library.
MALLOC_CTHREAD=<1,2> Memory Analysis > Advanced Settings Create control thread Start a control thread. Set to 1 to allow the IDE to send commands to the application through /dev/rcheck. Set to 2 to allow the IDE to send commands using signals. A supported option for the rcheck library.
MALLOC_CTRL_FILE=<file> N/A N/A Specify a file for the control command (to use with the control signal). You can use ${pid} in the filename to replace with process Id and escape $ if running from the shell. A supported option for the rcheck library.
MALLOC_CTRL_SIG=<sigs> N/A N/A Override the default signals (for example, "control:41,leaks:42, start:44,stop:43, marker:45"). A supported option for the rcheck library.
MALLOC_DUMP_ LEAKS=1 Memory Analysis > Memory Errors Perform leak check when process exits Enable the dumping of leaks on exit. A supported option for the rcheck library.
MALLOC_ERRFILE= /dev/null N/A N/A Error file location.
MALLOC_EVENTBTDEPTH=<number> Memory Analysis > Memory Tracing Limit back-trace depth to: 5 Set the error traces depth to a specific number. A supported option for the rcheck library.
MALLOC_FATAL=0 Memory Analysis > Memory Errors When an error is detected: report the error and continue
MALLOC_FILE=<file> Memory Analysis > Advanced Settings Target output file or device Re-direct output to a file. You can use ${pid} in the filename to replace with process Id and escape $ if running from the shell. A supported option for the rcheck library.
MALLOC_HANDLE_SIGNALS=0 N/A N/A When the value is 0, don't install signal handlers. A supported option for the rcheck library.
MALLOC_SAMPLING=<millis> N/A N/A Run sampling thread to produce heap statistics every <millis> milliseconds. A supported option for the rcheck library.
MALLOC_START_TRACING=1 Memory Analysis > Memory Tracing Enable memory allocation/deallocation tracing Enable memory tracing (0 to disable). A supported option for the rcheck library.
MALLOC_STAT_BINS=<bin1>,<bin2>,... Memory Analysis > Memory Snapshots Bin counters (comma separated) e.g. 8, 16, 32, 1024 Set custom bins. A supported option for the rcheck library.
MALLOC_TRACEBTDEPTH=<number> Memory Analysis > Memory Tracing Limit back-trace depth to Set the allocation traces depth to a specific number. A supported option for the rcheck library.
MALLOC_TRACEMAX=<number> Memory Analysis > Memory Tracing Maximum allocation to trace Only trace the allocation for the <= <number> of bytes. A supported option for the rcheck library.
MALLOC_TRACEMIN=<number> Memory Analysis > Memory Tracing Minimum allocation to trace Only trace the allocation for the >= <number> of bytes. A supported option for the rcheck library.
MALLOC_TRUNCATE=1 N/A N/A Truncate the output files before writing. A supported option for the rcheck library.
MALLOC_USE_CACHE=<number> N/A N/A Set to 0 to disable optimization. The default is 32. A supported option for the rcheck library.
MALLOC_VERBOSE=1 Memory Analysis > Advanced Settings Show debug output on console When set to 1, it enables the debug output. A supported option for the rcheck library.
MALLOC_WARN=0 Memory Analysis > Memory Errors When an error is detected: report the error and continue

Last modified: 2013-12-21

comments powered by Disqus