Chinaunix首页 | 论坛 | 博客
  • 博客访问: 411807
  • 博文数量: 115
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 393
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-26 12:10
个人简介

踏实做事,认真做人

文章分类

全部博文(115)

文章存档

2017年(1)

2016年(2)

2015年(14)

2014年(63)

2013年(35)

分类: 嵌入式

2013-06-05 18:58:45



 

ANDROID ON INTEL ARCHITECTUREperf for Android

Perf is a tracing and profiling tool for Linux, available on 2.6+ kernels. It is a userspace tool built on the perf_events kernel interface. The source code is available as part of the . Kernel versions 3.5+ also provide user space probes, so you can define new dynamic tracepoints in user space.

Using perf, you can dynamically trace and profile code. The advantage is that you can do this at runtime, without the need to recompile your code. For this, you need to have the symbols available for the functions you want to trace or profile.

Google has integrated perf 3.0.8 in their Jelly Bean realease. We are also providing the latest perf version (3.6) ported to Android in the Android-IA tree. Using perf 3.6 and the kernel from our tree, you can also use user space probes.

Next, is a short list of the main things you can do using perf.

System profiling

Using perf top, you can do a live analysis on the running system and see what functions are called most often, statistically. This is a tool similar to top, but it shows both kernel and userspace functions.

For example, you can check what functions are called when you enable Wi-Fi in Android:

root@android:/ # perf top
   PerfTop:    1271 irqs/sec  kernel:70.9%  exact:  0.0% [4000Hz cycles],  (all, 4 CPUs)
-------------------------------------------------------------------------------
     7.35%  wpa_supplicant    [.] dvmAsmInstructionStartCode          
     6.74%  wpa_supplicant    [k] 0x000001b1                          
     2.94%  [kernel]          [k] __lock_acquire.isra.31              
     2.65%  wpa_supplicant    [.] 0x00006ef8                          
     1.93%  wpa_supplicant    [.] _Z24S32_opaque_D32_filter_DXRK17SkBi
     1.77%  [kernel]          [k] lock_release                        
     1.72%  [kernel]          [k] native_sched_clock                  
     1.65%  [kernel]          [k] delay_tsc                           
     1.64%  wpa_supplicant    [.] .L1722                              
     1.24%  [kernel]          [k] lock_acquire                        
     1.12%  [kernel]          [k] lock_acquired                       
     1.12%  [kernel]          [k] local_clock                         
     1.09%  [kernel]          [k] sched_clock_cpu                     
     1.04%  wpa_supplicant    [.] symbol_filter                       
     1.03%  wpa_supplicant    [.] _ZL10scanObjectPK6ObjectP13GcMarkCon
     0.98%  wpa_supplicant    [.] strstr                              
     0.95%  wpa_supplicant    [.] inflate_fast                        
     0.85%  wpa_supplicant    [.] strcmp                              
     0.85%  wpa_supplicant    [.] pthread_mutex_unlock                
     0.79%  wpa_supplicant    [.] sha1_block_data_order               
     0.70%  wpa_supplicant    [.] pthread_mutex_lock

Gather performance statistics

You can run a command and gather performance statistics using perf stat. You can count any of the supported events listed by perf list and find out things like the number of cache misses, page faults, context switches, or system calls.

For example, you can find out how many memory related calls are made when starting zygote:

root@android:/ # stop zygote
root@android:/ # (sleep 5 && start zygote) &
root@android:/ # perf stat -e kmem:* -a sleep 20
 Performance counter stats for 'sleep 20':
            23,020 kmem:kmalloc                                                 [100.00%]
            70,682 kmem:kmem_cache_alloc                                        [100.00%]
                 0 kmem:kmalloc_node                                            [100.00%]
                 0 kmem:kmem_cache_alloc_node                                   [100.00%]
            21,151 kmem:kfree                                                   [100.00%]
            45,090 kmem:kmem_cache_free                                         [100.00%]
            15,673 kmem:mm_page_free                                            [100.00%]
            14,177 kmem:mm_page_free_batched                                    [100.00%]
            64,701 kmem:mm_page_alloc                                           [100.00%]
            54,134 kmem:mm_page_alloc_zone_locked                               [100.00%]
             5,084 kmem:mm_page_pcpu_drain                                      [100.00%]
                 0 kmem:mm_page_alloc_extfrag                                   
      20.004086711 seconds time elapsed

Collect profiles

You can use perf record to record the profile for a given command. Samples collected in this way can be analysed later, using perf report. For an example, see the section below.

Define new dynamic tracepoints

You can add dynamic tracepoints using perf probe. You can add these tracepoints in the kernel or user space. To use user space probes, you need to have kernel version 3.5+.

You can find out who called schedule in the kernel in 1 second on an idle system:

root@android:/ # perf probe -a schedule
Added new event:
  probe:schedule       (on schedule)
You can now use it in all perf tools, such as:
       perf record -e probe:schedule -aR sleep 1
root@android:/ # perf record -e probe:schedule -aR sleep 1                 
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.209 MB perf.data (~9123 samples) ]
root@android:/data # perf report --sort comm,dso                               
# [...]
# Samples: 58  of event 'probe:schedule'
# Event count (approx.): 58
#
# Overhead         Command      Shared Object
# ........  ..............  .................
#
    50.00%         swapper  toolbox          
    18.97%     kworker/0:0  toolbox          
    13.79%     kworker/1:0  toolbox          
     3.45%   system_server  toolbox          
     3.45%           sleep  toolbox          
     3.45%     kworker/2:1  toolbox          
     1.72%  wpa_supplicant  toolbox          
     1.72%            perf  toolbox          
     1.72%            netd  toolbox          
     1.72%     migration/1  toolbox          

Or you can see how many times the malloc function from libc is called on an idle system in 1 second:

root@android:/data # perf probe -x /system/lib/libc.so malloc                  
Added new event:
  probe_libc:malloc    (on 0x17e10)
You can now use it in all perf tools, such as:
       perf record -e probe_libc:malloc -aR sleep 1
root@android:/data # perf stat -e probe_libc:malloc -a sleep 1                 
 Performance counter stats for 'sleep 1':
               146 probe_libc:malloc                                           
       1.003249671 seconds time elapsed

... and much more

You can check the official documentation for perf in the Linux Kernel sources at tools/perf/Documentation. There is also a good tutorial for Linux at .

阅读(1607) | 评论(3) | 转发(0) |
0

上一篇:没有了

下一篇:Android Linux Kernel Module Oprofile

给主人留下些什么吧!~~

hongjiujing2013-07-12 09:19:52

>
> # perf record -a -g -F 997 sleep 60
>

注意这里使用997是要故意和时钟中断频率错开。指定时钟中断频率实际上在内核的perf profiling里会干扰到你样本的收集,使得结果不符合实际情况。

这点社区里很多文档是没有提的。Systemtap在这里好像还有bug,无法任意指定一个频率。

我们一般用997 需要再高点频率就是 1234。总之不要和时钟中断频率有倍数关联。

hongjiujing2013-06-09 11:08:35

hongjiujing:1)Makefile ===> CFLAGS = -static -fno-omit-frame-pointer ......==>static link for android,if android4.x platform,dont use ,can use android extern/perf

2)If report:
Makefile:455: No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev
Makefile:470: *** No gnu/libc-version.h found, 

android JB support perf

回复 | 举报

hongjiujing2013-06-09 11:07:59

1)Makefile ===> CFLAGS = -static -fno-omit-frame-pointer ......==>static link for android,if android4.x platform,dont use ,can use android extern/perf

2)If report:
Makefile:455: No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev
Makefile:470: *** No gnu/libc-version.h found,