安卓apk闪退问题排查记录
- logcat
- 程序包名
- 先看日志(以下日志是多次闪退记录的系统日志,挑拣几次有代表性的发上来)
- 最近一次闪退
- adb shell top
- help
- 一个demo
- 说明
- adb shell dumpsys meminfo <package_name>
ps:写在前面,这里只是记录一些方法,如果您有不同于这里的方法,希望能留言,给我指明方向!
以下的这些方法能够查到一些端倪,但是没办法定位到问题的位置,所以到写这个记录的时候还没有解决闪退问题。
logcat
导出日志到文件
adb logcat -v time >d:\b10.txt
程序包名
com.BOSHIAC.agvapp
先看日志(以下日志是多次闪退记录的系统日志,挑拣几次有代表性的发上来)
最近一次闪退
03-30 23:50:48.597 E/KernelCpuSpeedReader( 1532): Failed to read cpu-freq: /sys/devices/system/cpu/cpu6/cpufreq/stats/time_in_state: open failed: ENOENT (No such file or directory)
03-30 23:50:48.598 E/KernelCpuSpeedReader( 1532): Failed to read cpu-freq: /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state: open failed: ENOENT (No such file or directory)
03-31 00:00:00.015 D/DevicePolicyManager( 1532): updateSystemUpdateFreezePeriodsRecord
03-31 00:00:00.043 W/BroadcastQueue( 1532): Background execution not allowed: receiving Intent { act=android.intent.action.DATE_CHANGED flg=0x20200010 } to com.android.calendar/.widget.CalendarAppWidgetService$CalendarFactory
03-31 00:00:00.064 W/BroadcastQueue( 1532): Background execution not allowed: receiving Intent { act=android.intent.action.DATE_CHANGED flg=0x20200010 } to com.android.inputmethod.latin/com.android.inputmethod.dictionarypack.EventHandler
03-31 00:01:27.393 I/UsageStatsService( 1532): User[0] Flushing usage stats to disk
03-31 00:05:54.776 E/TLOC ( 1387): [TLOCChannel]"Can't receive message due to timeout"
03-31 00:05:54.778 I/TLOC ( 1387): [ModemComm ]"Request succeeded for gps engine lock"
03-31 00:05:54.778 D/TLOC ( 1387): [TLOCChannel] "Going to receive message for TLOCD"
03-31 00:05:54.778 D/TLOC ( 1387): [TLOCChannel] "wait for message for user TLOCD"
03-31 00:05:55.777 E/TLOC ( 1387): [TLOCChannel]"Can't receive message due to timeout"
03-31 00:05:55.777 E/TLOC ( 1387): [TLOCDaemon ]"Couldn't receive command response"
03-31 00:05:55.777 I/TLOC ( 1387): [TLOCDaemon ]"timeout passed - start periodic warm-up"
03-31 00:05:55.779 I/TLOC ( 1387): [ModemComm ]"Start a session successfully"
03-31 00:05:55.779 D/TLOC ( 1387): [TLOCDaemon ]"The command finished successfully"
03-31 00:05:55.779 D/TLOC ( 1387): [TLOCDaemon ]"waiting for command"
03-31 00:05:55.779 D/TLOC ( 1387): [TLOCChannel] "Going to receive message for TLOCD"
03-31 00:05:55.779 D/TLOC ( 1387): [TLOCChannel] "wait for message for user TLOCD"
03-31 00:06:15.779 E/TLOC ( 1387): [TLOCChannel]"Can't receive message due to timeout"
03-31 00:06:15.780 I/TLOC ( 1387): [TLOCDaemon ]"timeout passed with no location fix - close the session"
03-31 00:06:15.781 I/TLOC ( 1387): [ModemComm ]"Stopped the session successfully"
03-31 00:06:15.781 I/TLOC ( 1387): [Modem ]"Received event indication of position report with status USER_END"
03-31 00:06:15.781 D/TLOC ( 1387): [TLOCDaemon ]"The command finished successfully"
03-31 00:06:15.781 D/TLOC ( 1387): [TLOCDaemon ]"waiting for command"
03-31 00:06:15.781 D/TLOC ( 1387): [TLOCChannel] "Going to receive message for TLOCD"
03-31 00:06:15.781 D/TLOC ( 1387): [TLOCChannel] "wait for message for user TLOCD"
--------- beginning of crash
03-31 00:14:01.638 F/libc ( 7911): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xb4000071254bbd in tid 8132 (Thread Pool Wor), pid 7911 (.BOSHIAC.agvapp)
03-31 00:14:01.707 F/DEBUG ( 1487): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
03-31 00:14:01.707 F/DEBUG ( 1487): Build fingerprint: 'Q115M/Q115M/Q115M:11/RKQ1.210907.001/eng.shubin.20220516.215652:user/test-keys'
03-31 00:14:01.707 F/DEBUG ( 1487): Revision: '0'
03-31 00:14:01.707 F/DEBUG ( 1487): ABI: 'arm64'
03-31 00:14:01.707 F/DEBUG ( 1487): Timestamp: 2023-03-31 00:14:01+0800
03-31 00:14:01.707 F/DEBUG ( 1487): pid: 7911, tid: 8132, name: Thread Pool Wor >>> com.BOSHIAC.agvapp <<<
03-31 00:14:01.707 F/DEBUG ( 1487): uid: 10195
03-31 00:14:01.707 F/DEBUG ( 1487): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xb4000071254bbd
03-31 00:14:01.707 F/DEBUG ( 1487): x0 0000000000000012 x1 0000006f305df608 x2 0000000000000012 x3 0000006f30002020
03-31 00:14:01.707 F/DEBUG ( 1487): x4 0000000000000010 x5 0000000000000010 x6 fefeff6e2eff1f1f x7 7f7f7f7f7f7f7f7f
03-31 00:14:01.707 F/DEBUG ( 1487): x8 0000000000000000 x9 ed762b6d22163358 x10 0000000000000002 x11 0000000000000001
03-31 00:14:01.707 F/DEBUG ( 1487): x12 0000007297d3a2c3 x13 0000000000000000 x14 0000007297dd1d22 x15 0000000034155555
03-31 00:14:01.707 F/DEBUG ( 1487): x16 0000006f3a80da30 x17 0000007297db1050 x18 0000000000000032 x19 0000000000000000
03-31 00:14:01.707 F/DEBUG ( 1487): x20 0000000000000000 x21 0000000000000040 x22 0000006f3a7e6648 x23 0000006f3a746545
03-31 00:14:01.707 F/DEBUG ( 1487): x24 0000006f3a762d57 x25 000000000000002e x26 0000006f3a760d21 x27 0000006f3a746543
03-31 00:14:01.707 F/DEBUG ( 1487): x28 00b4000071254bbd x29 0000006f305dfa90
03-31 00:14:01.707 F/DEBUG ( 1487): lr 0000006f3a714684 sp 0000006f305dfa30 pc 0000006f3a714694 pst 0000000080001000
03-31 00:14:01.708 F/DEBUG ( 1487): backtrace:
03-31 00:14:01.708 F/DEBUG ( 1487): #00 pc 0000000000271694 /data/app/~~hRM_rd0iTvyiC9SQ4ywSVQ==/com.BOSHIAC.agvapp-o8RFjgJvaNeXA2aE_x2hHw==/lib/arm64/libmonosgen-2.0.so (mono_dump_mem+144)
03-31 00:14:03.032 W/ActivityTaskManager( 1532): Force finishing activity com.BOSHIAC.agvapp/crc64e731f8ab2063fb12.MainActivity
03-31 00:14:03.032 I/DropBoxManagerService( 1532): add tag=data_app_native_crash isTagEnabled=true flags=0x2
03-31 00:14:03.038 I/BootReceiver( 1532): Copying /data/tombstones/tombstone_08 to DropBox (SYSTEM_TOMBSTONE)
03-31 00:14:03.041 I/DropBoxManagerService( 1532): add tag=SYSTEM_TOMBSTONE isTagEnabled=true flags=0x2
03-31 00:14:03.124 I/ActivityManager( 1532): Process com.BOSHIAC.agvapp (pid 7911) has died: fg TOP
03-31 00:14:03.124 I/WindowManager( 1532): WIN DEATH: Window{672110d u0 com.BOSHIAC.agvapp/crc64e731f8ab2063fb12.MainActivity}
03-31 00:14:03.147 W/ActivityManager( 1532): setHasOverlayUi called on unknown pid: 7911
03-31 00:14:06.186 E/TaskPersister( 1532): File error accessing recents directory (directory doesn't exist?).
03-31 00:20:48.575 E/KernelCpuSpeedReader( 1532): Failed to read cpu-freq: /sys/devices/system/cpu/cpu6/cpufreq/stats/time_in_state: open failed: ENOENT (No such file or directory)
03-31 00:20:48.575 E/KernelCpuSpeedReader( 1532): Failed to read cpu-freq: /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state: open failed: ENOENT (No such file or directory)
03-31 00:21:06.262 W/EntropyMixer( 1532): Failed to add HW RNG output to entropy pool
03-31 00:21:06.262 W/EntropyMixer( 1532): java.io.FileNotFoundException: /dev/hw_random: open failed: EACCES (Permission denied)
03-31 00:21:06.262 W/EntropyMixer( 1532): at libcore.io.IoBridge.open(IoBridge.java:492)
03-31 00:21:06.262 W/EntropyMixer( 1532): at java.io.FileInputStream.<init>(FileInputStream.java:160)
03-31 00:21:06.262 W/EntropyMixer( 1532): at java.io.FileInputStream.<init>(FileInputStream.java:115)
03-31 00:21:06.262 W/EntropyMixer( 1532): at com.android.server.RandomBlock.fromFile(RandomBlock.java:45)
03-31 00:21:06.262 W/EntropyMixer( 1532): at com.android.server.EntropyMixer.addHwRandomEntropy(EntropyMixer.java:205)
03-31 00:21:06.262 W/EntropyMixer( 1532): at com.android.server.EntropyMixer.access$000(EntropyMixer.java:59)
03-31 00:21:06.262 W/EntropyMixer( 1532): at com.android.server.EntropyMixer$1.handleMessage(EntropyMixer.java:83)
03-31 00:21:06.262 W/EntropyMixer( 1532): at android.os.Handler.dispatchMessage(Handler.java:106)
03-31 00:21:06.262 W/EntropyMixer( 1532): at android.os.Looper.loop(Looper.java:223)
03-31 00:21:06.262 W/EntropyMixer( 1532): at android.os.HandlerThread.run(HandlerThread.java:67)
03-31 00:21:06.262 W/EntropyMixer( 1532): at com.android.server.ServiceThread.run(ServiceThread.java:44)
03-31 00:21:06.262 W/EntropyMixer( 1532): Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
03-31 00:21:06.262 W/EntropyMixer( 1532): at libcore.io.Linux.open(Native Method)
03-31 00:21:06.262 W/EntropyMixer( 1532): at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
03-31 00:21:06.262 W/EntropyMixer( 1532): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
03-31 00:21:06.262 W/EntropyMixer( 1532): at libcore.io.IoBridge.open(IoBridge.java:478)
03-31 00:21:06.262 W/EntropyMixer( 1532): ... 10 more
03-31 00:21:06.262 I/EntropyMixer( 1532): Writing entropy...
03-31 00:21:27.538 I/UsageStatsService( 1532): User[0] Flushing usage stats to disk
03-31 00:36:15.783 E/TLOC ( 1387): [TLOCChannel]"Can't receive message due to timeout"
03-31 00:36:15.787 I/TLOC ( 1387): [ModemComm ]"Request succeeded for gps engine lock"
03-31 00:36:15.787 D/TLOC ( 1387): [TLOCChannel] "Going to receive message for TLOCD"
03-31 00:36:15.787 D/TLOC ( 1387): [TLOCChannel] "wait for message for user TLOCD"
03-31 00:36:16.785 E/TLOC ( 1387): [TLOCChannel]"Can't receive message due to timeout"
03-31 00:36:16.785 E/TLOC ( 1387): [TLOCDaemon ]"Couldn't receive command response"
03-31 00:36:16.785 I/TLOC ( 1387): [TLOCDaemon ]"timeout passed - start periodic warm-up"
03-31 00:36:16.787 I/TLOC ( 1387): [ModemComm ]"Start a session successfully"
03-31 00:36:16.787 D/TLOC ( 1387): [TLOCDaemon ]"The command finished successfully"
03-31 00:36:16.787 D/TLOC ( 1387): [TLOCDaemon ]"waiting for command"
03-31 00:36:16.787 D/TLOC ( 1387): [TLOCChannel] "Going to receive message for TLOCD"
03-31 00:36:16.787 D/TLOC ( 1387): [TLOCChannel] "wait for message for user TLOCD"
03-31 00:36:36.789 E/TLOC ( 1387): [TLOCChannel]"Can't receive message due to timeout"
03-31 00:36:36.789 I/TLOC ( 1387): [TLOCDaemon ]"timeout passed with no location fix - close the session"
03-31 00:36:36.790 I/TLOC ( 1387): [Modem ]"Received event indication of position report with status USER_END"
03-31 00:36:36.790 I/TLOC ( 1387): [ModemComm ]"Stopped the session successfully"
03-31 00:36:36.790 D/TLOC ( 1387): [TLOCDaemon ]"The command finished successfully"
03-31 00:36:36.790 D/TLOC ( 1387): [TLOCDaemon ]"waiting for command"
03-31 00:36:36.790 D/TLOC ( 1387): [TLOCChannel] "Going to receive message for TLOCD"
03-31 00:36:36.790 D/TLOC ( 1387): [TLOCChannel] "wait for message for user TLOCD"
03-31 00:41:27.692 I/UsageStatsService( 1532): User[0] Flushing usage stats to disk
03-31 00:50:48.576 E/KernelCpuSpeedReader( 1532): Failed to read cpu-freq: /sys/devices/system/cpu/cpu6/cpufreq/stats/time_in_state: open failed: ENOENT (No such file or directory)
03-31 00:50:48.576 E/KernelCpuSpeedReader( 1532): Failed to read cpu-freq: /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state: open failed: ENOENT (No such file or directory)
adb shell top
help
一个demo
定时刷新指定进程下的所有线程信息
先通过adb shell ps | grep 找到自己的包对应的pid
adb shell top -H -p 4924 -m 50
说明
Tasks: 552 total, 1 running, 510 sleeping, 0 stopped, 0 zombie
任务(进程) 系统现在共有552个进程,其中处于运行中的有1个,510个在休眠(sleep),stoped状态的有0个,zombie状态(僵尸)的有0个。
Mem: 5849960k total, 4014628k used, 1835332k free, 5756k buffers
内存状态: 物理内存总量 (5.6G) 使用中的内存总量 空闲内存总量 缓存的内存量
1TB=1024GB ,1GB=1024MB ,1MB=1024KB ,1KB=1024字节。
Swap: 2293756k total, 1039804k used, 1253952k free, 918600k cached
swap交换分区: 交换区总量 使用的交换区总量 空闲交换区总量 缓冲的交换区总量
如果出于习惯去计算可用内存数,这里有个近似的计算公式:
Mem的free + Mem的buffers + Swap的cached
按这个公式此台服务器的可用内存:1835332k + 5756k + 918600k = 2759688k(约2.6G)
800%cpu 13%user 0%nice 31%sys 756%idle 0%iow 0%irq 0%sirq 0%host
cpu状态
800%cpu – CPU总量
13%user – 用户空间占用CPU的百分比。
0%nice – 改变过优先级的进程占用CPU的百分比
31%sys – 内核空间占用CPU的百分比
756%idle – 空闲CPU百分比
0%iow – IO等待占用CPU的百分比
0%irq – 硬中断(Hardware IRQ)占用CPU的百分比
0%sirq – 软中断(Software Interrupts)占用CPU的百分比
0%host –
PID — 进程id
USER — 进程所有者
PR — 进程优先级
NI — nice值。负值表示高优先级,正值表示低优先级
VIRT — 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
RES — 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
SHR — 共享内存大小,单位kb
S — 进程状态。D=不可中断的睡眠状态 R=运行 S=睡眠 T=跟踪/停止 Z=僵尸进程
%CPU — 上次更新到现在的CPU时间占用百分比
%MEM — 进程使用的物理内存百分比
TIME+ — 进程使用的CPU时间总计,单位1/100秒
COMMAND — 进程名称(命令名/命令行)
https://www.jianshu.com/p/68e04c27246e
adb shell dumpsys meminfo <package_name>
查看包数据信息
重点关注如下几个字段:
(1) Native/Dalvik 的 Heap 信息
具体在上面的第一行和第二行,它分别给出的是JNI层和Java层的内存分配情况,如果发现这个值一直增长,则代表程序可能出现了内存泄漏。
(2) Total 的 PSS 信息
这个值就是你的应用真正占据的内存大小,通过这个信息,你可以轻松判别手机中哪些程序占内存比较大了。
VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)
RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存)
PSS - Proportional Set Size 实际使用的物理内存(比例分配共享库占用的内存)
USS - Unique Set Size 进程独自占用的物理内存(不包含共享库占用的内存)
VSS:VSS表示一个进程可访问的全部内存地址空间的大小。这个大小包括了进程已经申请但尚未使用的内存空间。在实际中很少用这种方式来表示进程占用内存的情况,用它来表示单个进程的内存使用情况是不准确的。
RSS:表示一个进程在RAM中实际使用的空间地址大小,包括了全部共享库占用的内存,这种表示进程占用内存的情况也是不准确的。
PSS:表示一个进程在RAM中实际使用的空间地址大小,它按比例包含了共享库占用的内存。假如有3个进程使用同一个共享库,那么每个进程的PSS就包括了1/3大小的共享库内存。这种方式表示进程的内存使用情况较准确,但当只有一个进程使用共享库时,其情况和RSS一模一样。
USS:表示一个进程本身占用的内存空间大小,不包含其它任何成分,这是表示进程内存大小的最好方式!