分析log
1. 查找关键字
通过查找:"null" "error" " "E/","Fatal","NullPointerException","Build fingerprint:","exception","anr","DexOpt"等的错误信息,来定位问题
1)空指针问题
NullPointerException: 这个直接找到java代码,首先分析为什么会是空指针,如果逻辑上没有问题,加上一个判断就可以,也就是说如果为空的时候再次赋值或者直接返回
2).没有捕获异常问题
Exception: 能捕获的话捕获
3)ANR问题
anr:要分析原因了,看看什么导致的,然后优化代码
例子
[ruby] view plaincopy
I/dalvikvm( 1014): Wrote stack traces to '/data/anr/traces.txt'
I/Process ( 957): Sending signal. PID: 1124 SIG: 9
E/ActivityManager( 957): ANR in com.ipanel.join.appstore
E/ActivityManager( 957): Reason: Broadcast of Intent { act=android.appwidget.action.APPWIDGET_UPDATE cmp=com.ipanel.join.appstore/.widget.SmallWidget1 (has extras) }
E/ActivityManager( 957): Load: 1.57 / 0.38 / 0.13
E/ActivityManager( 957): CPU usage from 6290ms to 0ms ago:
E/ActivityManager( 957): 70% 957/system_server: 1.1% user + 69% kernel / faults: 204 minor
E/ActivityManager( 957): 8.7% 1014/com.ipanel.join.home.jelly: 7.7% user + 0.9% kernel / faults: 899 minor
E/ActivityManager( 957): 0.3% 687/yaffs-bg-1: 0% user + 0.3% kernel
E/ActivityManager( 957): 0.3% 688/yaffs-bg-1: 0% user + 0.3% kernel
E/ActivityManager( 957): 0.3% 935/irkeyservice: 0% user + 0.3% kernel
E/ActivityManager( 957): 0% 890/galcore daemon : 0% user + 0% kernel
E/ActivityManager( 957): 0.1% 1076/com.ipanel.join.browser: 0.1% user + 0% kernel
E/ActivityManager( 957): 0.1% 1124/com.ipanel.join.appstore: 0.1% user + 0% kernel
E/ActivityManager( 957): 75% TOTAL: 4.7% user + 70% kernel
E/ActivityManager( 957): CPU usage from 622ms to 1169ms later:
E/ActivityManager( 957): 71% 957/system_server: 0% user + 71% kernel / faults: 2 minor
E/ActivityManager( 957): 67% 965/SurfaceFlinger: 0% user + 67% kernel
E/ActivityManager( 957): 1.9% 973/ActivityManager: 1.9% user + 0% kernel
E/ActivityManager( 957): 1.9% 991/CursorMove: 0% user + 1.9% kernel
E/ActivityManager( 957): 7.6% 1014/com.ipanel.join.home.jelly: 7.6% user + 0% kernel / faults: 31 minor
E/ActivityManager( 957): 5.7% 1119/Thread-13: 5.7% user + 0% kernel
E/ActivityManager( 957): 1.9% 1123/Thread-13: 1.9% user + 0% kernel
E/ActivityManager( 957): 76% TOTAL: 1.8% user + 72% kernel + 1.8% softirq
指定哪个java包出问题
E/ActivityManager( 957): ANR in com.ipanel.join.appstore
进程号为957发生了如下错误:com.ipanel.join.appstore 包下面 Broadcast问题
ANR原因:
E/ActivityManager( 957): Reason: Broadcast of Intent { act=android.appwidget.action.APPWIDGET_UPDATE cmp=com.ipanel.join.appstore/.widget.SmallWidget1 (has extras) }
这是ANR的堆栈调用文件
I/dalvikvm( 1014): Wrote stack traces to '/data/anr/traces.txt'
通过上面的log信息分析,应该是接收一个广播消息时超时了
我们再分析虚拟机信息 ,打开/data/anr/traces.txt,可有通过adb pull /data/anr/traces.txt .
这里每一段都是一个线程 ,当然我们还是看线程号为1的主线程了。通过分析发现关键问题是这样:
搜索“DALVIK THREADS”关键词,快速定位到本应用程序的虚拟机信息日志
[ruby] view plaincopy
----- pid 1516 at 1970-01-02 08:03:07 -----
Cmd line: com.ipanel.join.appstore
DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
"main" prio=5 tid=1 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x4001f188 self=0xd028
| sysTid=1516 nice=0 sched=3/0 cgrp=[fopen-error:2] handle=-1345017744
at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:357)
at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:204)
at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437)
at java.net.Socket.connect(Socket.java:983)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:74)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:298)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1018)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:726)
at com.ipanel.join.appstore.http.DefaultHttpRequest.doGet(DefaultHttpRequest.java:35)
at com.ipanel.join.appstore.widget.AbsSmallWidget.requestApps(AbsSmallWidget.java:117)
at com.ipanel.join.appstore.widget.AbsSmallWidget.getRemoteViews(AbsSmallWidget.java:56)
其实从这句话:
at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
基本上确认是 socket ->connect 连接超时了,导致主线程5s内没有响应从而产生ANR错误。默认的connect连接timeout时间是75s
其实解决办法就是利用非阻塞方式进行连接即可。
从CPU占用率上也可以看出是在kernel中执行堵塞住了
E/ActivityManager( 957): 75% TOTAL: 4.7% user + 70% kernel
4)Fatal问题
Fatal: 比较严重了,很多都很动态库和空指针有关,一般会接下来打印"Build fingerprint:"或”NullPointerException“
5)动态库问题
Build fingerprint:动态库的问题,如何调试,还在学习中。。。
Log:
[ruby] view plaincopy
05-30 15:07:40.559: A/libc(623): Fatal signal 11 (SIGSEGV) at 0x00000014 (code=1), thread 1000 (Binder_5)
05-30 15:07:40.609: I/DEBUG(85): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
05-30 15:07:40.609: I/DEBUG(85): Build fingerprint: 'unknown'
05-30 15:07:40.609: I/DEBUG(85): pid: 623, tid: 1000, name: Binder_5 >>> system_server <<<
05-30 15:07:40.609: I/DEBUG(85): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000014
05-30 15:07:40.679: I/DEBUG(85): r0 00000000 r1 649661d6 r2 6d12fc30 r3 00000001
05-30 15:07:40.679: I/DEBUG(85): r4 6740e3d0 r5 00000000 r6 6d12fc30 r7 6740e3d0
05-30 15:07:40.679: I/DEBUG(85): r8 00000001 r9 400aff10 sl 6740e3c8 fp 00000001
05-30 15:07:40.679: I/DEBUG(85): ip 00000000 sp 6d12fbe8 lr 40054dff pc 40054e0a cpsr 60000030
05-30 15:07:40.679: I/DEBUG(85): d0 3f8000003f800000 d1 11111111c1c00000
05-30 15:07:40.679: I/DEBUG(85): d2 1a1a1a1a1a1a1a1a d3 ffffffffffffffff
05-30 15:07:40.679: I/DEBUG(85): d4 0808080808080808 d5 1111111111111111
05-30 15:07:40.679: I/DEBUG(85): d6 000000001a1a1a1a d7 0000000000000000
05-30 15:07:40.679: I/DEBUG(85): d8 0000000000000000 d9 0000000000000000
05-30 15:07:40.679: I/DEBUG(85): d10 0000000000000000 d11 0000000000000000
05-30 15:07:40.679: I/DEBUG(85): d12 0000000000000000 d13 0000000000000000
05-30 15:07:40.679: I/DEBUG(85): d14 0000000000000000 d15 0000000000000000
05-30 15:07:40.679: I/DEBUG(85): d16 000000000bebc200 d17 0000000000000000
05-30 15:07:40.679: I/DEBUG(85): d18 0000000000000000 d19 0000000000000000
05-30 15:07:40.679: I/DEBUG(85): d20 0808080808080808 d21 1111111111111111
05-30 15:07:40.679: I/DEBUG(85): d22 1a1a1a1a1a1a1a1a d23 ffffffffffffffff
05-30 15:07:40.679: I/DEBUG(85): d24 0808080808080808 d25 1111111111111111
05-30 15:07:40.679: I/DEBUG(85): d26 1a1a1a1a1a1a1a1a d27 ffffffffffffffff
05-30 15:07:40.679: I/DEBUG(85): d28 0100010001000100 d29 0100010001000100
05-30 15:07:40.679: I/DEBUG(85): d30 0000000000000000 d31 0000000000000000
05-30 15:07:40.679: I/DEBUG(85): scr 60000010
05-30 15:07:40.689: I/DEBUG(85): backtrace:
05-30 15:07:40.689: I/DEBUG(85): #00 pc 00011e0a /system/lib/libutils.so (android::VectorImpl::insertAt(void const*, unsigned int, unsigned int)+37)
05-30 15:07:40.689: I/DEBUG(85): #01 pc 0001205b /system/lib/libutils.so (android::SortedVectorImpl::add(void const*)+26)
05-30 15:07:40.689: I/DEBUG(85): #02 pc 0000dbdb /system/lib/libsensorservice.so (android::SensorDevice::activate(void*, int, int)+122)
05-30 15:07:40.689: I/DEBUG(85): #03 pc 0000e1cf /system/lib/libsensorservice.so (android::SensorFusion::activate(void*, bool)+98)
05-30 15:07:40.689: I/DEBUG(85): #04 pc 000101df /system/lib/libsensorservice.so (android::SensorService::enable(android::sp<android::SensorService::SensorEventConnection> const&, int)+68)
05-30 15:07:40.689: I/DEBUG(85): #05 pc 000102ef /system/lib/libsensorservice.so (android::SensorService::SensorEventConnection::enableDisable(int, bool)+24)
05-30 15:07:40.689: I/DEBUG(85): #06 pc 0001d1c5 /system/lib/libgui.so (android::BnSensorEventConnection::onTransact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+108)
05-30 15:07:40.689: I/DEBUG(85): #07 pc 00016e4d /system/lib/libbinder.so (android::BBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+60)
05-30 15:07:40.689: I/DEBUG(85): #08 pc 00019a29 /system/lib/libbinder.so (android::IPCThreadState::executeCommand(int)+520)
05-30 15:07:40.689: I/DEBUG(85): #09 pc 00019e51 /system/lib/libbinder.so (android::IPCThreadState::joinThreadPool(bool)+184)
05-30 15:07:40.689: I/DEBUG(85): #10 pc 0001e829 /system/lib/libbinder.so
05-30 15:07:40.689: I/DEBUG(85): #11 pc 00010f47 /system/lib/libutils.so (android::Thread::_threadLoop(void*)+114)
05-30 15:07:40.689: I/DEBUG(85): #12 pc 00046af3 /system/lib/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+66)
05-30 15:07:40.689: I/DEBUG(85): #13 pc 00010aad /system/lib/libutils.so
05-30 15:07:40.689: I/DEBUG(85): #14 pc 00012b70 /system/lib/libc.so (__thread_entry+48)
05-30 15:07:40.689: I/DEBUG(85): #15 pc 000122c8 /system/lib/libc.so (pthread_create+172)
arm-eabi-addr2line这个工具通过库的trace来跟踪代码的,这个工具位于Android\prebuilt\linux-x86\toolchain\arm-eabi-4.4.3\binarm-eabi-addr2line, "source built/envsetup.sh"可以将这个工具加入到全局
查找:
[java] view plaincopy
lijinwei@softser30-15:~/RK4_1_B07_BRH/out/target/product/rk30sdk_joyplus/obj/SHARED_LIBRARIES/libutils_intermediates/LINKED$ arm-eabi-addr2line 00011e0a -e libutils.so
/home/lijinwei/RK4_1_B07_BRH/frameworks/native/libs/utils/VectorImpl.cpp:476
lijinwei@softser30-15:~/RK4_1_B07_BRH/out/target/product/rk30sdk_joyplus/obj/SHARED_LIBRARIES/libsensorservice_intermediates/LINKED$ ls
libsensorservice.so
lijinwei@softser30-15:~/RK4_1_B07_BRH/out/target/product/rk30sdk_joyplus/obj/SHARED_LIBRARIES/libsensorservice_intermediates/LINKED$ arm-eabi-addr2line 0000dbdb -e libsensorservice.so
/home/lijinwei/RK4_1_B07_BRH/frameworks/native/include/utils/SortedVector.h:211
template<class TYPE> inline
ssize_t SortedVector<TYPE>::add(const TYPE& item) {
return SortedVectorImpl::add(&item);
}
lijinwei@softser30-15:~/RK4_1_B07_BRH/out/target/product/rk30sdk_joyplus/obj/SHARED_LIBRARIES/libsensorservice_intermediates/LINKED$ arm-eabi-addr2line 0000e1cf -e libsensorservice.so
/home/lijinwei/RK4_1_B07_BRH/frameworks/base/services/sensorservice/SensorFusion.cpp:95
mSensorDevice.activate(ident, mMag.getHandle(), enabled);
lijinwei@softser30-15:~/RK4_1_B07_BRH/out/target/product/rk30sdk_joyplus/obj/SHARED_LIBRARIES/libsensorservice_intermediates/LINKED$ arm-eabi-addr2line 000101df -e libsensorservice.so
/home/lijinwei/RK4_1_B07_BRH/frameworks/base/services/sensorservice/SensorService.cpp:413
status_t SensorService::enable(const sp<SensorEventConnection>& connection,
int handle)
{
if (mInitCheck != NO_ERROR)
return mInitCheck;
Mutex::Autolock _l(mLock);
SensorInterface* sensor = mSensorMap.valueFor(handle);
status_t err = sensor ? sensor->activate(connection.get(), true) : status_t(BAD_VALUE);
...
}
lijinwei@softser30-15:~/RK4_1_B07_BRH/out/target/product/rk30sdk_joyplus/obj/SHARED_LIBRARIES/libsensorservice_intermediates/LINKED$ arm-eabi-addr2line 000102ef -e libsensorservice.so
/home/lijinwei/RK4_1_B07_BRH/frameworks/base/services/sensorservice/SensorService.cpp:622
status_t SensorService::SensorEventConnection::enableDisable(
int handle, bool enabled)
{
status_t err;
if (enabled) {
err = mService->enable(this, handle);
} else {
err = mService->disable(this, handle);
}
return err;
}
lijinwei@softser30-15:~/RK4_1_B07_BRH/out/target/product/rk30sdk_joyplus/obj/SHARED_LIBRARIES/libgui_intermediates/LINKED$ arm-eabi-addr2line 0001d1c5 -e libgui.so
/home/lijinwei/RK4_1_B07_BRH/frameworks/native/libs/gui/ISensorEventConnection.cpp:94
status_t BnSensorEventConnection::onTransact(
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
switch(code) {
case GET_SENSOR_CHANNEL: {
CHECK_INTERFACE(ISensorEventConnection, data, reply);
sp<BitTube> channel(getSensorChannel());
channel->writeToParcel(reply);
return NO_ERROR;
} break;
case ENABLE_DISABLE: {
CHECK_INTERFACE(ISensorEventConnection, data, reply);
int handle = data.readInt32();
int enabled = data.readInt32();
status_t result = enableDisable(handle, enabled);
可以知道是sensorservice在调enable的时候出现了问题,具体原因还得看sensorservice的管理机制,总之能定位到问题出现的地方了。
6)执行DexOpt错误
DexOpt:解压或优化extract+optimize DEX出的问题
[ruby] view plaincopy
W/dalvikvm( 1803): DexOpt: --- END 'SettingsProvider.apk' --- status=0x000a, process failed
E/dalvikvm( 1803): Unable to extract+optimize DEX from '/system/app/SettingsProvider.apk'
E/SystemServer( 1803): Failure starting Input Manager Service
E/SystemServer( 1803): java.lang.RuntimeException: Unable to get provider com.android.providers.settings.SettingsProvider: java.lang.ClassNotFoundException: com.android.providers.settings.SettingsProvider in loader dalvik.system.PathClassLoader[/system/app/SettingsProvider.apk]
E/SystemServer( 1803): at android.app.ActivityThread.installProvider(ActivityThread.java:3557)
E/SystemServer( 1803): at android.app.ActivityThread.getProvider(ActivityThread.java:3356)
从上面的打印看,是在解压或优化extract+optimize DEX的apk文件时出错了
I、没有出现magic number错误,这个原因与原子操作无关(这是一快速的加锁和解锁的轻量级操作函数)
II、执行dexopt出错,查明是服务器硬盘没空间了,导致引导文件系统的时候没有空间进行解压而失败
2.系统启动后默认其妙或随机死机情况
出现这种错误:
[ruby] view plaincopy
12-01 08:11:56.027: WARN/SharedBufferStack(312): waitForCondition(LockCondition) timed out (identity=19, status=0). CPU may be pegged. trying again.
12-01 08:11:57.315: WARN/SharedBufferStack(312): waitForCondition(LockCondition) timed out (identity=19, status=0). CPU may be pegged. trying again.
12-01 08:11:59.318: WARN/SharedBufferStack(312): waitForCondition(LockCondition) timed out (identity=19, status=0). CPU may be pegged. trying again.
12-01 08:12:03.332: WARN/SharedBufferStack(312): waitForCondition(LockCondition) timed out (identity=19, status=0). CPU may be pegged. trying again.
12-01 08:12:05.329: WARN/SharedBufferStack(312): waitForCondition(LockCondition) timed out (identity=19, status=0). CPU may be pegged. trying again.
12-01 08:12:07.216: WARN/KeyCharacterMap(312): No keyboard for id 0
12-01 08:12:07.216: WARN/KeyCharacterMap(312): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
查看内存: cat /proc/meminfo 发现空闲内存只剩下几M空间了。
请加大android系统的内存即可解决问题