Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化主线程获取栈顶/栈底耗时较大的问题 #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Mr-JingShi
Copy link

主线程第一次获取栈顶/栈底时会一个字节一个字节的读操作,这样会相当耗时,现在修改为逐行读取,粗略估算速度可提高10倍。

主线程为什么不使用使用pthread_getattr_np?
(1)man pthread_getattr_np的ERRORS里有提到:
In addition, if thread refers to the main thread, then
pthread_getattr_np() can fail because of errors from various
underlying calls: fopen(3), if /proc/self/maps can't be opened;
and getrlimit(2), if the RLIMIT_STACK resource limit is not
supported.
(2)主线程使用pthread_getattr_np也是相当耗时,貌似也是需要解析/proc/self/maps,并且不止解析/proc/self/maps。

测试机型:
三星SM-G570F CPU架构armeabi-v7a Android版本7.0 测试OK
LG-H422 CPU架构armeabi-v7a Android版本5.0.1 测试OK
三星SM-N910F CPU架构aarmeabi-v7a Android版本4.4.2 测试OK

修改前后耗时对比:
image
image

主线程第一次获取栈顶/栈底时会一个字节一个字节的读操作,这样会相当耗时,现在修改为逐行读取,粗略估算速度可提高10倍。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant