-toggle-collect option in valgrind/callgrind not working

175 views Asked by At

When I run callgrind with "--toggle-collect=fun" or "--toggle-collect=main" it does not work. I tried with adding return type also but nothing worked. "--toggle-collect=void fun" or "--toggle-collect=int main". any idea why it is not working?

cmd used

valgrind --tool=callgrind --callgrind-out-file=callgrind.out  "--toggle-collect=fun"  -v  a.out

below is the sample code

#include<stdio.h>
#include<stdlib.h>

void fun1()
{     
   for(int i=0; i<10;i++)
      printf("a");
}

int main()
{
        fun1();
}
1

There are 1 answers

2
Paul Floyd On

Your code uses fun1 but your Callgrind command uses --toggle-collect=fun which is missing the "1" at the end.

I don't know exactly what function matching Callgrind uses for toggle collect. It certainly supports '*' and '?' wildcards. I'm not sure what it does for C++ mangled names. It won't use the return type though.

EDIT: add example

With the wrong toggle. Note zero Ir (instructions retired).

paulf> valgrind --tool=callgrind --toggle-collect=fun  ./test                                          
==1606== Callgrind, a call-graph generating cache profiler
==1606== Copyright (C) 2002-2017, and GNU GPL'd, by Josef Weidendorfer et al.
==1606== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==1606== Command: ./test
==1606== 
==1606== For interactive control, run 'callgrind_control -h'.
==1606== 
==1606== Events    : Ir
==1606== Collected : 0
==1606== 
==1606== I   refs:      0

With the right toggle. 57k Irs.

paulf> valgrind --tool=callgrind --toggle-collect=fun1  ./test
==1607== Callgrind, a call-graph generating cache profiler
==1607== Copyright (C) 2002-2017, and GNU GPL'd, by Josef Weidendorfer et al.
==1607== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==1607== Command: ./test
==1607== 
==1607== For interactive control, run 'callgrind_control -h'.
==1607== 
==1607== Events    : Ir
==1607== Collected : 57501
==1607== 
==1607== I   refs:      57,501

If you want to use some form of prefix then you need to use the "?" or "*" wildcard characters.