Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int square(int x) { return x*x; }
- int main(void) {
- square(2);
- }
- $ gcc -O0 --coverage square.c
- $ ./a.out
- $ gcov -i square.c
- $ awk -F '[,:]' '$1 == "function" && $3 > 0 {print $3, $4}' square.c.gcov
- 1 square
- 1 main
- $ gcc -O0 -pg square.c
- $ ./a.out
- $ gprof -b -P
- Call graph
- granularity: each sample hit covers 2 byte(s) no time propagated
- index % time self children called name
- 0.00 0.00 1/1 main [7]
- [1] 0.0 0.00 0.00 1 square [1]
- -----------------------------------------------
- Index by function name
- [1] square
- #define _GNU_SOURCE
- #include <dlfcn.h>
- #include <stdlib.h>
- #include <stdio.h>
- #define TRACE_FD 3
- void __cyg_profile_func_enter (void *, void *)
- __attribute__((no_instrument_function));
- void __cyg_profile_func_enter (void *func, void *caller)
- {
- static FILE* trace = NULL;
- Dl_info info;
- if (trace == NULL) {
- trace = fdopen(TRACE_FD, "w");
- if (trace == NULL) abort();
- setbuf(trace, NULL);
- }
- if (dladdr(func, &info))
- fprintf (trace, "%p [%s] %sn",
- func,
- info.dli_fname ? info.dli_fname : "?",
- info.dli_sname ? info.dli_sname : "?");
- }
- $ gcc -O0 -rdynamic -finstrument-functions square.c instrument.c -ldl
- $ ./a.out 3>&1
- 0x400a8f [./a.out] main
- 0x400a4f [./a.out] square
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement