Android文件描述符泄漏调试 [英] Android file descriptor leakage debuging

查看:204
本文介绍了Android文件描述符泄漏调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们公司,我们有很多在虚拟/真实设备上运行的ui测试.运行一段时间后,测试随机崩溃,我认为这是文件描述符超过以下结果的结果:我使用了

I our company we have a lot of ui-tests which are run on virtual/real devices. After running for some time tests randomly crashing, which I think is the result of file descriptor exceeding: I used

ls /proc/${PID}/fd | wc -llsof -p ${PID} 但这并没有太大帮助-lsof中的大多数行看起来像:

ls /proc/${PID}/fd | wc -l and lsof -p ${PID} but it did not help a lot - most of the rows in lsof looks like:

30015    u0_a104  678      sock                                    859560 socket:[859560]
30015    u0_a104  679      0000                0,8                 4539 anon_inode:[eventpoll]
30015    u0_a104  680      0000                0,8                 4539 anon_inode:[eventfd]
30015    u0_a104  681      0000                0,8                 4539 anon_inode:[eventfd]
30015    u0_a104  682      0000                0,8                 4539 anon_inode:[eventpoll]
30015    u0_a104  683      0000                0,8                 4539 anon_inode:[eventfd]
30015    u0_a104  684      0000                0,8                 4539 anon_inode:[eventpoll]
30015    u0_a104  685      0000                0,8                 4539 anon_inode:[eventfd]

所以我的问题是:是否有任何android/java/linux Instruments/utils可以找到泄漏的?

So my question is: is there any android/java/linux instruments/utils to find the source of leakage?

PS System.gc()没有帮助

P.S. System.gc() did not help

推荐答案

我已经对此问题进行了一段时间的研究,并希望分享我发现的内容:

I have researched for this question for a while and would like to share what I found:

  1. 文件描述符至少在Android中用于:

  1. File descriptor are used in Android at least for:

  • 网络套接字(或其他类型的文件)
  • 映射到内存文件
  • 线程-这就是我的情况.看到下面的原因

如果创建了HandlerThread,即使到HandlerThread实例的最后一个链接将消失,线程仍然可以工作并消耗FileDescriptor

If you have created a HandlerThread, even if the last link to the HandlerThread instance will disappear thread will still work and consume FileDescriptor

可以看到android中的线程:

Threads in android can be seen:

  • 在Memory Abalyze工具的"Java堆转储"中-所以我已经看到> 500个线程在执行插入测试时-它们吞噬"了所有文件描述符
  • 通过Android设备adb shell ps -t或仅ps -t
  • 上的终端
  • In "Java heap dump" in Memory Abalyze Tool - so I have seen > 500 threads while running intsrumentation tests - they "eat" all file descriptors
  • Via terminal on android device adb shell ps -t or just ps -t

这篇关于Android文件描述符泄漏调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆