1、打印某个进程中所有线程的backtrace
adb shell debuggerd -b pid
C:\Users\hxiong>adb root
C:\Users\hxiong>adb shell
generic_x86_64:/ # ps | grep cameraserver
cameraserver 1293 1 21368 5700 binder_thr 00ffffe430 S /system/bin/camera
server
generic_x86_64:/ # debuggerd -b 1293
Sending request to dump task 1293.
----- pid 1293 at 2017-06-17 08:00:15 -----
Cmd line: /system/bin/cameraserver
ABI: 'x86'
"cameraserver" sysTid=1293
#00 pc ffffe430 [vdso:ffffe000] (__kernel_vsyscall+16)
#01 pc 0008a07c /system/lib/libc.so (__ioctl+28)
#02 pc 000251f1 /system/lib/libc.so (ioctl+42)
#03 pc 000477e7 /system/lib/libbinder.so (_ZN7android14IPCThreadState14talkWithDriverEb+343)
#04 pc 0004799a /system/lib/libbinder.so (_ZN7android14IPCThreadState20getAndExecuteCommandEv+42)
#05 pc 0004826f /system/lib/libbinder.so (_ZN7android14IPCThreadState14joinThreadPoolEb+95)
#06 pc 00000950 /system/bin/cameraserver
#07 pc 00016bd6 /system/lib/libc.so (__libc_init+100)
#08 pc 000007c2 /system/bin/cameraserver
"EmulatedCameraH" sysTid=1310
#00 pc ffffe430 [vdso:ffffe000] (__kernel_vsyscall+16)
#01 pc 0008b9ac /system/lib/libc.so (read+28)
#02 pc 00099880 /system/lib/libc.so (__read_chk+74)
#03 pc 00019bb1 /system/lib/hw/camera.ranchu.so (_ZN7android27EmulatedCameraHotplugThread10threadLoopEv+625)
#04 pc 00012095 /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+309)
#05 pc 00011883 /system/lib/libutils.so (_ZN13thread_data_t10trampolineEPKS_+259)
#06 pc 00086cdf /system/lib/libc.so (_ZL15__pthread_startPv+190)
#07 pc 00022f00 /system/lib/libc.so (__start_thread+25)
#08 pc 00020766 /system/lib/libc.so (__bionic_clone+70)
"Binder:1293_1" sysTid=1576
#00 pc ffffe430 [vdso:ffffe000] (__kernel_vsyscall+16)
#01 pc 0008a07c /system/lib/libc.so (__ioctl+28)
#02 pc 000251f1 /system/lib/libc.so (ioctl+42)
#03 pc 000477e7 /system/lib/libbinder.so (_ZN7android14IPCThreadState14talkWithDriverEb+343)
#04 pc 0004799a /system/lib/libbinder.so (_ZN7android14IPCThreadState20getAndExecuteCommandEv+42)
#05 pc 0004826f /system/lib/libbinder.so (_ZN7android14IPCThreadState14joinThreadPoolEb+95)
#06 pc 0006edbe /system/lib/libbinder.so (_ZN7android10PoolThread10threadLoopEv+46)
#07 pc 00012095 /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+309)
#08 pc 00011883 /system/lib/libutils.so (_ZN13thread_data_t10trampolineEPKS_+259)
#09 pc 00086cdf /system/lib/libc.so (_ZL15__pthread_startPv+190)
#10 pc 00022f00 /system/lib/libc.so (__start_thread+25)
#11 pc 00020766 /system/lib/libc.so (__bionic_clone+70)
"Binder:1293_2" sysTid=2168
#00 pc ffffe430 [vdso:ffffe000] (__kernel_vsyscall+16)
#01 pc 0008a07c /system/lib/libc.so (__ioctl+28)
#02 pc 000251f1 /system/lib/libc.so (ioctl+42)
#03 pc 000477e7 /system/lib/libbinder.so (_ZN7android14IPCThreadState14talkWithDriverEb+343)
#04 pc 0004799a /system/lib/libbinder.so (_ZN7android14IPCThreadState20getAndExecuteCommandEv+42)
#05 pc 0004826f /system/lib/libbinder.so (_ZN7android14IPCThreadState14joinThreadPoolEb+95)
#06 pc 0006edbe /system/lib/libbinder.so (_ZN7android10PoolThread10threadLoopEv+46)
#07 pc 00012095 /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+309)
#08 pc 00011883 /system/lib/libutils.so (_ZN13thread_data_t10trampolineEPKS_+259)
#09 pc 00086cdf /system/lib/libc.so (_ZL15__pthread_startPv+190)
#10 pc 00022f00 /system/lib/libc.so (__start_thread+25)
#11 pc 00020766 /system/lib/libc.so (__bionic_clone+70)
----- end 1293 -----
generic_x86_64:/ #
这个命令(工具)很有用,比如出现死锁的时候,通过打印线程的信息大概可以分析出来,比如有两个线程都在等同一把锁。
2、打印系统所有注册的服务
adb shell service listC:\Users\hxiong>adb shell service list
Found 117 services:
0 carrier_config: [com.android.internal.telephony.ICarrierConfigLoader]
1 phone: [com.android.internal.telephony.ITelephony]
2 isms: [com.android.internal.telephony.ISms]
3 iphonesubinfo: [com.android.internal.telephony.IPhoneSubInfo]
4 simphonebook: [com.android.internal.telephony.IIccPhoneBook]
5 isub: [com.android.internal.telephony.ISub]
6 telecom: [com.android.internal.telecom.ITelecomService]
7 contexthub_service: [android.hardware.location.IContextHubService]
8 dns_listener: [android.net.metrics.IDnsEventListener]
9 connmetrics: [android.net.IIpConnectivityMetrics]
10 connectivity_metrics_logger: [android.net.IConnectivityMetricsLogger]
11 imms: [com.android.internal.telephony.IMms]
12 media_projection: [android.media.projection.IMediaProjectionManager]
13 launcherapps: [android.content.pm.ILauncherApps]
14 shortcut: [android.content.pm.IShortcutService]
15 fingerprint: [android.hardware.fingerprint.IFingerprintService]
16 trust: [android.app.trust.ITrustManager]
17 media_router: [android.media.IMediaRouterService]
18 media_session: [android.media.session.ISessionManager]
19 restrictions: [android.content.IRestrictionsManager]
20 print: [android.print.IPrintManager]
21 graphicsstats: [android.view.IGraphicsStats]
22 assetatlas: [android.view.IAssetAtlas]
23 dreams: [android.service.dreams.IDreamManager]
24 commontime_management: []
25 network_time_update_service: []
26 samplingprofiler: []
27 diskstats: []
28 voiceinteraction: [com.android.internal.app.IVoiceInteractionManagerServ
ice]
29 appwidget: [com.android.internal.appwidget.IAppWidgetService]
30 backup: [android.app.backup.IBackupManager]
31 soundtrigger: [com.android.internal.app.ISoundTriggerService]
32 jobscheduler: [android.app.job.IJobScheduler]
33 hardware_properties: [android.os.IHardwarePropertiesManager]
34 serial: [android.hardware.ISerialManager]
35 usb: [android.hardware.usb.IUsbManager]
36 midi: [android.media.midi.IMidiManager]
37 DockObserver: []
38 audio: [android.media.IAudioService]
39 wallpaper: [android.app.IWallpaperManager]
40 dropbox: [com.android.internal.os.IDropBoxManagerService]
41 search: [android.app.ISearchManager]
42 country_detector: [android.location.ICountryDetector]
43 location: [android.location.ILocationManager]
44 devicestoragemonitor: []
45 notification: [android.app.INotificationManager]
46 recovery: [android.os.IRecoverySystem]
47 updatelock: [android.os.IUpdateLock]
48 servicediscovery: [android.net.nsd.INsdManager]
49 connectivity: [android.net.IConnectivityManager]
50 rttmanager: [android.net.wifi.IRttManager]
51 wifiscanner: [android.net.wifi.IWifiScanner]
52 wifi: [android.net.wifi.IWifiManager]
53 wifip2p: [android.net.wifi.p2p.IWifiP2pManager]
54 netpolicy: [android.net.INetworkPolicyManager]
55 netstats: [android.net.INetworkStatsService]
56 network_score: [android.net.INetworkScoreService]
57 textservices: [com.android.internal.textservice.ITextServicesManager]
58 network_management: [android.os.INetworkManagementService]
59 clipboard: [android.content.IClipboard]
60 statusbar: [com.android.internal.statusbar.IStatusBarService]
61 device_policy: [android.app.admin.IDevicePolicyManager]
62 deviceidle: [android.os.IDeviceIdleController]
63 lock_settings: [com.android.internal.widget.ILockSettings]
64 uimode: [android.app.IUiModeManager]
65 mount: [IMountService]
66 accessibility: [android.view.accessibility.IAccessibilityManager]
67 input_method: [com.android.internal.view.IInputMethodManager]
68 pinner: []
69 vrmanager: [android.service.vr.IVrManager]
70 input: [android.hardware.input.IInputManager]
71 window: [android.view.IWindowManager]
72 alarm: [android.app.IAlarmManager]
73 consumer_ir: [android.hardware.IConsumerIrService]
74 vibrator: [android.os.IVibratorService]
75 content: [android.content.IContentService]
76 account: [android.accounts.IAccountManager]
77 media.camera.proxy: [android.hardware.ICameraServiceProxy]
78 telephony.registry: [com.android.internal.telephony.ITelephonyRegistry]
79 scheduling_policy: [android.os.ISchedulingPolicyService]
80 webviewupdate: [android.webkit.IWebViewUpdateService]
81 usagestats: [android.app.usage.IUsageStatsManager]
82 battery: []
83 sensorservice: [android.gui.SensorServer]
84 processinfo: [android.os.IProcessInfoService]
85 permission: [android.os.IPermissionController]
86 cpuinfo: []
87 dbinfo: []
88 gfxinfo: []
89 meminfo: []
90 procstats: [com.android.internal.app.procstats.IProcessStats]
91 activity: [android.app.IActivityManager]
92 user: [android.os.IUserManager]
93 otadexopt: [android.content.pm.IOtaDexopt]
94 package: [android.content.pm.IPackageManager]
95 display: [android.hardware.display.IDisplayManager]
96 power: [android.os.IPowerManager]
97 appops: [com.android.internal.app.IAppOpsService]
98 batterystats: [com.android.internal.app.IBatteryStats]
99 media.camera: [android.hardware.ICameraService]
100 netd: [android.net.INetd]
101 gpu: [android.ui.IGpuService]
102 SurfaceFlinger: [android.ui.ISurfaceComposer]
103 android.security.keystore: [android.security.IKeystoreService]
104 android.service.gatekeeper.IGateKeeperService: [android.service.gatekeep
er.IGateKeeperService]
105 drm.drmManager: [drm.IDrmManagerService]
106 android.hardware.fingerprint.IFingerprintDaemon: [android.hardware.finge
rprint.IFingerprintDaemon]
107 media.sound_trigger_hw: [android.hardware.ISoundTriggerHwService]
108 media.radio: [android.hardware.IRadioService]
109 media.audio_policy: [android.media.IAudioPolicyService]
110 media.resource_manager: [android.media.IResourceManagerService]
111 media.player: [android.media.IMediaPlayerService]
112 media.drm: [android.media.IMediaDrmService]
113 media.codec: [android.media.IMediaCodecService]
114 media.extractor: [android.media.IMediaExtractorService]
115 media.audio_flinger: [android.media.IAudioFlinger]
116 batteryproperties: [android.os.IBatteryPropertiesRegistrar]
C:\Users\hxiong>这个信息可以让你知道某个service是否已经成功注册,我在公司就是负责某个service (公司开发的,不是安卓原生有的)开发维护工作,有发现过service注册不成功的情况,比如在ota升级后会有概率出现,打印这个信息可以确认service是否成功注册,如果没有,再查servicemanager进程是否有异常。
3、查看某个应用是32位还是64位
adb shell ps --abi
C:\Users\hxiong>adb root
C:\Users\hxiong>adb shell ps --abi
USER PID PPID VSIZE RSS WCHAN PC ABI NAME
root 1 0 10448 1668 ep_poll 00004fcc4a S 64 /init
root 2 0 0 0 kthreadd 0000000000 S kthreadd
root 3 2 0 0 smpboot_th 0000000000 S ksoftirqd/0
root 5 2 0 0 worker_thr 0000000000 S kworker/0:0H
root 6 2 0 0 worker_thr 0000000000 S kworker/u8:0
root 7 2 0 0 smpboot_th 0000000000 S migration/0
root 8 2 0 0 rcu_gp_kth 0000000000 S rcu_preempt
root 9 2 0 0 rcu_gp_kth 0000000000 S rcu_bh
root 10 2 0 0 rcu_gp_kth 0000000000 S rcu_sched
root 11 2 0 0 smpboot_th 0000000000 S migration/1
root 12 2 0 0 smpboot_th 0000000000 S ksoftirqd/1
root 13 2 0 0 worker_thr 0000000000 S kworker/1:0
root 14 2 0 0 worker_thr 0000000000 S kworker/1:0H
root 15 2 0 0 smpboot_th 0000000000 S migration/2
root 16 2 0 0 smpboot_th 0000000000 S ksoftirqd/2
root 17 2 0 0 worker_thr 0000000000 S kworker/2:0
root 18 2 0 0 worker_thr 0000000000 S kworker/2:0H
root 19 2 0 0 smpboot_th 0000000000 S migration/3
root 20 2 0 0 smpboot_th 0000000000 S ksoftirqd/3
root 21 2 0 0 worker_thr 0000000000 S kworker/3:0
root 22 2 0 0 worker_thr 0000000000 S kworker/3:0H
root 23 2 0 0 rescuer_th 0000000000 S khelper
root 24 2 0 0 worker_thr 0000000000 S kworker/u8:1
root 327 2 0 0 rescuer_th 0000000000 S writeback
root 329 2 0 0 rescuer_th 0000000000 S bioset
root 331 2 0 0 rescuer_th 0000000000 S kblockd
root 416 2 0 0 rescuer_th 0000000000 S ata_sff
root 427 2 0 0 hub_thread 0000000000 S khubd
root 436 2 0 0 rescuer_th 0000000000 S md
root 445 2 0 0 worker_thr 0000000000 S kworker/0:1
root 446 2 0 0 rescuer_th 0000000000 S cfg80211
root 558 2 0 0 kswapd 0000000000 S kswapd0
root 625 2 0 0 fsnotify_m 0000000000 S fsnotify_mark
root 647 2 0 0 rescuer_th 0000000000 S crypto
root 667 2 0 0 worker_thr 0000000000 S kworker/1:1
root 668 2 0 0 worker_thr 0000000000 S kworker/2:1
root 669 2 0 0 worker_thr 0000000000 S kworker/3:1
root 774 2 0 0 rescuer_th 0000000000 S iscsi_eh
root 788 2 0 0 scsi_error 0000000000 S scsi_eh_0
root 791 2 0 0 scsi_error 0000000000 S scsi_eh_1
root 826 2 0 0 rescuer_th 0000000000 S uether
root 845 2 0 0 rescuer_th 0000000000 S dm_bufio_cache
root 876 2 0 0 rescuer_th 0000000000 S binder
root 895 2 0 0 rescuer_th 0000000000 S deferwq
root 902 2 0 0 worker_thr 0000000000 S kworker/0:1H
root 907 2 0 0 worker_thr 0000000000 S kworker/0:2
root 911 1 6168 1088 poll_sched 00004fcc8a S 64 /sbin/ueventd
root 1215 2 0 0 kjournald2 0000000000 S jbd2/vda-8
root 1217 2 0 0 rescuer_th 0000000000 S ext4-rsv-conver
root 1219 2 0 0 kjournald2 0000000000 S jbd2/vdb-8
root 1220 2 0 0 rescuer_th 0000000000 S ext4-rsv-conver
root 1224 2 0 0 kjournald2 0000000000 S jbd2/vdc-8
root 1225 2 0 0 rescuer_th 0000000000 S ext4-rsv-conver
logd 1226 1 17388 3168 sigsuspend 7e7268b51907 S 64 /system/bin/logd
root 1227 1 7144 1696 __skb_recv 00ffffe430 S 32 /system/bin/debuggerd
root 1228 1 10828 2160 __skb_recv 707dcc2c862a S 64 /system/bin/debuggerd64
root 1229 1 18936 3916 hrtimer_na 77fd804bd3e7 S 64 /system/bin/vold
root 1230 2 0 0 worker_thr 0000000000 S kworker/2:1H
root 1236 2 0 0 kauditd_th 0000000000 S kauditd
root 1237 1228 10444 580 __skb_recv 707dcc2c9547 S 64 debuggerd64:signaller
root 1240 1227 6888 452 __skb_recv 00ffffe430 S 32 debuggerd:signaller
root 1276 2 0 0 worker_thr 0000000000 S kworker/3:1H
root 1278 1 6500 432 ep_poll 000048db0a S 64 /sbin/healthd
root 1280 1 9320 2056 ep_poll 7e0e7c1a56aa S 64 /system/bin/lmkd
system 1281 1 9912 2028 binder_thr 7c6030e1f7e7 S 64 /system/bin/servicemanager
system 1282 1 70748 5068 ep_poll 7a383830c6aa S 64 /system/bin/surfaceflinger
shell 1285 1 8304 1720 n_tty_read 71b841775547 S 64 /system/bin/sh
root 1290 1 1466344 80624 poll_sched 74032f18182a S 64 zygote64
root 1291 1 1450376 69044 poll_sched 00ffffe430 S 32 zygote
audioserver 1292 1 37428 6232 binder_thr 00ffffe430 S 32 /system/bin/audioserver
cameraserver 1293 1 21368 5788 binder_thr 00ffffe430 S 32 /system/bin/cameraserver
drm 1294 1 17732 4324 binder_thr 00ffffe430 S 32 /system/bin/drmserver
root 1295 1 10468 2492 unix_strea 7750bfd5e547 S 64 /system/bin/installd
keystore 1296 1 13440 3376 binder_thr 7d457b8057e7 S 64 /system/bin/keystore
mediacodec 1297 1 24808 6056 binder_thr 00ffffe430 S 32 media.codec
media 1298 1 22996 5964 binder_thr 00ffffe430 S 32 /system/bin/mediadrmserver
mediaex 1299 1 45956 6752 binder_thr 00ffffe430 S 32 media.extractor
media 1300 1 48972 7664 binder_thr 00ffffe430 S 32 /system/bin/mediaserver
root 1301 1 26508 3592 binder_thr 7119e02d87e7 S 64 /system/bin/netd
radio 1302 1 16524 2320 hrtimer_na 7ab02ea8b3e7 S 64 /system/bin/rild
system 1303 1 14280 3204 binder_thr 76dd22fe77e7 S 64 /system/bin/fingerprintd
system 1304 1 13120 3112 binder_thr 7c57e3c337e7 S 64 /system/bin/gatekeeperd
root 1321 1 8888 1748 hrtimer_na 76c6435a43e7 S 64 /system/xbin/perfprofd
root 1544 2 0 0 worker_thr 0000000000 S kworker/1:1H
system 1587 1290 1635052 119624 ep_poll 74032f1816aa S 64 system_server
u0_a43 1675 1290 1552760 53456 ep_poll 74032f1816aa S 64 com.android.inputmethod.latin
u0_a21 1681 1290 1637972 114748 ep_poll 74032f1816aa S 64 com.android.systemui
media_rw 1708 1229 14492 2472 inotify_re 7b59feb1b547 S 64 /system/bin/sdcard
media_rw 1761 1229 14492 2476 inotify_re 7d32d2c38547 S 64 /system/bin/sdcard
radio 1789 1290 1559692 58256 ep_poll 74032f1816aa S 64 com.android.phone
system 1803 1290 1572448 51096 ep_poll 74032f1816aa S 64 com.android.settings
u0_a33 1957 1290 1547172 46384 ep_poll 74032f1816aa S 64 com.android.deskclock
u0_a10 1995 1290 1538340 40416 ep_poll 74032f1816aa S 64 android.ext.services
u0_a47 2018 1290 1845312 84700 ep_poll 74032f1816aa S 64 com.google.android.apps.maps
u0_a22 2049 1291 1612784 43680 ep_poll 00ffffe430 S 32 com.google.android.googlequicksearchbox:interactor
u0_a58 2068 1290 1540276 42276 ep_poll 74032f1816aa S 64 com.android.printspooler
u0_a14 2091 1290 1581544 72808 ep_poll 74032f1816aa S 64 com.google.android.apps.nexuslauncher
u0_a12 2146 1290 1748984 97160 ep_poll 74032f1816aa S 64 com.google.android.gms.persistent
u0_a1 2184 1290 1546404 51948 ep_poll 74032f1816aa S 64 android.process.acore
u0_a22 2213 1291 1667860 104184 ep_poll 00ffffe430 S 32 com.google.android.googlequicksearchbox:search
u0_a12 2300 1290 1546296 48408 ep_poll 74032f1816aa S 64 com.google.process.gapps
u0_a27 2319 1290 1546448 44872 ep_poll 74032f1816aa S 64 com.android.calendar
u0_a36 2342 1290 1556232 49680 ep_poll 74032f1816aa S 64 com.android.email
u0_a2 2358 1290 1541464 45616 ep_poll 74032f1816aa S 64 com.android.providers.calendar
u0_a13 2384 1290 1539260 40484 ep_poll 74032f1816aa S 64 com.android.managedprovisioning
u0_a12 2459 1290 1707428 58224 ep_poll 74032f1816aa S 64 com.google.android.gms.feedback
u0_a12 2493 1290 1861464 96524 ep_poll 74032f1816aa S 64 com.google.android.gms
u0_a56 2529 1291 1560060 50072 ep_poll 00ffffe430 S 32 com.google.android.apps.messaging
u0_a60 2568 1290 1545932 42864 ep_poll 74032f1816aa S 64 com.google.android.apps.wallpaper
u0_a30 2613 1291 1553044 42536 ep_poll 00ffffe430 S 32 com.android.chrome
u0_a41 2635 1290 1546860 43792 ep_poll 74032f1816aa S 64 com.google.process.gapps
root 2965 1 16576 760 poll_sched 00004cc40a S 64 /sbin/adbd
root 3497 2965 9868 1784 0 72cab7b5d547 R 64 ps
C:\Users\hxiong>或者通过 grep 来过滤
C:\Users\hxiong>adb shell
generic_x86_64:/ # ps | grep cameraserver
cameraserver 1293 1 21368 5788 binder_thr 00ffffe430 S /system/bin/cameraserver
generic_x86_64:/ # ps --abi | grep cameraserver
cameraserver 1293 1 21368 5788 binder_thr 00ffffe430 S 32 /system/bin/cameraserver
generic_x86_64:/ #之所以要了解这个信息,是因为buffer 从32位进程传给64位进程的时候,读取或处理buffer的时候可能会有问题。
本文介绍了三个实用的Android调试命令,包括使用debuggerd获取进程线程backtrace以分析死锁,检查系统服务注册状态确保服务正常运行,以及通过ps命令查看应用的架构信息。这些命令对于Android开发者进行问题排查和性能优化极具帮助。
887

被折叠的 条评论
为什么被折叠?



