How to detect application memory growth using Intel® Inspector XE 2013

Background

The most common usage of Intel® Inspector XE 2013 is for finding and fixing memory and threading correctness errors. Another useful feature is detecting where memory usage is growing in your program. This article describes the steps to use Intel® Inspector XE 2013 to detect where and when in your application memory use is growing.

Overview

The following is a step by step method for detecting application memory growth using Intel® Inspector XE 2013. These steps will be testing the tachyon sample code supplied with the Inspector XE 2013 release.

  1. Unzip the tachyon package located here: C:\Program Files (x86)\Intel\Inspector XE 2013\samples\en\C++\tachyon_insp_xe.zip. These steps assume you have unzipped the package to C:\tachyon_insp_xe.
  2. To build the tachyon sample application, double-click on the Microsoft Visual Studio* solution file located C:\tachyon_insp_xe\vc9\tachyon_insp_xe.sln
    1. Inside of Visual Studio, click on Build->Build Solution. This will compile and link the tachyon application in Microsoft Visual Studio
  3. Click on the "New Analysis" Icon in the toolbar. The icon is a light blue play button.

  4. By clicking the "New Analysis" button, you will bring up a dialog that will allow you configure the type of analysis you are about to run

  5. In this example we will run a "Detect Memory Problems analysis.
  6. To start the analysis click on the "Start" button.

  7. After you pressed the "Start" button the application should now be running.
  8. To measure the growth of memory Intel Inspector XE 2013 needs to have 2 relative points to measure from, a start and an end. To mark the start of the memory growth boundary, click on the "Set Transaction Start" button as shown in image in step 6.
  9. After the application has run a couple seconds, click the "Set Transaction End" button, also shown in the image in step 6.
  10. When the application completes, Intel Inspector XE 2013 will report some diagnostics in found in the program.

  11. In the image in step 10, you will notice a "Problem" of type "Memory Growth". By clicking on the "+" icon by the "Problem ID", P8, you can expand this to show all of the places, within the region you identified that memory grew. Note: the number of diagnostics reported is directly related to when you clicked the "Set Transaction Begin" and "Set Transaction End".

     

  12. By clicking on each of the individual problem lines you can view the error and source of the problem.

  13. If you double click on a problem line you can view and edit your source file.
  14. If you need to re-run an additional analysis you can always click on "New Analysis" and start the process from the beginning.

Computing Memory Growth via API

It is also possible to compute memory growth using a supplied Intel® Inspector XE 2013 api. In order to make use of this api, you will need to include the header file C:\Program Files (x86)\Intel\Inspector XE 2013\include\ittnotify.h into your application source file.

  1. To mark the beginning of a memory growth region, call the function __itt_heap_record_memory_growth_begin()
  2. To mark the end of a memory growth region, call the function __itt_heap_record_memory_growth_end()

Here is an example of snippet of code showing how you could compute memory growth using the ittnotify api. Note, you would need to add the directory C:\Program Files (x86)\Intel\Inspector XE 2013\include to your include path. 

#include "ittnotify.h"
main()
{
__itt_heap_record_memory_growth_begin();
<< INSERT the code you need to compute memory growth on here >>
__itt_heap_record_memory_growth_end();
}

After, you have rebuilt your application, you can then run a "New Analysis". Intel Inspector XE 2013 will be aware that you are using the ittnotify api, and will mark the memory regions precisely where you have indicated by the api calls.

Conclusion

Intel® Inspector XE 2013 is a powerful tool to help you easily identify correctness errors in your code. With the addition of ability to detect application memory growth it is now easier than ever to track down places in your code where memory use may be growing with you even being aware of it.

Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.