Android System Programming Tips and Tricks系统编程技巧(46P)

上传人:cn****1 文档编号:569544326 上传时间:2024-07-30 格式:PPT 页数:46 大小:927KB
返回 下载 相关 举报
Android System Programming Tips and Tricks系统编程技巧(46P)_第1页
第1页 / 共46页
Android System Programming Tips and Tricks系统编程技巧(46P)_第2页
第2页 / 共46页
Android System Programming Tips and Tricks系统编程技巧(46P)_第3页
第3页 / 共46页
Android System Programming Tips and Tricks系统编程技巧(46P)_第4页
第4页 / 共46页
Android System Programming Tips and Tricks系统编程技巧(46P)_第5页
第5页 / 共46页
点击查看更多>>
资源描述

《Android System Programming Tips and Tricks系统编程技巧(46P)》由会员分享,可在线阅读,更多相关《Android System Programming Tips and Tricks系统编程技巧(46P)(46页珍藏版)》请在金锄头文库上搜索。

1、4/11/11Android System ProgrammingTips and Tricks4/11/11OverviewIntro to AndroidWorking with SourceInteracting with the TargetDebug and Trace toolsPerformance toolsRandom thoughts on AndroidResources4/11/11Intro to AndroidGoogle runtime on top of LinuxObligatoryArchitecturediagram:4/11/11Android devi

2、ce proliferation4/11/11Working With Source4/11/11Working with SourceGitRepoBuild SystemBuilding fastAdding a program to the build4/11/11GitAndroid open source project uses gitYou need to learn to use git well, reallyNeed to know how to do a git rebase especially for kernel patchesgit rebase -iKernel

3、 patch rebase needed for moving kernel versions, porting work, etc.Lots of online resourcesRecommended online book: http:/progit.org/book/4/11/11RepoExport REPO_TRACE=1 is handy to see what git commands are happeningRepo tricksRepo forall -c git diff Repo forall -c echo $REPO_PATH;git remote -vUse t

4、o see upstream remotes from which to compare and merge with.Repo manifest -r -o my-tag-file.xmlMake a repository snapshot manifest4/11/11Build systemLots of interesting stuff in build/envsetup.shhelpchoosecombo/lunchjgrep/cgrepgodirInteresting make targets:showcommands psuedo-target to show build co

5、mmandssdk can build the SDK from scratch4/11/11Fast buildingParallel make threadsmake -j6Use 2 more than your number of CPUs (include hyperthreaded CPUs)Compiled output cacheccache is in /prebuilt areaexport USE_CCACHE=1Great for rebuilds (21 minutes on my desktop)Make only a specific modulemm build

6、 only the module(s) in the current directory (and below)I usually combine with a custom install script, which copies from out/target/product/4/11/11Adding a program to the buildMake a directory under externale.g. /external/myprogramCreate your C/cpp files.Create Android.mk as clone of external/ping/

7、Android.mkChange the names ping.c and ping to match your C/cpp files and program nameAdd the directory name in ANDROID/build/core/main.mk after external/zlib as external/myprogramMake from the root of the source tree4/11/11Interacting with the Target4/11/11Interacting with the TargetAndroid has some

8、 very nice integration engineeringTools discussedFastbootADBUseful development configurations4/11/11Fastboot“fastboot” is a both tool and a bootloader protocolRequired by Google for certified devicesWould be really nice to adopt as an industry standarde.g. maybe support fastboot in U-BootFastboot op

9、erationsInstall kernelInstall new flash imageBoot directly from hostVery useful for test automation4/11/11ADBAndroid Debug BridgeTool for all kinds of target interactions (install, logging, remote shell, file copy)shell push/pullLogcatInstall/uninstallPrint this and keep it under your pillow.http:/

10、(cont.)Can work over network, instead of USBUseful if you run build inside virtual machine on hoste.g. I build on Ubuntu 8.04 on Fedora 12 (64-bit) hostIts simple:export ADBHOST=192.168.2.1For some reason, I have to kill the server after rebooting targetadb kill-serverCalling adb will re-spawn the s

11、erver automatically4/11/11Development configurationsNetworkTargetHostHostUSBSerialPower controlNetworkTargetHostTFTPNFSKernelRoot filesystemTargetHostUSBNetworkkernelroot fsdataflashFunctionality testingTargetIntegration and Performance testing4/11/11Trace and Debug Tools4/11/11Trace and Debug tools

12、LoggingKernel log (dmesg)LogcatStdio redirectionStraceBootchartDumpsysDDMSgdb4/11/11Kernel logIts there, use dmesg to access after bootTurn on PRINTK_TIMES for timestampsIncrease buffer size: CONFIG_LOG_BUF_SHIFTCan emit messages into log by writing to /dev/kmsgVery handy to synchronize with kernel

13、messages4/11/11LogcatLogging system in kernelIntegrated throughout Android system (C+ and Java access)Increase logging levelsFlags to control logging level in code (DEBUG emits more?)Different logs (main, event, etc.)Event is funky, is coded for sizeSee jamboree presentation on log info http:/ (Pres

14、entation by Tetsuyuki Kobayashi)4/11/11LogcatUse from host to redirect to a fileTo get main log info, use:e.g. adb logcat v time d *:V test.logTo get info from events log, use -b:e.g. adb logcat b events v time d | grep bootFilter using :Can use ANDROID_LOG_TAGS environment variableI wrote my own lo

15、gdelta tool, to see time between eventsSee http:/elinux.org/Improving_Android_Boot_Time#logdelta4/11/11Logging system overview diagram* Shameless ripoff of Tetsuyuki Kobayashi4/11/11Logcat results (events)I/boot_progress_start( 754): 12559I/boot_progress_preload_start( 754): 17879I/boot_progress_pre

16、load_end( 754): 28546I/boot_progress_system_run( 768): 29230I/boot_progress_pms_start( 768): 29697I/boot_progress_pms_system_scan_start( 768): 30117I/boot_progress_pms_data_scan_start( 768): 44171I/boot_progress_pms_scan_end( 768): 50006I/boot_progress_pms_ready( 768): 50505I/boot_progress_ams_ready

17、( 768): 53166I/boot_progress_enable_screen( 768): 567934/11/11Stdio redirectionYou can send stdout and stderr to the log:logwrapper myprogramRedirecting Dalvik output:Redirecting C/cpp output:Myprogram | xargs logAssumes you have busybox xargs installed # stop # setprop log.redirect-stdio true # sta

18、rt4/11/11StraceShows system calls for a process (or set of processes)Is part of AOSP since EclairCan add to init.rc to trace initialization.For example, to trace zygote startup, in /init.rc change: toservice zygote /system/xbin/strace -tt -o/data/boot.strace /system/bin/app_process -Xzygote /system/

19、bin -zygote -start-system-serverservice zygote /system/bin/app_process -Xzygote /system/bin -zygote -start-system-server4/11/11Bootchartinit gathers data on startupMust re-compile init with support for bootchart data collectionA tool on the host produces a nice graphicSee http:/elinux.org/Bootchart

20、and http:/elinux.org/Using_Bootchart_on_Android4/11/11Bootchart output4/11/11Dumpstate/dumpsysDumps huge amounts of information about the system, including status, counts and statisticsDumpstate reproduces lots of stuff from /procDoes a dumpsys as wellDumpsys show status information from Androidserv

21、icese.g. dumpsys alarmFirst part of dump has list of services you can dump4/11/11DDMSDalvik Debug Monitor Servicehttp:/ of features, controllable via eclipseTo watch allocations in C/c+ code, try:Set “native=true” in /.android/ddms.cfgUse standalone ddms programOn target do: # setprop libc.debug.mal

22、loc 1 # stop # start4/11/11GDBHow to invoke:Note that gdbclient is a function in build/envsetup.shFiles are stripped in output dirUnstripped files are at;./out/target/product/generic/obj/EXECUTABLES/_intermediates/LINKED/1. adb forward tcp:5039 tcp:50392. adb shell gdbserver :5039 3. In another shel

23、l, gdbclient Or, manually: $ arm-eabi-gdb# file . /out/target/product/generic/symbols/system/bin/app_process# set solib-search-path ./out/target/product/generic/symbols/system/lib# target remote localhost:50394/11/11More debug tipsSee http:/omappedia.org/wiki/Android_DebuggingTons of tips, including

24、:How to debug a native program segfaultHow to use kernel profiler and oprofileHow to use gdb and DDDInfo is for Zoom2 board, but some things should work on your board also4/11/11Performance Tools4/11/11Performance ToolsSmemTraceview0xbenchPerf?4/11/11SmemTools for analyzing system-wide memory usageC

25、an slice, dice, and visualize memory info snapshotRun smemcap on target, grab data with adb, then analyze on hostSee http:/elinux.org/Using_smem_on_Android4/11/11TraceviewShows trace of Java methodsAlso shows profile informationUser can start and stop tracing either using DDMSApp can start and stop

26、tracing programmaticallyGoogle: “android traceview”4/11/110xbenchHas several built-in benchmarks, such as Linpack, Scimark2, and LibMicroProject page at: http:/ available in Android MarketSome tests require root privileges4/11/11PerfStandard kernel tool for performance analysisNow that Android is on

27、 more recent kernels, it should work out of the boxHave to admit that I havent done it yetAnyone here used it?4/11/11Miscellaneous toolsprocranksetprop/getpropsqlite (command line)start/stopCan stop/start whole system4/11/11ProcrankShows a quick summary of processes, sorted by VSS, RSS, PSS or USSSe

28、e http:/elinux.org/Android_Memory_UsageOutput:# procrank PID Vss Rss Pss Uss cmdline 1217 36848K 35648K 17983K 13956K system_server 1276 32200K 32200K 14048K 10116K android.process.acore 1189 26920K 26920K 9293K 5500K zygote 1321 20328K 20328K 4743K 2344K android.process.media 1356 20360K 20360K 462

29、1K 2148K com.android.email 1303 20184K 20184K 4381K 1724K com.android.settings 1271 19888K 19888K 4297K 1764K com.android.inputmethod.latin 1332 19560K 19560K 3993K 1620K com.android.alarmclock 1187 5068K 5068K 2119K 1476K /system/bin/mediaserver 1384 436K 436K 248K 236K procrank 1 212K 212K 200K 20

30、0K /init 753 572K 572K 171K 136K /system/bin/rild 748 340K 340K 163K 152K /system/bin/sh 751 388K 388K 156K 140K /system/bin/vold 1215 148K 148K 136K 136K /sbin/adbd 757 352K 352K 117K 92K /system/bin/dbus-daemon 760 404K 404K 104K 80K /system/bin/keystore 759 312K 312K 102K 88K /system/bin/installd

31、 749 288K 288K 96K 84K /system/bin/servicemanager 752 244K 244K 71K 60K /system/bin/debuggerd4/11/11setprop/getpropMany services have debug elements controlled by propertiesMany properties are set in /init.rcYou can also query and set properties on the command lineUse getprop (with no args) to see l

32、ist of propertiesHave to examine source for properties with special effects (or see some tip on a mailing list)Example: setting the DNS server address manually:setprop net.nds1 xx.yy.zz.aa4/11/11SqliteYou can inspect and modify sqlite data directly from the command line (or over adb)Heres an example

33、 of setting the http_proxy for a development boardMost databases are under a directory called databases, and end in .db# cd /data/data/com.android.providers.settings/databases# sqlite3 settings.dbSQLite version 3.5.9Enter .help for instructionssqlite insert into system values(99,http_proxy,192.168.1

34、.1:80);sqlite.exit#4/11/11Wrapup4/11/11Random thoughts on AndroidThrows POSIX out the windowThis is refreshingHas some downsides, but most things are OKCan finally jettison some legacy baggageSeems destined to be a major embedded Linux platformOnly drawback(?) is non-native appsBut even this has pro

35、s and consWould like to see consolidationYou can use an Android kernel for “regular” embedded Linux work4/11/11ResourceseLinux wiki Android portal:http:/elinux.org/Android_PortalUse android-porting, android-platform, and android-kernel mailing lists, depending on where your issue isSee http:/elinux.org/Android_Web_Resources#Mailing_ListsMy e-mail: tim.bird (at) 4/11/11Thanks for your timeQuestions and Answers

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号