分类: 嵌入式
2011-04-06 18:46:31
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.
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.
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 profilestart
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 profilestop
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.
Traceview application is pretty straightforward to use. So no need to go in to details here. Also have a look at traceview page
This sometimes occurs, I don't know why. Add the following uses-permission element to your AndroidManifest.
Also see this post.
Make sure you have set debuggable flag in your AndroidManifest file.
...
Make sure you have set debuggable flag in your AndroidManifest file.
...
preference: