我想以编程方式获得以下命令的相同结果:
jcmd <pid> GC.class_histogram | grep 'sun.util'
728: 27 2592 sun.util.calendar.Gregorian$Date
800: 44 2112 sun.util.locale.LocaleObjectCache$CacheEntry
816: 36 2016 sun.util.calendar.ZoneInfo
1169: 22 880 sun.util.locale.BaseLocale$Key
...
我已经搜索了很多答案,但没有找到明确的答案并做我想做的事,有什么办法可以做到这一点吗?
下面的代码显示了相同的结果:
import javax.management.MBeanException;
import javax.management.ReflectionException;
import com.sun.management.DiagnosticCommandMBean;
import sun.management.ManagementFactoryHelper;
@SuppressWarnings("restriction")
public class ClassHistogram {
public static void main(String[] args) throws MBeanException, ReflectionException {
DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean();
String[] emptyStringArgs = {};
Object[] dcmdArgs = { emptyStringArgs };
String[] signature = { String[].class.getName() };
System.out.println(dcmd.invoke("gcClassHistogram", dcmdArgs, signature));
}
}
可用命令的参考:https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)