如何获取Binder事务缓冲区的内容以进行故障排除

时间:2014-09-01 14:46:44

标签: android android-intent

有没有办法,无论是通过编程方式还是通过调试工具,都能知道Binder事务缓冲区中保存的当前事务?

有时,通常在运行几小时/几天后,我的应用程序崩溃并出现如下错误跟踪:

08-30 09:49:57.459  1879  1904 E JavaBinder: !!! FAILED BINDER TRANSACTION !!!
08-30 09:49:57.469  1879  1904 W BroadcastQueue: Exception when sending broadcast to ComponentInfo{com.mycompany.myapp/com.mycompany.myapp.receiver.UpdateContentReceiver}
08-30 09:49:57.469  1879  1904 W BroadcastQueue: android.os.TransactionTooLargeException
08-30 09:49:57.469  1879  1904 W BroadcastQueue:    at android.os.BinderProxy.transact(Native Method)
08-30 09:49:57.469  1879  1904 W BroadcastQueue:    at android.app.ApplicationThreadProxy.scheduleReceiver(ApplicationThreadNative.java:771)
08-30 09:49:57.469  1879  1904 W BroadcastQueue:    at com.android.server.am.BroadcastQueue.processCurBroadcastLocked(BroadcastQueue.java:231)
08-30 09:49:57.469  1879  1904 W BroadcastQueue:    at com.android.server.am.BroadcastQueue.processNextBroadcast(BroadcastQueue.java:778)
08-30 09:49:57.469  1879  1904 W BroadcastQueue:    at com.android.server.am.BroadcastQueue$1.handleMessage(BroadcastQueue.java:140)
08-30 09:49:57.469  1879  1904 W BroadcastQueue:    at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 09:49:57.469  1879  1904 W BroadcastQueue:    at android.os.Looper.loop(Looper.java:137)
08-30 09:49:57.469  1879  1904 W BroadcastQueue:    at com.android.server.am.ActivityManagerService$AThread.run(ActivityManagerService.java:1487)

我试图发送的广播没有额外内容,所以它的大小可以忽略不计。根据{{​​3}}的文档:

  

Binder事务缓冲区具有有限的固定大小,当前为1Mb,由进程正在进行的所有事务共享。因此,即使大多数单个事务的大小适中,当有许多事务正在进行时,也会抛出此异常。

我的想法是缓冲区被其他东西(我的应用程序,我使用的其中一个库或系统)填满,当它几乎已满时,它会抛出TransactionTooLargeException。通过检查缓冲区的内容,我可以很容易地发现问题。

1 个答案:

答案 0 :(得分:6)

http://www.slideshare.net/jserv/android-ipc-mechanism的幻灯片67中所示,可以通过debugfs找到有关Binder事务缓冲区的详细信息。用

安装后
mount -t debugfs none /sys/kernel/debug

可以在/sys/kernel/debug/binder/中访问Binder信息,其中可以获取全局信息和每个进程信息。

相关问题