Java Code Examples for java.lang.management.CompilationMXBean

The following examples show how to use java.lang.management.CompilationMXBean. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: swage   Source File: CompilationTimeSensor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void sense(final MetricContext metricContext)
{
    CompilationMXBean mxBean = ManagementFactory.getCompilationMXBean();

    // Compilation time may not be supported on some platforms, skip if so.
    if (!mxBean.isCompilationTimeMonitoringSupported()) {
        return;
    }

    long total = mxBean.getTotalCompilationTime();
    metricContext.record(TOTAL_COMPILATION_TIME, total, Unit.MILLISECOND);
    metricContext.record(COMPILATION_TIME, total - prevTotal, Unit.MILLISECOND);

    this.prevTotal = total;
}
 
Example 2
Source Project: astor   Source File: JvmMetrics.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static void writeJitMetrics(
    PrintStream out, boolean verbose, boolean pretty) {

  CompilationMXBean cBean = ManagementFactory.getCompilationMXBean();

  String name;
  if (verbose) {
    name = cBean.getName();
  } else {
    name = "total";
  }

  if (pretty) {
    out.println("\nJIT Stats");
    out.println(String.format(
        "\t%s jit time: %d ms", name, cBean.getTotalCompilationTime()));
  } else {
    out.println(normalizeTabularColonPos(String.format("%s-jit-time-ms : %d",
        normalizeName(name), cBean.getTotalCompilationTime())));
  }
}
 
Example 3
Source Project: Deta_Cache   Source File: OperatingSystemInfoUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
	 * Java ������ı���ϵͳ
	 */
	public static Map<String, String> showCompilation(){
		Map<String, String> map = new HashMap<>();
		CompilationMXBean com = ManagementFactory.getCompilationMXBean();
		map.put("TotalCompilationTime:", "" + com.getTotalCompilationTime());
		map.put("name:", "" +  com.getName());
		return map;
//		System.out.println("TotalCompilationTime:" + com.getTotalCompilationTime());
//		System.out.println("name:" + com.getName());
	}
 
Example 4
private final int doCompilationMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- CompilationMXBean") ;

    try {
        ObjectName compilationName =
                new ObjectName(ManagementFactory.COMPILATION_MXBEAN_NAME);

        if ( mbsc.isRegistered(compilationName) ) {
            MBeanInfo mbInfo = mbsc.getMBeanInfo(compilationName);
            errorCount += checkNonEmpty(mbInfo);
            System.out.println("getMBeanInfo\t\t" + mbInfo);
            CompilationMXBean compilation = null ;

            compilation =
                    JMX.newMXBeanProxy(mbsc,
                    compilationName,
                    CompilationMXBean.class) ;
            System.out.println("getName\t\t"
                    + compilation.getName());
            boolean supported =
                    compilation.isCompilationTimeMonitoringSupported() ;
            System.out.println("isCompilationTimeMonitoringSupported\t\t"
                    + supported);

            if ( supported ) {
                System.out.println("getTotalCompilationTime\t\t"
                        + compilation.getTotalCompilationTime());
            }
        }

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 5
private final int doCompilationMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- CompilationMXBean") ;

    try {
        ObjectName compilationName =
                new ObjectName(ManagementFactory.COMPILATION_MXBEAN_NAME);

        if ( mbsc.isRegistered(compilationName) ) {
            MBeanInfo mbInfo = mbsc.getMBeanInfo(compilationName);
            errorCount += checkNonEmpty(mbInfo);
            System.out.println("getMBeanInfo\t\t" + mbInfo);
            CompilationMXBean compilation = null ;

            compilation =
                    JMX.newMXBeanProxy(mbsc,
                    compilationName,
                    CompilationMXBean.class) ;
            System.out.println("getName\t\t"
                    + compilation.getName());
            boolean supported =
                    compilation.isCompilationTimeMonitoringSupported() ;
            System.out.println("isCompilationTimeMonitoringSupported\t\t"
                    + supported);

            if ( supported ) {
                System.out.println("getTotalCompilationTime\t\t"
                        + compilation.getTotalCompilationTime());
            }
        }

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 6
Source Project: systemds   Source File: Statistics.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the total time of asynchronous JIT compilation in milliseconds.
 * 
 * @return JIT compile time
 */
public static long getJITCompileTime(){
	long ret = -1; //unsupported
	CompilationMXBean cmx = ManagementFactory.getCompilationMXBean();
	if( cmx.isCompilationTimeMonitoringSupported() )
	{
		ret = cmx.getTotalCompilationTime();
		ret += jitCompileTime; //add from remote processes
	}
	return ret;
}
 
Example 7
private final int doCompilationMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- CompilationMXBean") ;

    try {
        ObjectName compilationName =
                new ObjectName(ManagementFactory.COMPILATION_MXBEAN_NAME);

        if ( mbsc.isRegistered(compilationName) ) {
            MBeanInfo mbInfo = mbsc.getMBeanInfo(compilationName);
            errorCount += checkNonEmpty(mbInfo);
            System.out.println("getMBeanInfo\t\t" + mbInfo);
            CompilationMXBean compilation = null ;

            compilation =
                    JMX.newMXBeanProxy(mbsc,
                    compilationName,
                    CompilationMXBean.class) ;
            System.out.println("getName\t\t"
                    + compilation.getName());
            boolean supported =
                    compilation.isCompilationTimeMonitoringSupported() ;
            System.out.println("isCompilationTimeMonitoringSupported\t\t"
                    + supported);

            if ( supported ) {
                System.out.println("getTotalCompilationTime\t\t"
                        + compilation.getTotalCompilationTime());
            }
        }

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 8
Source Project: game-server   Source File: SysUtil.java    License: MIT License 5 votes vote down vote up
/**
 * 类编译信息
 * 
 * @author JiangZhiYong
 * @QQ 359135103 2017年10月12日 下午3:39:22
 * @param spliteStr
 * @return
 */
public static String compilationInfo(String spliteStr) {
	CompilationMXBean bean = ManagementFactory.getCompilationMXBean();
	StringBuilder sb = new StringBuilder();
	sb.append("编译器名称:   " + bean.getName()).append(spliteStr);
	sb.append("编译耗时:   " + bean.getTotalCompilationTime()).append(spliteStr);
	sb.append("是否支持编译监视:   " + bean.isCompilationTimeMonitoringSupported()).append(spliteStr);
	return sb.toString();
}
 
Example 9
Source Project: micrometer   Source File: JvmCompilationMetrics.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void bindTo(MeterRegistry registry) {
    CompilationMXBean compilationBean = ManagementFactory.getCompilationMXBean();
    if (compilationBean != null && compilationBean.isCompilationTimeMonitoringSupported()) {
        FunctionCounter.builder("jvm.compilation.time", compilationBean, CompilationMXBean::getTotalCompilationTime)
                .tags(Tags.concat(tags, "compiler", compilationBean.getName()))
                .description("The approximate accumulated elapsed time spent in compilation")
                .baseUnit(BaseUnits.MILLISECONDS)
                .register(registry);
    }
}
 
Example 10
Source Project: micrometer   Source File: JvmCompilationMetricsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void compilationTimeMetric() {
    new JvmCompilationMetrics().bindTo(registry);

    CompilationMXBean compilationMXBean = ManagementFactory.getCompilationMXBean();
    assumeTrue(compilationMXBean != null && compilationMXBean.isCompilationTimeMonitoringSupported());

    assertThat(registry.get("jvm.compilation.time").functionCounter().count()).isGreaterThan(0);
}
 
Example 11
Source Project: ClusterDeviceControlPlatform   Source File: Test.java    License: MIT License 5 votes vote down vote up
private static void printCompilationInfo() {
    CompilationMXBean compilation = ManagementFactory.getCompilationMXBean();
    System.out.println("JIT编译器名称:" + compilation.getName());
    //判断jvm是否支持编译时间的监控
    if (compilation.isCompilationTimeMonitoringSupported()) {
        System.out.println("总编译时间:" + compilation.getTotalCompilationTime() + "秒");
    }
}
 
Example 12
Source Project: ClusterDeviceControlPlatform   Source File: Test.java    License: MIT License 5 votes vote down vote up
private static void printCompilationInfo() {
    CompilationMXBean compilation = ManagementFactory.getCompilationMXBean();
    System.out.println("JIT编译器名称:" + compilation.getName());
    //判断jvm是否支持编译时间的监控
    if (compilation.isCompilationTimeMonitoringSupported()) {
        System.out.println("总编译时间:" + compilation.getTotalCompilationTime() + "秒");
    }
}
 
Example 13
private final int doCompilationMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- CompilationMXBean") ;

    try {
        ObjectName compilationName =
                new ObjectName(ManagementFactory.COMPILATION_MXBEAN_NAME);

        if ( mbsc.isRegistered(compilationName) ) {
            MBeanInfo mbInfo = mbsc.getMBeanInfo(compilationName);
            errorCount += checkNonEmpty(mbInfo);
            System.out.println("getMBeanInfo\t\t" + mbInfo);
            CompilationMXBean compilation = null ;

            compilation =
                    JMX.newMXBeanProxy(mbsc,
                    compilationName,
                    CompilationMXBean.class) ;
            System.out.println("getName\t\t"
                    + compilation.getName());
            boolean supported =
                    compilation.isCompilationTimeMonitoringSupported() ;
            System.out.println("isCompilationTimeMonitoringSupported\t\t"
                    + supported);

            if ( supported ) {
                System.out.println("getTotalCompilationTime\t\t"
                        + compilation.getTotalCompilationTime());
            }
        }

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 14
private final int doCompilationMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- CompilationMXBean") ;

    try {
        ObjectName compilationName =
                new ObjectName(ManagementFactory.COMPILATION_MXBEAN_NAME);

        if ( mbsc.isRegistered(compilationName) ) {
            MBeanInfo mbInfo = mbsc.getMBeanInfo(compilationName);
            errorCount += checkNonEmpty(mbInfo);
            System.out.println("getMBeanInfo\t\t" + mbInfo);
            CompilationMXBean compilation = null ;

            compilation =
                    JMX.newMXBeanProxy(mbsc,
                    compilationName,
                    CompilationMXBean.class) ;
            System.out.println("getName\t\t"
                    + compilation.getName());
            boolean supported =
                    compilation.isCompilationTimeMonitoringSupported() ;
            System.out.println("isCompilationTimeMonitoringSupported\t\t"
                    + supported);

            if ( supported ) {
                System.out.println("getTotalCompilationTime\t\t"
                        + compilation.getTotalCompilationTime());
            }
        }

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 15
Source Project: jdk8u-jdk   Source File: MXBeanInteropTest1.java    License: GNU General Public License v2.0 5 votes vote down vote up
private final int doCompilationMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- CompilationMXBean") ;

    try {
        ObjectName compilationName =
                new ObjectName(ManagementFactory.COMPILATION_MXBEAN_NAME);

        if ( mbsc.isRegistered(compilationName) ) {
            MBeanInfo mbInfo = mbsc.getMBeanInfo(compilationName);
            errorCount += checkNonEmpty(mbInfo);
            System.out.println("getMBeanInfo\t\t" + mbInfo);
            CompilationMXBean compilation = null ;

            compilation =
                    JMX.newMXBeanProxy(mbsc,
                    compilationName,
                    CompilationMXBean.class) ;
            System.out.println("getName\t\t"
                    + compilation.getName());
            boolean supported =
                    compilation.isCompilationTimeMonitoringSupported() ;
            System.out.println("isCompilationTimeMonitoringSupported\t\t"
                    + supported);

            if ( supported ) {
                System.out.println("getTotalCompilationTime\t\t"
                        + compilation.getTotalCompilationTime());
            }
        }

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 16
Source Project: visualvm   Source File: JvmMXBeansFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an MXBean proxy for the compilation system of the JVM.
 */
public synchronized CompilationMXBean getCompilationMXBean() {
    if (mbsc != null && compilationMXBean == null) {
        compilationMXBean = getMXBean(COMPILATION_MXBEAN_NAME, CompilationMXBean.class);
    }
    return compilationMXBean;
}
 
Example 17
Source Project: jdk8u_jdk   Source File: MXBeanInteropTest1.java    License: GNU General Public License v2.0 5 votes vote down vote up
private final int doCompilationMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- CompilationMXBean") ;

    try {
        ObjectName compilationName =
                new ObjectName(ManagementFactory.COMPILATION_MXBEAN_NAME);

        if ( mbsc.isRegistered(compilationName) ) {
            MBeanInfo mbInfo = mbsc.getMBeanInfo(compilationName);
            errorCount += checkNonEmpty(mbInfo);
            System.out.println("getMBeanInfo\t\t" + mbInfo);
            CompilationMXBean compilation = null ;

            compilation =
                    JMX.newMXBeanProxy(mbsc,
                    compilationName,
                    CompilationMXBean.class) ;
            System.out.println("getName\t\t"
                    + compilation.getName());
            boolean supported =
                    compilation.isCompilationTimeMonitoringSupported() ;
            System.out.println("isCompilationTimeMonitoringSupported\t\t"
                    + supported);

            if ( supported ) {
                System.out.println("getTotalCompilationTime\t\t"
                        + compilation.getTotalCompilationTime());
            }
        }

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 18
Source Project: jmxmon   Source File: ProxyClient.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized CompilationMXBean getCompilationMXBean() throws IOException {
    if (hasCompilationMXBean && compilationMBean == null) {
        compilationMBean =
            newPlatformMXBeanProxy(server, COMPILATION_MXBEAN_NAME,
                                   CompilationMXBean.class);
    }
    return compilationMBean;
}
 
Example 19
Source Project: jvmtop   Source File: ProxyClient.java    License: GNU General Public License v2.0 5 votes vote down vote up
public synchronized CompilationMXBean getCompilationMXBean() throws IOException {
    if (hasCompilationMXBean && compilationMBean == null) {
        compilationMBean =
            newPlatformMXBeanProxy(server, COMPILATION_MXBEAN_NAME,
                                   CompilationMXBean.class);
    }
    return compilationMBean;
}
 
Example 20
Source Project: kieker   Source File: CompilationSampler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected IMonitoringRecord[] createNewMonitoringRecords(final long timestamp, final String hostname, final String vmName,
		final IMonitoringController monitoringCtr) {
	if (!monitoringCtr.isProbeActivated(SignatureFactory.createJVMCompilationSignature())) {
		return new IMonitoringRecord[] {};
	}

	final CompilationMXBean compilationBean = ManagementFactory.getCompilationMXBean();

	return new IMonitoringRecord[] { new CompilationRecord(timestamp, hostname, vmName, compilationBean.getName(), compilationBean.getTotalCompilationTime()), };
}
 
Example 21
Source Project: systemds   Source File: Statistics.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the total time of asynchronous JIT compilation in milliseconds.
 * 
 * @return JIT compile time
 */
public static long getJITCompileTime(){
	long ret = -1; //unsupported
	CompilationMXBean cmx = ManagementFactory.getCompilationMXBean();
	if( cmx.isCompilationTimeMonitoringSupported() )
	{
		ret = cmx.getTotalCompilationTime();
		ret += jitCompileTime; //add from remote processes
	}
	return ret;
}
 
Example 22
Source Project: perfmon-agent   Source File: CompilerDataProviderTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test of getMXBeanClass method, of class CompilerDataProvider.
 */
public void testGetMXBeanClass() throws Exception {
    System.out.println("getMXBeanClass");
    CompilerDataProvider instance = new CompilerDataProvider(new EmulatorMBeanServerConnection(), false);
    Class expResult = CompilationMXBean.class;
    Class result = instance.getMXBeanClass();
    assertEquals(expResult, result);
}
 
Example 23
private static CompilationMXBean getCompilationMXBean() {
    return ManagementFactory.getCompilationMXBean();
}
 
Example 24
Source Project: metrics   Source File: CompilationGauge.java    License: Apache License 2.0 4 votes vote down vote up
public CompilationGauge(long timeout, TimeUnit timeoutUnit, CompilationMXBean mxBean) {
    super(timeout, timeoutUnit);
    this.mxBean = mxBean;
}
 
Example 25
private static CompilationMXBean getCompilationMXBean() {
    return ManagementFactory.getCompilationMXBean();
}
 
Example 26
Source Project: garmadon   Source File: CompilationStatistics.java    License: Apache License 2.0 4 votes vote down vote up
CompilationStatistics(CompilationMXBean compilation) {
    super(COMPILE_HEADER);
    this.compilation = compilation;
}
 
Example 27
Source Project: garmadon   Source File: HotspotCompilationStatistics.java    License: Apache License 2.0 4 votes vote down vote up
HotspotCompilationStatistics(CompilationMXBean compilation, HotspotCompilationMBean hsCompilation) {
    super(compilation);
    this.hsCompilation = hsCompilation;
}
 
Example 28
Source Project: jdk8u60   Source File: JvmCompilationImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static CompilationMXBean getCompilationMXBean() {
    return ManagementFactory.getCompilationMXBean();
}
 
Example 29
private static CompilationMXBean getCompilationMXBean() {
    return ManagementFactory.getCompilationMXBean();
}
 
Example 30
Source Project: netbeans   Source File: DiagnosticTask.java    License: Apache License 2.0 4 votes vote down vote up
private String logParams() {
        StringBuilder sb = new StringBuilder(500);
        sb.append("Diagnostic information\n");
        try {
            RuntimeMXBean         rmBean     = ManagementFactory.getRuntimeMXBean();
            CompilationMXBean     cmpMBean   = ManagementFactory.getCompilationMXBean();
//            ThreadMXBean          tmBean     = ManagementFactory.getThreadMXBean();
            MemoryMXBean          memoryBean = ManagementFactory.getMemoryMXBean();
            ClassLoadingMXBean    clMBean    = ManagementFactory.getClassLoadingMXBean();

//            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
//            ObjectName hsDiag = new ObjectName("com.sun.management:name=HotSpotDiagnostic");
//            com.sun.management.OperatingSystemMXBean sunOSMBean  =
//               ManagementFactory.getSunOperatingSystemMXBean();

//            Map<String, String> props = new TreeMap<String, String>(rmBean.getSystemProperties());
//            System.out.println("System properties");
//            for (Map.Entry<String, String> entry: props.entrySet()) {
//                System.out.println("Property: "+entry.getKey()+" Value: "+entry.getValue());
//            }
            sb.append("Input arguments:");
            for (String s: rmBean.getInputArguments()) {
                sb.append("\n\t").append(s);
            }
            
            if (cmpMBean != null) {
                sb.append("\nCompiler: "+cmpMBean.getName()).append('\n');
            }
            
            // Memory
            MemoryUsage usage = memoryBean.getHeapMemoryUsage();
            logMemoryUsage(sb, usage, "Heap memory");
            usage = memoryBean.getNonHeapMemoryUsage();
            logMemoryUsage(sb, usage, "Non heap memory");
            for (GarbageCollectorMXBean gcMBean: ManagementFactory.getGarbageCollectorMXBeans()) {
                sb.append("Garbage collector: ").append(gcMBean.getName())
                        .append(" (Collections=").append(gcMBean.getCollectionCount())
                        .append(" Total time spent=").append(formatTime(gcMBean.getCollectionTime()))
                        .append(")\n");
            }
            
            // classes
            int clsLoaded;
            long clsTotal, clsUnloaded;
            clsLoaded = clMBean.getLoadedClassCount();
            clsTotal = clMBean.getTotalLoadedClassCount();
            clsUnloaded = clMBean.getUnloadedClassCount();
            sb.append("Classes: loaded=").append(clsLoaded)
                    .append(" total loaded=").append(clsTotal)
                    .append(" unloaded ").append(clsUnloaded).append('\n');

//        } catch (MalformedObjectNameException ex) {
//            Logger.getLogger("global").log(Level.WARNING, null, ex);
        } catch (NullPointerException ex) {
            LOG.log(Level.WARNING, null, ex);
        }
        return sb.toString();
    }