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.
极客时间账号:13055537258
这份作业断断续续一直做,但是没有整理,今天花点时间整理了一下。
原理:使用HaHa库进行hprof解析,Leak-Canary中的ShortestPathFinder获取堆栈信息,过程:
1.通过findClass获取到ClassObj。
2.如果按照正常遍历ClassObj的heap会发现一共有4块heap分别是default、app、image、zygote,而我们项目中的主要来源自appHeap中,所以我只提取了这个Heap中的Instance列表。
3.然后遍历Instance列表,通过HaHaHelper的fieldValue提取出buffer数组。
4.拿到buffer数组我先对数组进行大小分类,如果大小不同可以大概率判定为是不同图片,过滤掉一部分。
5.剩下一部分的通过进行遍历比较value值,判断是否是相同图片。后续看能不能使用分治算法进行比较。
6.通过结果通过对象转成json字符串打印。
心得和体会:
1.其中遇到的问题和其他同学一样就是无法打印出堆栈信息,后来通过查看研究Leak-Canary源码发现了ShortestPathFinder这个类,并对此进行了部分删减。
2.之前用过一段时间的MAT,感觉有点难用,这份作业我给了新的自动化分析的思路,很感谢。
3.最后是执行力上的思考,作业虽然大概完成了,但是一直没花时间整理,给自己敲了一个警钟,以后一定要把一件事情有始有终的做完。