valgrind打印程序调用栈

使用valgrind调试,他功能有很多,但是真正性能调试时候,外加valgrind运行程序时,应用程序本身性能发挥不全,目前对于我来讲还是调用栈打印最实用

通过多次打调用栈,可得知应用程序忙在哪里,确认优化的方向

使用valgrind开启程序

1
2
3
4
5
6
7
8
[root@localhost ~]# valgrind --tool=callgrind  ./server
==1789== Callgrind, a call-graph generating cache profiler
==1789== Copyright (C) 2002-2015, and GNU GPL'd, by Josef Weidendorfer et al.
==1789== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==1789== Command: ./server
==1789==
==1789== For interactive control, run 'callgrind_control -h'.
listening...

打印调用栈

callgrind_control -e -b

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@localhost ~]# callgrind_control -e -b
PID 1789: ./server
sending command status internal to pid 1789

Totals: Ir
Th 1 159,440

Frame: Ir Backtrace for Thread 1
[ 0] 2,538 __select_nocancel (424 x)
[ 1] 3,378 select (423 x)
[ 2] 64,731 main (1 x)
[ 3] 64,937 (below main) (1 x)
[ 4] 65,876 _dl_runtime_resolve_sse_vex (1 x)
[ 5] 65,888 _dl_runtime_resolve_avx_slow (1 x)
[ 6] 65,904 0x0000000000400710 (1 x)
[ 7] . 0x0000000000001170