英文:
Parsing hprof memory dump
问题
我正在开发一个Android应用程序,我有一个内存转储文件(即.hprof文件),是从我的应用程序中捕获的。
我想要调查应用程序中的特定容器。
就像ArrayList一样,当容器的大小达到时,容器具有增长策略,以保证在其中添加元素时具有恒定的平摊时间成本。
我的假设是容器的每个实例都拥有多个未使用的已分配内存空间。
我想自动化调查这种情况的过程。是否有办法编写一个脚本,可以解析这个.hprof文件并返回这些未使用的已分配空间与total_entries的比率?
谢谢!
英文:
I am working on an Android application and I have a memory dump (i.e. a .hprof file) that I captured from my application.
I want to investigate a certain container of the application.
Just like an ArrayList, the container has a growth policy that increases the capacity of the container when the size is reached to guarantee constant amortized time cost for adding elements into it.
My hypothesis is that every instance of the container possesses multiple unused allocated memory spaces.
I want to automate the process of investigating this case. Is there a way to write a script that can parse this .hprof file and return the ratio of these unused allocated spaces to total_entries?
Thank you!
答案1
得分: 0
您可以查看jvm-hprof-rs
(https://bitbucket.org/marshallpierce/jvm-hprof-rs/src/master/)。
如果您熟悉Rust编程,该库可以让您对如何处理数据有很大的控制权。 (文档)
对于更简单的情况,analyze_hprof
示例可以提供包含“实例计数”,“实例大小(字节)”,“总浅实例大小(字节)”,“类名”和“类对象ID”的CSV格式。 然后,您可以进行后处理以获取所需的信息。
cargo run --release --example analyze_hprof -- \
-f path/to/your.hprof \
instance-counts
如果我理解您的问题正确,您可以获取输出的CSV,使用grep筛选出您要分析的类名,然后计算“实例大小(字节)/实例计数”。
英文:
You can take a look at jvm-hprof-rs
(https://bitbucket.org/marshallpierce/jvm-hprof-rs/src/master/).
If you are comfortable writing Rust code, the library gives you a great deal of control over how to process the data. (Documentation)
For simpler cases, the analyze_hprof
example can give you a CSV format containing the "Instance count", "Instance size (bytes)", "Total shallow instance size (bytes)", "Class name", and "Class obj id". You can then post-process to get the info you need.
cargo run --release --example analyze_hprof -- \
-f path/to/your.hprof \
instance-counts
If I am understanding your problem correctly, you can take the output CSV, grep for the class name you want to analyze, and compute Instance size (bytes) / Instance count
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论