GDB will not do it well, although you can certainly hack something that yields wildly inaccurate results.
I would suggest the Valgrind plugin "Callgrind". As a bonus, it does not require absolutely no recompilation or other special settings. All you need is a valgrind installed on your system and debugging information in your program (or full information about characters, at least I'm not sure).
Then you invoke your program as follows:
valgrind
When this is done, the name of the file callgrind.out.<pid> will be indicated in the current directory. You can read and visualize this file with a very nice GUI tool called kcachegrind (usually you need to install it separately).
The only problem is that since callgrind slows down the execution of your program a little, the time spent on system calls may be less (in percentage terms) than it actually would be. By default, callgrind does not include system time in its counters, so the values it gives you are a real comparison of the code in your program, if not the actual time "under" this function. This may be confusing at first, so if that happens try adding --collect-systime=yes .
I'm not sure what the state of callgrind on ARM might be. ARMv7 is listed as a supported platform , but only says “fully enough”, whatever that means.
source share