性能分析工具

来源:互联网 发布:制作日历的软件 编辑:程序博客网 时间:2024/04/29 13:21

保建国是我们另外一个组做存储的人,对内核很了解的高手,看到我在做性能优化,说perf这个可以看到内核消耗的时间。

gprof主要是优化用户空间程序调用,perf主要是看内核的函数占用的时间。

rtmp这种协议,将message分成chunk后发送,会导致小的chunk包在user和kernel之间拷贝,放在哪个地方都是一样的费时间。

centos6下面才有这个工具,系统自带的。

使用方法:

[plain] view plaincopy
  1. perf record -g -p 8786 -f  

运行一段时间后,按CTRL+C退出。

然后看结果:

[plain] view plaincopy
  1. perf report -g  

另外,top也能看到CPU的用户使用,内核使用率,中断的CPU使用率。

Cpu7  : 57.5%us, 19.6%sy,  0.0%ni,  5.0%id,  0.0%wa,  0.0%hi, 17.9%si,  0.0%st

明显内核和软中断比较高,用户空间也不小。


另外,mpstat也能看到。

mpstat -P ALL 3

12:33:09 PM  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s

12:33:12 PM    7   56.15    0.00   18.94    0.00    0.00   19.60    0.00    5.32   7373.09

可见用户空间,系统调用和软中断(网卡发包)三个大头。


查看系统调用占用的时间:sudo strace -p 25817 -c

譬如:

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 85.32    0.003865           0    142413           gettimeofday

获取时间的函数太多了,改了下后,提升了6%左右。


另外,绑定cpu后,能将软中断降低10%,所以降低CPU10%。

taskset -p 1 pid

https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_MRG/1.3/html/Realtime_Tuning_Guide/sect-Realtime_Tuning_Guide-General_System_Tuning-Interrupt_and_Process_Binding.html 

0 0
原创粉丝点击