[英]how to find cpu usage by java process
I want to moniter cpu usage of some java application. 我想监视某些Java应用程序的CPU使用情况。 I don't want to use tools like jconsole (JMX) 我不想使用jconsole(JMX)之类的工具
if there is any way to check by java code? 是否有任何方法可以通过Java代码检查?
Use JavaSysMon 使用JavaSysMon
Currently it reports: 目前它报告:
Also you can use jmx mbeans or get PID using Runtime.exec() and using that call platform-specific command like ps. 您也可以使用jmx mbeans或通过Runtime.exec()并使用特定于调用平台的命令(例如ps)来获取PID。
One way would be to use 一种方法是使用
Runtime.getRuntime().exec(command);
and run top | grep java
并运行top | grep java
top | grep java
command. top | grep java
命令。
You should retrieve the MX Bean ThreadMXBean
from the Java class itself and use the methods get*CpuTime()
. 您应该从Java类本身检索MX Bean ThreadMXBean
,并使用get*CpuTime()
。
Otherwise, you can use good old top
and grep on your Java process PID. 否则,您可以在Java进程PID上使用旧的top
和grep。
If you are brave enough, there is also perf
tool in linux-tools
package. 如果您足够勇敢,则linux-tools
软件包中也有perf
工具。
Hope that helps ! 希望能有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.