如何以编程方式获取堆栈内存统计信息? [英] How do I get stack memory stats programatically?

查看:123
本文介绍了如何以编程方式获取堆栈内存统计信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的内存报告实用程序(在这种特殊情况下,不能使用现有工具).我已经打印出通过迭代ManagementFactory.getMemoryPoolMXBeans()返回的所有内存池的最大值,提交和使用情况.这使我获得了堆内存的三个堆世代(eden,survivor和old),permgen和代码缓存".

I'm writing a simple memory reporting utility (in this particular situation using an existing tool is not an option). I've got it to print the max, commit and usage for all the memory pools returned by iterating ManagementFactory.getMemoryPoolMXBeans(). That gets me the three heap generations of heap memory (eden, survivor and old), the permgen, and the "code cache".

这些似乎都不是方法堆栈存储器.最接近的东西似乎是代码缓存",但是我读到,这实际上是热点放置编译的类的地方.

None of these appear to be the method stack memory. The closest thing seems be the "code cache", but I've read that that's actually where the hotspotter puts compiled classes.

我问,因为我试图找出未能创建新线程的JBoss Webapp崩溃的原因. http ://www.mastertheboss.com/jboss-server/jboss-monitoring/how-to-solve-javalangoutofmemoryerror-unable-to-create-new-native-thread 表示这可能是由于耗尽堆栈存储器,这是有道理的.问题是:如何获取堆栈内存,以便进行检查?

I ask because I'm trying to track down the cause of a crash in a JBoss webapp that's failing to create a new thread. http://www.mastertheboss.com/jboss-server/jboss-monitoring/how-to-solve-javalangoutofmemoryerror-unable-to-create-new-native-thread suggests that this could be due to running out of stack memory, which stands to reason. The question is: how do I get the stack memory, so I can check?

推荐答案

在Linux上,您可以解析/proc/self/maps(或/proc/self/smaps了解更多详细信息).
查找以[stack:NNN]结尾的行,并将堆栈大小计算为top-bottom:

On Linux you can parse /proc/self/maps (or /proc/self/smaps for more details).
Look for the lines ending with [stack:NNN] and calculate the stack size as top - bottom:

7f8a5c0e1000-7f8a5c1df000 rw-p 00000000 00:00 0    [stack:2669]
^ bottom     ^ top                                        ^ tid

在Windows上这会比较困难,但是您可以将堆栈使用的内存估计为
数字线程数 * default_stack_size

On Windows this would be harder, but you can estimate the memory used by stacks as
number_of_threads * default_stack_size

这篇关于如何以编程方式获取堆栈内存统计信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆