Chinese

https://github.com/teawater/cma

What is CMA?
A GDB Python script that analyzes and records C/C++ application's dynamic memory status.
CMA has little effect on analyzed C/C++ application performance.
CMA supports X86_32, X86_64 and ARM.

How to use CMA?
  1. CMA just can work with GDB 7.5 or newer version. You can use Get-GDB check the version of GDB in current system and get GDB 7.5 or newer version if need.
    wget https://raw.githubusercontent.com/teawater/get-gdb/master/get-gdb.py
    python get-gdb.py
  2. Get CMA.
    wget https://raw.githubusercontent.com/teawater/cma/master/cma.py
  3. C/C++ application that want to analyzes should be built with GCC "-g" option to get the memory allocate and release code line infomation.
    gcc -g xxx
    g++ -g xxx
  4. GDB control the C/C++ application that want to analyzes.
    There are some ways:
    • Open GDB with a application. Don't need execute application because CMA script will auto do it if need.
      gdb xxx
    • Attach a running application.
      gdb -p pid
      Or
      gdb
      attach pid
  5. Start CMA script inside GDB.
    It will let you input some options. Then, exencute application and analyzes its memory allocate and release.
    source cma.py
  6. When CMA script and application is running, you can use CTRL-C interrupt their execution. Then, you can let CMA script save record to a CSV file.
    CSV file can be read by Openoffice or Excel.
    [0] Record memory infomation to "/home/teawater/tmp/cma.csv".
    [1] Continue.
    [2] Quit.
    Which operation?[0]
    Memory infomation saved into "/home/teawater/tmp/cma.csv".
    Continuing.

The CSV file that is generated by CMA script
Btween the not released dynamic memories and the released dynamic memories have a blank line.

The columns:
  • Type
    The dynamic memory type is new or malloc. CMA script can record them in same time.
  • Address
    The address of a dynamic memory.
  • Size
    The size of a dynamic memory.
  • Existence time(sec)
    The existence time of a dynamic memory in second.
    If this dynamic memory is released, it is time from allocate this dynamic memory to release this dynamic memory.
    If this dynamic memory is not released, it is time from allocate this dynamic memory to current time.
  • Allocate line
    The code line infomation of a dynamic memory is allocated.
  • Release line
    The code line infomation of a dynamic memory is allocated.
    If this dynamic memory is not released, this column is empty.
  • Allocate backtrace
    The backtrace infomation of a dynamic memory is allocated.
  • Release backtrace
    The backtrace infomation of a dynamic memory is allocated.
    If this dynamic memory is not released, this column is empty.

Screenshot
This is a screenshot of a CSV file.

My home page