Callgrind输出不包括函数调用

时间:2013-08-12 16:21:39

标签: valgrind output callgrind

我有一个简单的.c程序,它调用一个delcared并在同一个文件中实现的函数。 我用gcc编译它:

gcc myProgram.c -o myProgram -g

然后我使用valgrind和callgrind生成callgrind.out。*文件。

valgrind --tool=callgrind myProgram

然后我使用调用grind_annotate

callgrind_annotate callgrind.out.1974

但是结果与后面的内容类似,它不包含文件中的函数调用。我尝试了不同的c代码,但我得到了类似的结果,任何想法为什么?

--------------------------------------------------------------------------------
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]

1 个答案:

答案 0 :(得分:1)

尝试将这些选项添加到callgrind_annotate:

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

--tree=both为每个函数打印其调用者和被调用函数。

--threshold=100将打印所有事件(默认为99%,因此现在应打印您的功能)

顺便说一句,这两个选项可以打印一个非常重要的输出,所以你可以运行这个命令来找到你的功能:

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

编辑1

这很奇怪。你能发布你的代码吗? 这是我的代码:

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

void foo(int value);

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

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

这是我的输出:

$ 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]