I am looking for such kind of a tool on either Unix/Linux platform which can achieve:
- I have the source files and I compiled the application myself (the source code is in C, although I don't really think it matters here)
- I want to run this application while every function calls are printed/logged to a stdout/file
For example:
#include <stdio.h>
int square(int x) { return x*x; }
int main(void) {
square(2);
}
And when I run this program it will print out
- main
- square
I understand that gdb
can do this to some extent, or valgrind
but they all do not do exactly what I want. I am just wondering if such a tool exist? Thanks.
Best Answer
Using
gcov
:(where the number is the number of times the function was called (we skip the ones that are never called with
$3 > 0
in theawk
part)).That's typically used for code coverage (how much of the code is being tested). You could also use the
gprof
code profiling tool (typically used to figure out how much time is spent in various areas of the code):