如何获得Java进程的最大堆大小?
我想检查我的应用程序是否获得了如何获得Java进程的最大堆大小?,java,jvm,Java,Jvm,我想检查我的应用程序是否获得了-Xmx选项 java进程在docker容器中运行 为了做到这一点,我需要找到所创建进程的最大堆大小 起初,我尝试了jmap命令,但出现了一个错误: bash-4.2$ jmap -heap 128 Attaching to process ID 128, please wait... Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the
-Xmx
选项
java进程在docker容器中运行
为了做到这一点,我需要找到所创建进程的最大堆大小
起初,我尝试了jmap
命令,但出现了一个错误:
bash-4.2$ jmap -heap 128
Attaching to process ID 128, please wait...
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 128: Operation not permitted
sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 128: Operation not permitted
at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.execute(LinuxDebuggerLocal.java:163)
at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach(LinuxDebuggerLocal.java:278)
at sun.jvm.hotspot.HotSpotAgent.attachDebugger(HotSpotAgent.java:671)
at sun.jvm.hotspot.HotSpotAgent.setupDebuggerLinux(HotSpotAgent.java:611)
at sun.jvm.hotspot.HotSpotAgent.setupDebugger(HotSpotAgent.java:337)
at sun.jvm.hotspot.HotSpotAgent.go(HotSpotAgent.java:304)
at sun.jvm.hotspot.HotSpotAgent.attach(HotSpotAgent.java:140)
at sun.jvm.hotspot.tools.Tool.start(Tool.java:185)
at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
at sun.jvm.hotspot.tools.HeapSummary.main(HeapSummary.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.tools.jmap.JMap.runTool(JMap.java:201)
at sun.tools.jmap.JMap.main(JMap.java:130)
Caused by: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 128: Operation not permitted
at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach0(Native Method)
at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.access$100(LinuxDebuggerLocal.java:62)
at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$1AttachTask.doit(LinuxDebuggerLocal.java:269)
at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.run(LinuxDebuggerLocal.java:138)
我不知道为什么jmap
命令失败。我寻找同样的问题,但没有一个对我有帮助
- 我尝试的是:
- 与创建进程的用户一起运行该命令
- 在docker容器外部运行命令 docker exec container_id jcmd PID GC.heap_dump/tmp/docker.hprof
jstat
命令工作正常,那么有没有办法用jstat
命令检查jvm最大堆大小
可以假定(NGCMX+OGCMX)=(-Xmx值
)吗
您可以使用
jcmd
工具:
jcmd <you_vm_process_id> VM.flags | grep MaxHeapSize
jcmd VM.flags | grep MaxHeapSize
这将显示最大堆(即使您自己没有设置)错误是
不允许
您尝试过这个吗?这是一种选择吗?