问题描述
在我们公司,我们有很多在虚拟/真实设备上运行的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 -l
和lsof -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:
-
文件描述符至少在Android中用于:
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 justps -t
这篇关于Android文件描述符泄漏调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!