MTuner
 C/C++ memory profiler

Home | Download | Features | Documentation | License

MTuner documentation - custom toolchains

Using custom GCC toolchains

If your applications are built using GCC based cross compilers, targeting other platforms, you can still use MTuner to profile memory with some additional work. Each capture file (*.MTuner) starts with a header defining the host platform and a few additional parameters like endianess and word size of the host platform. Adding a custom toolchain is a matter of porting the MTuner SDK library to your target platform and this page will provide a detailed guideline how to do that.

MTuner SDK comes with full source code and file names will be referred to here directly. For information on directory structure please visit the MTuner SDK page.

Linking custom toolchains to MTuner

rmem_enums.h header file has an enum ToolChain that lists toolchains that may be supported by MTuner. Some of the toolchains will be supported in the future but the focus in this page is on ‘CustomX’ enums. Each of those enum values corresponds to an entry in toolchain combo box in GCC toolchains dialog. These values are the toolchain identifier written in the header of the capture (*.MTuner) file. See the MemoryHook constructor in rmem_hook.cpp for details.

When MTuner loads the capture file it will use the toolchain identifier in order to use the correct way to resolve debug symbols. For GCC based toolchains this normally means locating addr2line, nm and C++filt utilities.

Adding a new custom toolchain

All of the code that needs porting work is located in three header files, rmem.h, rmem_mutex.h and rmem_platform.h. Following the implementation for any of the already supported platforms should provide you with sufficient information to add a new platform but here is the breakdown of the process:

  • Add a define specifying a new platform, e.g. RMEM_PLATFORM_NEW_PLATFORM.
  • Modify platform and compiler detection code so it correctly detects the new platform. This code can be found just below the “Detect platform” comment in rmem.h
  • Make sure the endianess is correctly detected too based on the target CPU. Basically RMEM_BIG_ENDIAN or RMEM_LITTLE_ENDIAN should be set to 1 accordingly.
  • Implement code for your target platform in the following functions: getThreadID, getStackTrace, getCPUClock and getCPUFrequency.
  • Finally, implement a mutex class for your target platform by modifying rmem_mutex.h, Please note that mutex implementation needs to be reentrant at the moment.

That’s it! Once the porting is done, build the library with the target toolchain. GENie may be used for easy builds but creating a library and manually adding files to your favourite IDE will work fine as well.

Consider donating to support the ongoing development and maintenance of MTuner.
Thank you!
 

Help promote MTuner

     

Copyright © 2016 by Milos Tosic
All rights reserved.