Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
主线程第一次获取栈顶/栈底时会一个字节一个字节的读操作,这样会相当耗时,现在修改为逐行读取,粗略估算速度可提高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
修改前后耗时对比: