抓取进程中包括其所有线程的iowait时间

perf事件是可以按照线程按照进程统计的呢,但是/proc/接口就不提供这样的功能

hon@station6:/proc/6288$ sudo perf stat -e sched:sched_switch -p 6288
[sudo] hon 的密码: 
^C
 Performance counter stats for process id '6288':

               473      sched:sched_switch                                          

       1.267507195 seconds time elapsed


hon@station6:/proc/6288$ sudo perf stat -e sched:sched_switch -t 6291
^C
 Performance counter stats for thread id '6291':

               157      sched:sched_switch                                          

       1.497770188 seconds time elapsed

 perf可以提供线程和进程的统计功能的,perf统计的原理是啥子呢

在perf_event_open处跟踪pid函数,发现结果是:

hon@station6:~/codebox/pthread$ sudo stap perf_event_open.stp 
Begin
perf: pid:6291

perf: pid:6288
perf: pid:6289
perf: pid:6290
perf: pid:6291
perf: pid:6292

这就明白是咋回事了,一个进程的线程是如何获取的,然后进程的pid

最重要的结构体是perf_event_context和perf_event,

perf: pid:12500 group_fd:4294967295
perf perf_event_alloc
perf: find_get_context.isra.82 ffff8800a770ba00
perf: pid:12932 group_fd:4294967295
perf perf_event_alloc
perf: find_get_context.isra.82 0
perf: alloc_perf_context



perf: pid:12931 group_fd:4294967295
perf perf_event_alloc
perf: find_get_context.isra.82 0
perf: alloc_perf_context
perf: pid:12932 group_fd:4294967295
perf perf_event_alloc
perf: find_get_context.isra.82 ffff88013677ee00
perf: pid:12933 group_fd:4294967295
perf perf_event_alloc
perf: find_get_context.isra.82 0
perf: alloc_perf_context
perf: pid:12934 group_fd:4294967295
perf perf_event_alloc
perf: find_get_context.isra.82 0
perf: alloc_perf_context
perf: pid:12935 group_fd:4294967295
perf perf_event_alloc
perf: find_get_context.isra.82 0
perf: alloc_perf_context

 都是在第一次新建的时候创建的

猜你喜欢

转载自www.cnblogs.com/honpey/p/9108728.html