[Android] 性能获取方式-转自淘测试

来源:互联网 发布:单片机课程设计目的 编辑:程序博客网 时间:2024/05/29 10:22
原文地址:http://www.taobaotesting.com/blogs/2189 
不需要再安装任何性能监测工具,直接如下访问,帮助完成性能数据的获取和查看。 

Android apk 需要关注的点:apk大小、apk启动时间、流量、电量、CPU运行时长、内存、actvity切换时间等。 


android性能数据采集: 
流量数据: 
    /proc/self/net/dev   中的:eth0 和 rmnet0 对应数据和 

result-eg: 
    Inter-|   Receive                                                |  Transmit 
face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed 
    lo:    2304      32    0    0    0     0          0         0     230432    0    0    0     0       0          0 
  eth0:  122801    1712    0    0    0     0          0         0   232055    1399    0    0    0     0       0          0 
  sit0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0 
    
    
apk信息: 
   命令: aapt d badging   可获取:packagename、versioncode、launchActivity ---- 供后面启动时间等传参使用

result-eg: 
    package: name='com.taobao.taobao' versionCode='56' versionName='3.3.1' 
launchable-activity: name='com.taobao.tao.Welcome' 

# 电量信息及CPU 使用时长 
    命令: adb shell dumpsys batteryinfo  packagename 
结果包含如下数据:network ---received and send 大小;wake lock window:屏幕唤醒时长;sensor:传感器时长;cpu运行时长(包含各子进程的时长,后台service等) 

result-eg: 

#10109: 
    Network: 10.81MB received, 118.94KB sent 
    Wake lock window: 7s 232ms window (2 times) realtime 
    Sensor 0: 1m 31s 22ms realtime (27 times) 
    Proc com.taobao.taobao: 
      CPU: 1m 46s 270ms usr + 27s 410ms krn 
      10 proc starts 
    Proc com.taobao.taobao:taobao_remote: 
      CPU: 4s 220ms usr + 640ms krn 
      2 proc starts 
    Proc com.taobao.taobao:remote: 
      CPU: 530ms usr + 430ms krn 
      2 proc starts 
    Apk com.taobao.taobao: 
      Service com.taobao.tao.WWMessageService: 
        Created for: 45m 40s 653ms  uptime 
        Starts: 2, launches: 2 

#客户端启动时间获取: 
   命令: adb logcat -c && adb logcat -s ActivityManager | grep  "Displayed”  可获取到actvity的切换时间 ,其中可以获取到launch Activity对应的时间-----即apk启动时间。 

result-eg: 

   Line 1387: I/ActivityManager(   59): Displayed activity com.taobao.taobao/com.taobao.tao.Welcome: 2438 ms (total 2438 ms) 
     

# 内存情况获取: 
   命令 adb shell dumpsys meminfo  packagename 
   获取 alloc 和 size的值 

result-eg: 

    ** MEMINFO in pid 2427 [com.taobao.taobao] ** 

                    native   dalvik    other    total 

            size:    14416     8583      N/A    22999 

       allocated:    10800     6383      N/A    17183 

            free:      647     2200      N/A     2847 

           (Pss):     3193     7545    13536    24274 

  (shared dirty):     1180     4040     2772     7992 

    (priv dirty):     3168     5660     7756    16584 

   =========================================================================== 
   对任何apk,都可以通过以上命令获取到对应的性能数据。
0 0
原创粉丝点击