|
From: Jon <jo...@po...> - 2015-05-01 21:45:31
|
Hello,
I am entirely new to Valgrind and have just installed it on a Linux Mint
system by running "apt-get install valgrind". To get started, I did run
cachegrind on a very simple C program, which did nothing more than to
add two integer variables. This is the result I got:
==12404== I refs: 101,339
==12404== I1 misses: 711
==12404== LLi misses: 704
==12404== I1 miss rate: 0.70%
==12404== LLi miss rate: 0.69%
==12404==
==12404== D refs: 38,424 (25,653 rd + 12,771 wr)
==12404== D1 misses: 1,696 ( 1,210 rd + 486 wr)
==12404== LLd misses: 1,502 ( 1,043 rd + 459 wr)
==12404== D1 miss rate: 4.4% ( 4.7% + 3.8% )
==12404== LLd miss rate: 3.9% ( 4.0% + 3.5% )
I was surprised by the relatively large amount of instructions executed,
so I did the following:
mint ~ $ cat test.c
int main() {
return 0;
}
mint ~ $ gcc test.c -o test
mint ~ $ valgrind --tool=callgrind ./test
==12430== Callgrind, a call-graph generating cache profiler
==12430== Copyright (C) 2002-2013, and GNU GPL'd, by Josef Weidendorfer
et al.
==12430== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for
copyright info
==12430== Command: ./test
==12430==
==12430== For interactive control, run 'callgrind_control -h'.
==12430==
==12430== Events : Ir
==12430== Collected : 101336
==12430==
==12430== I refs: 101,336
mint ~ $ callgrind_annotate callgrind.out.12430
--------------------------------------------------------------------------------
Profile data file 'callgrind.out.12430' (creator: callgrind-3.10.0.SVN)
--------------------------------------------------------------------------------
I1 cache:
D1 cache:
LL cache:
Timerange: Basic block 0 - 22401
Trigger: Program termination
Profiled target: ./test (PID 12430, part 1)
Events recorded: Ir
Events shown: Ir
Event sort order: Ir
Thresholds: 99
Include dirs:
User annotated:
Auto-annotation: off
--------------------------------------------------------------------------------
Ir
--------------------------------------------------------------------------------
101,336 PROGRAM TOTALS
--------------------------------------------------------------------------------
Ir file:function
--------------------------------------------------------------------------------
21,478 /build/buildd/eglibc-2.19/elf/dl-lookup.c:do_lookup_x
[/lib/x86_64-linux-gnu/ld-2.19.so]
17,844 /build/buildd/eglibc-2.19/elf/dl-lookup.c:_dl_lookup_symbol_x
[/lib/x86_64-linux-gnu/ld-2.19.so]
16,283
/build/buildd/eglibc-2.19/elf/../sysdeps/x86_64/dl-machine.h:_dl_relocate_object
8,247 /build/buildd/eglibc-2.19/elf/do-rel.h:_dl_relocate_object
8,231
/build/buildd/eglibc-2.19/string/../sysdeps/x86_64/multiarch/../strcmp.S:strcmp'2
[/lib/x86_64-linux-gnu/ld-2.19.so]
4,224 /build/buildd/eglibc-2.19/elf/dl-lookup.c:check_match.9458
[/lib/x86_64-linux-gnu/ld-2.19.so]
2,226
/build/buildd/eglibc-2.19/string/../sysdeps/x86_64/rtld-memset.S:memset
[/lib/x86_64-linux-gnu/ld-2.19.so]
1,179
/build/buildd/eglibc-2.19/elf/dl-version.c:_dl_check_map_versions
[/lib/x86_64-linux-gnu/ld-2.19.so]
1,169
/build/buildd/eglibc-2.19/string/../sysdeps/x86_64/multiarch/../strcmp.S:strcmp
[/lib/x86_64-linux-gnu/ld-2.19.so]
1,147 /build/buildd/eglibc-2.19/elf/dl-load.c:_dl_map_object_from_fd
[/lib/x86_64-linux-gnu/ld-2.19.so]
1,058 /build/buildd/eglibc-2.19/elf/dl-deps.c:_dl_map_object_deps
[/lib/x86_64-linux-gnu/ld-2.19.so]
1,018 /build/buildd/eglibc-2.19/string/../string/memcmp.c:bcmp
[/lib/x86_64-linux-gnu/ld-2.19.so]
1,014 /build/buildd/eglibc-2.19/elf/dl-minimal.c:strsep
[/lib/x86_64-linux-gnu/ld-2.19.so]
[...]
Since none of these functions were called by the program above, I wonder
if this how the output is supposed to look. Were are these function
calls coming from then? Or could there be something wrong with the way I
installed Valgrind?
Best regards,
Jon
|
|
From: Philippe W. <phi...@sk...> - 2015-05-01 22:07:54
|
On Fri, 2015-05-01 at 23:45 +0200, Jon wrote: > Since none of these functions were called by the program above, I wonder > if this how the output is supposed to look. Were are these function > calls coming from then? Or could there be something wrong with the way I > installed Valgrind? This is all normal. Unless you link statically, the program will be linked with the dynamic loader and other .so, which will be called at startup Use ldd ./test to see these. Note btw that having a dynamically linked executable is critical to have Valgrind tools such as memcheck or helgrind working properly. Philippe |
|
From: Julian S. <js...@ac...> - 2015-05-02 07:06:25
|
On 02/05/15 00:07, Philippe Waroquiers wrote: > This is all normal. Unless you link statically, the program will be > linked with the dynamic loader and other .so, which will be called > at startup Indeed, a mere 100000 instructions to get to main() is cheap. More typically I have seen it costing around a million instructions to get to main(). J |
|
From: John R. <jr...@bi...> - 2015-05-01 22:17:56
|
> Since none of these functions were called by the program above,
Those functions are the dynamic linker adding libc.so to your process address space.
'main' is moderately far removed from the beginning of execution.
$ readelf --headers test | grep Entry
Entry point address: 0x400400
$ gdb test
(gdb) x/12i 0x400400
0x400400 <_start>: xor %ebp,%ebp
0x400402 <_start+2>: mov %rdx,%r9
0x400405 <_start+5>: pop %rsi
0x400406 <_start+6>: mov %rsp,%rdx
0x400409 <_start+9>: and $0xfffffffffffffff0,%rsp
0x40040d <_start+13>: push %rax
0x40040e <_start+14>: push %rsp
0x40040f <_start+15>: mov $0x400570,%r8
0x400416 <_start+22>: mov $0x400500,%rcx
0x40041d <_start+29>: mov $0x4004f0,%rdi
0x400424 <_start+36>: callq 0x4003e0 <__libc_start_main@plt>
0x400429 <_start+41>: hlt
(gdb) quit
$ LD_DEBUG=ALL ./test
5360:
5360: file=libc.so.6 [0]; needed by ./test [0]
5360: find library=libc.so.6 [0]; searching
5360: search cache=/etc/ld.so.cache
5360: trying file=/lib64/libc.so.6
5360:
5360: file=libc.so.6 [0]; generating link map
5360: dynamic: 0x0000003ef37b8b80 base: 0x0000000000000000 size: 0x00000000003bf260
5360: entry: 0x0000003ef3421c50 phdr: 0x0000003ef3400040 phnum: 10
5360:
5360: checking for version `GLIBC_2.2.5' in file /lib64/libc.so.6 [0] required by file ./test [0]
5360: checking for version `GLIBC_2.3' in file /lib64/ld-linux-x86-64.so.2 [0] required by file /lib64/libc.so.6 [0]
5360: checking for version `GLIBC_PRIVATE' in file /lib64/ld-linux-x86-64.so.2 [0] required by file /lib64/libc.so.6 [0]
5360:
5360: Initial object scopes
5360: object=./test [0]
5360: scope 0: ./a.out /lib64/libc.so.6 /lib64/ld-linux-x86-64.so.2
[[snip]]
|