First, install the Valgrind
Install Valgrind, the normal trilogy Configure/make/make install on the line.
Second, the use of Memchk
1. Execution of Orders
[Email protected] tools]# valgrind--track-fds=yes--log-file=memchk-svr.log--tool=memcheck--leak-check=full-- Show-reachable=yes./udp-pacing/valgrind_svr
2. View Logs
185 ==29107== 208 Bytes in 1 blocks is definitely lost in loss record 9 of 12
186 ==29107== at 0x4a05fef:calloc (vg_replace_malloc.c:711)
187 ==29107== by 0x4030f4:wmp_sender_init (wmp_impl.c:237)
188 ==29107== by 0x4034b5:wmp_socket_new_impl (wmp_impl.c:327)
189 ==29107== by 0x4069d6:handle_packet (wmp_impl.c:1434)
==29107== by 0x406d2e:wmp_socket_notify_packet (wmp_impl.c:1500)
191 ==29107== by 0x409dc2:udp_recvfrom (pt_session_udp.c:321)
192 ==29107== by 0x415487:event_process_active_single_queue (event.c:1346)
193 ==29107== by 0x415487:event_process_active (event.c:1416)
194 ==29107== by 0x415487:event_base_loop (event.c:1617)
195 ==29107== by 0x402839:main (valgrind_svr.c:167)
3. Analysis Log
"Definitely lost" this is a description of the certainty that a memory leak has occurred.
wmp_impl.c:237 sender_t *s = calloc (1, sizeof (sender_t));
Wmp_sender_init () function name, the memory space was requested in line 237, but not released.
Third, Callgrind
1. Execution of Orders
[Email protected] tools]# valgrind--tool=callgrind./udp-pacing/valgrind_svr
[Email protected] udp-pacing]# Ps-ef | grep valgrind
Root 29980 13926 5 11:06 pts/0 00:00:01 valgrind--tool=callgrind./udp-pacing/valgrind_svr
Root 29984 28594 0 11:06 pts/1 00:00:00 grep valgrind
[[email protected] udp-pacing]# KILL-USR1 29980 send signal to application process
[Email protected] udp-pacing]# Ps-ef | grep valgrind
Root 30012 28594 0 11:06 pts/1 00:00:00 grep valgrind
[email protected] tools]# ll callgrind.out.29980
-RW-------1 root root 73177 Jan 6 11:06 callgrind.out.29980
2. Print Graphics
To the official website to download the latest gprof2dot.py program, the old version does not support certain parameters, Https://github.com/jrfonseca/gprof2dot.
[[email protected] tools] #valgrind--tool=callgrind./udp-pacing/ut_cmp_server
[email protected] tools]# python gprof2dot-2015.12.1/gprof2dot.py-f callgrind callgrind.out.29980-z main-e0-n0 > Callgrind.out
[Email protected] tools]# dot-tjpg callgrind.out-o call.jpg
Valgrind's Memchk and Callgrind