Memory Consumption Analysis Using Intel® VTune™ Amplifier

ID 659842
Updated 9/14/2017
Version Latest




Intel® VTune™ Amplifier 2018 has a new feature called memory consumption analysis. Memory consumption analysis can be used to identify memory resources that are allocated and released over time and can be used in Linux native* and Python* targets. 


The memory consumption analysis can be found in the "Analysis Type" tab under Algorithm Analysis. This article uses a simple snippet of code shown below to illustrate  how memory consumption analysis can be used to identify a potential memory leak. 

void main(){
   char *ptr;
   for(int i=1000;i<1000000;i++){
       ptr = (char*)malloc(sizeof(i)+1024);

To start the analysis from the GUI, under "Analysis target" select the target system and launch the application by specifying the target executable.  Then under "Analysis type" tab select "Memory consumption analysis" and select "Start analysis".  If needed, you can change the Minimal dynamic memory object size to track option to reduce the runtime overhead of the instrumentation.

Once the analysis is done, the summary window is displayed as below.   This displays the list of top memory-consuming objects. For example, in this case the main function in mem_cons.cpp has the highest memory consumption metric of 979MB. The histogram shows the number of allocations for the particular allocation size. For the sample code, there are almost 1000000 allocations of size 1024 bytes.

For further analysis of the top consuming memory object, move to the bottom-up tab. The bottom-up tab indicates that the module mem_cons allocated 979MB of memory in a call tree displayed in the call stack pane on the right and hasn't released any memory so far as can be seen in the deallocation column or the allocation/dellocation delta value. If the allocation/deallocation delta value is non-zero that signals a potential memory leak. 


The timeline view in the bottom-up tab also shows the memory usage over time and for the above sample code since we haven't deallocated the memory, the memory consumption grows with time.

You can also double click on the function in the bottom-up tab to open the source view. This highlights the line of the code that allocates the maximum memory and can be used to identify the cause of memory leaks. For the sample code, as can be seen the memory allocation of 979MB happens at line number 13 of the source code and there is no deallocation of this dynamic memory leading to a potential memory leak.


The memory consumption analysis in VTune Amplifier can be used to intercept memory allocation/dellocation and identify peaks of memory consumption over the timeline and analyze allocation stacks for the hotspots functions that take up huge amount of memory