user847988
user847988

Reputation: 984

Callgrind output does not include function calls

I have a simple .c program that makes a call to a function delcared and implemented in the same file. I compile it using gcc:

gcc myProgram.c -o myProgram -g

Then I use valgrind with callgrind to generate the callgrind.out.* file.

valgrind --tool=callgrind myProgram

Then I use the call grind_annotate

callgrind_annotate callgrind.out.1974

But the result is something similar to what follows and it doesnt include the function call that is in the file. I tried different c code but I get similar results, any idea why?

--------------------------------------------------------------------------------
Profile data file 'callgrind.out.1974' (creator: callgrind-3.8.1)
--------------------------------------------------------------------------------
I1 cache: 
D1 cache: 
LL cache: 
Timerange: Basic block 0 - 34772
Trigger: Program termination
Profiled target:  myProgram (PID 1974, part 1)
Events recorded:  Ir
Events shown:     Ir
Event sort order: Ir
Thresholds:       99
Include dirs:     
User annotated:   
Auto-annotation:  off

--------------------------------------------------------------------------------
     Ir 
--------------------------------------------------------------------------------
159,723  PROGRAM TOTALS

--------------------------------------------------------------------------------
    Ir  file:function
--------------------------------------------------------------------------------
51,246  ???:_dl_addr [/lib64/libc-2.5.so]
25,816  ???:do_lookup_x [/lib64/ld-2.5.so]
21,895  ???:_dl_lookup_symbol_x [/lib64/ld-2.5.so]
10,955  ???:_dl_relocate_object [/lib64/ld-2.5.so]
10,487  ???:strcmp'2 [/lib64/ld-2.5.so]
 4,974  ???:check_match.8516 [/lib64/ld-2.5.so]
 3,885  ???:getenv [/lib64/libc-2.5.so]
 1,834  ???:strcmp [/lib64/ld-2.5.so]
 1,663  ???:_dl_map_object_from_fd [/lib64/ld-2.5.so]
 1,638  ???:strlen [/lib64/ld-2.5.so]
 1,382  ???:bsearch [/lib64/libc-2.5.so]
 1,323  ???:_dl_name_match_p [/lib64/ld-2.5.so]
 1,288  ???:strsep [/lib64/ld-2.5.so]
 1,211  ???:_dl_map_object_deps [/lib64/ld-2.5.so]
 1,175  ???:dl_main [/lib64/ld-2.5.so]
 1,038  ???:_dl_check_map_versions [/lib64/ld-2.5.so]
   796  ???:malloc_consolidate [/lib64/libc-2.5.so]
   780  ???:strncmp [/lib64/libc-2.5.so]
   751  ???:_dl_cache_libcmp'2 [/lib64/ld-2.5.so]
   635  ???:__libc_memalign [/lib64/ld-2.5.so]
   625  ???:setlocale [/lib64/libc-2.5.so]
   624  ???:_nl_find_locale [/lib64/libc-2.5.so]
   586  ???:intel_02_known_compare [/lib64/libc-2.5.so]
   577  ???:_dl_fixup [/lib64/ld-2.5.so]
   576  ???:_dl_new_object [/lib64/ld-2.5.so]
   543  ???:memset [/lib64/ld-2.5.so]
   528  ???:index [/lib64/ld-2.5.so]
   489  ???:_dl_fini [/lib64/ld-2.5.so]
   471  ???:match_symbol [/lib64/ld-2.5.so]
   469  ???:open_verify [/lib64/ld-2.5.so]
   450  ???:memcpy [/lib64/ld-2.5.so]
   427  ???:_dl_map_object [/lib64/ld-2.5.so]
   415  ???:intel_check_word [/lib64/libc-2.5.so]
   400  ???:_int_malloc [/lib64/libc-2.5.so]
   395  ???:mempcpy [/lib64/ld-2.5.so]
   392  ???:_dl_sysdep_start [/lib64/ld-2.5.so]
   375  ???:_dl_start [/lib64/ld-2.5.so]
   370  ???:ptmalloc_init [/lib64/libc-2.5.so]
   348  ???:new_composite_name [/lib64/libc-2.5.so]
   340  ???:_dl_load_cache_lookup [/lib64/ld-2.5.so]
   331  ???:_dl_next_ld_env_entry [/lib64/ld-2.5.so]
   301  ???:open_path [/lib64/ld-2.5.so]
   279  ???:process_envvars [/lib64/ld-2.5.so]
   279  ???:_dl_important_hwcaps [/lib64/ld-2.5.so]
   278  ???:_dl_init_paths [/lib64/ld-2.5.so]
   225  ???:_dl_runtime_resolve [/lib64/ld-2.5.so]
   188  ???:_dl_sort_fini [/lib64/ld-2.5.so]
   165  ???:_dl_cache_libcmp [/lib64/ld-2.5.so]
   164  ???:call_init [/lib64/ld-2.5.so]
   135  ???:fillin_rpath [/lib64/ld-2.5.so]
   118  ???:handle_intel [/lib64/libc-2.5.so]
   114  ???:malloc [/lib64/ld-2.5.so]
   109  ???:init_cacheinfo [/lib64/libc-2.5.so]
   109  ???:_IO_un_link [/lib64/libc-2.5.so]
   108  ???:_dl_catch_error [/lib64/ld-2.5.so]
    96  ???:_dl_setup_hash [/lib64/ld-2.5.so]
    94  ???:_dl_add_to_namespace_list [/lib64/ld-2.5.so]
    81  ???:_IO_flush_all_lockp [/lib64/libc-2.5.so]
    79  ???:_dl_check_all_versions [/lib64/ld-2.5.so]
    76  ???:set_binding_values [/lib64/libc-2.5.so]
    75  ???:__new_exitfn [/lib64/libc-2.5.so]
    73  ???:_dl_allocate_tls_init [/lib64/ld-2.5.so]
    73  ???:_dl_init [/lib64/ld-2.5.so]
    72  ???:calloc [/lib64/ld-2.5.so]
    65  ???:exit [/lib64/libc-2.5.so]
    65  ???:fclose@@GLIBC_2.2.5 [/lib64/libc-2.5.so]
    64  ???:_xstat [/lib64/ld-2.5.so]
    63  ???:__sigsetjmp [/lib64/ld-2.5.so]
    63  ???:init_tls [/lib64/ld-2.5.so]
    59  ???:open [/lib64/ld-2.5.so]

Upvotes: 2

Views: 4246

Answers (1)

Junior Dussouillez
Junior Dussouillez

Reputation: 2397

Try to add these options to callgrind_annotate :

callgrind_annotate --threshold=100 --tree=both callgrind.out.*

--tree=both prints, for each functions, their callers and the called functions.

--threshold=100 will print all the events (default is 99% so now your function should be printed)

BTW, these two options can print a very important output, so you can run this command to find your function :

callgrind_annotate --threshold=100 --tree=both callgrind.out.* | grep your_function_name

EDIT 1

That's weird. Can you post your code ? This is my code :

// myProgram.c
#include <stdio.h>

void foo(int value);

int main(void) {
  foo(10);
  return 0;
}

void foo(int value) {
  printf("%d\n", value);
}

And this is my output :

$ gcc myProgram.c -o myProgram -g
$ valgrind --tool=callgrind ./myProgram
==5551== Callgrind, a call-graph generating cache profiler
==5551== Copyright (C) 2002-2012, and GNU GPL'd, by Josef Weidendorfer et al.
==5551== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==5551== Command: ./myProgram
==5551== 
==5551== For interactive control, run 'callgrind_control -h'.
10
==5551== 
==5551== Events    : Ir
==5551== Collected : 102927
==5551== 
==5551== I   refs:      102,927
$ callgrind_annotate --threshold=100 --tree=both callgrind.out.5551 | grep "foo"
  783  < myProgram.c:foo (1x) [/home/junior/test/myProgram]
1,613  < myProgram.c:foo (1x) [/home/junior/test/myProgram]
   11  *  myProgram.c:foo [/home/junior/test/myProgram]
2,407  >   myProgram.c:foo (1x) [/home/junior/test/myProgram]

Upvotes: 2

Related Questions