gpt4 book ai didi

java - 如何以编程方式获取 GC 类直方图

转载 作者:行者123 更新时间:2023-11-30 06:45:48 26 4
gpt4 key购买 nike

我想以编程方式获得以下命令的相同结果:

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

关于java - 如何以编程方式获取 GC 类直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48325951/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com