Chinaunix首页 | 论坛 | 博客
  • 博客访问: 580915
  • 博文数量: 192
  • 博客积分: 3780
  • 博客等级: 中校
  • 技术积分: 1487
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-26 10:11
文章存档

2012年(6)

2011年(160)

2010年(26)

分类: 嵌入式

2011-04-06 18:46:31

Profiling Android Applications

Profiling Android Applications

Profiling is important since it allows you to analyze runtime behaviour of your application. You can use gathered information to spot points which need improvement and hence optimize your application. Luckily Android provides tools for profiling if you had an Android device.

Profiling within Eclipse

Seems as this option is available for Linux users. Windows users report they don't have this option. I don't know about Mac. You need to install Android ADT plugin. See: insallation page. You also need your device connected to your computer and debuggable flag is set in AndroidManifest file.

In Eclipse, make sure Devices view is visible. Select Window|Show View|Other|Android|Devices. In Devices view, on upper right, among other buttons you will see "Start Method Profiling" button. Select your application among list and click "Start Method Profiling" button. The button's appearance and text changes. Use your application for some time and click button again to finish profiling. ADT plugin automatically pulls trace file from device and starts Traceview application to display results.

File:Eclipse_ADT_Devices_view.png

Profiling without Eclipse

You can also profile your application without Eclipse. Android command line tools are enough for this. All these commands are in tools folder in Android SDK.

Make sure your device is connected to your computer and your application is running and debuggable flag is set in AndroidManifest file..

The command to start profiling is:

adb shell am profile  start 

You can determine the PROCESS_ID either from the list within Eclipse or via the following command:

adb shell ps

TRACE_FILE is the file you want to store your trace results. Typically a file in the sdcard. For example:

adb shell am profile 5397 start /sdcard/my.app.trace

After started profiling, run your application for sometime. Then to stop profiling:

adb shell am profile  stop

Now the profiling is completed and results are stored in the file. To see the results you need to pull trace file from your device to your computer:

adb pull  

For example:

adb pull /sdcard/my.app.trace ./

The latest step is to open the Traceview application to see the results.

traceview 

Continuing our example:

traceview ./my.app.trace

That's it. Enjoy your results.

Inspecting results

Traceview application is pretty straightforward to use. So no need to go in to details here. Also have a look at traceview page

Troubleshooting

Unable to open trace file '...': Permission denied

This sometimes occurs, I don't know why. Add the following uses-permission element to your AndroidManifest.

    

Also see this post.

java.lang.SecurityException: Process not debuggable: ProcessRecord...

Make sure you have set debuggable flag in your AndroidManifest file.

    
       ...
    
My application is not listed in Devices view

Make sure you have set debuggable flag in your AndroidManifest file.

    
       ...
    
preference:
阅读(1200) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~