@Override public void sense(final MetricRecorder.Context 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; }
public static void main(String[] args) { CompilationMXBean bean = ManagementFactory.getCompilationMXBean(); if (bean == null) { System.out.println("The compilation bean is not supported by this VM."); System.exit(-1); } System.out.println("Bean: " + bean); System.out.println("JIT compiler name: " + bean.getName()); boolean timeMonitoring = bean.isCompilationTimeMonitoringSupported(); System.out.println("Compilation time monitoring supported: " + timeMonitoring); if (timeMonitoring) { System.out.println("Compilation time: " + bean.getTotalCompilationTime() + "ms"); } }
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()))); } }
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.printf("\t%s jit time: %d ms%n", name, cBean.getTotalCompilationTime()); } else { out.println(normalizeTabularColonPos(String.format("%s-jit-time-ms : %d", normalizeName(name), cBean.getTotalCompilationTime()))); } }
/** * Creates the metadata for the * {@link java.lang.management.CompilationMXBean}. For this type of * platform bean the metadata covers : * <ul> * <li>3 attributes * <li>0 constructors * <li>0 operations * <li>0 notifications * </ul> * * @param result */ private static void addCompilationBeanInfo(HashMap<String, MBeanInfo> result) { // Attributes MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[3]; attributes[0] = new MBeanAttributeInfo("Name", String.class.getName(), "Name", true, false, false); attributes[1] = new MBeanAttributeInfo("TotalCompilationTime", Long.TYPE.getName(), "TotalCompilationTime", true, false, false); attributes[2] = new MBeanAttributeInfo( "CompilationTimeMonitoringSupported", Boolean.TYPE.getName(), "CompilationTimeMonitoringSupported", true, false, true); result.put(CompilationMXBean.class.getName(), new MBeanInfo( CompilationMXBeanImpl.class.getName(), CompilationMXBeanImpl.class.getName(), attributes, null, null, null)); }
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 ; }
public synchronized CompilationMXBean getCompilationMXBean() throws IOException { if (hasCompilationMXBean && compilationMBean == null) { compilationMBean = newPlatformMXBeanProxy(server, COMPILATION_MXBEAN_NAME, CompilationMXBean.class); } return compilationMBean; }
/** * 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; }
public void testGetCompilationMXBean() { CompilationMXBean mb = ManagementFactory.getCompilationMXBean(); assertNotNull(mb); // Verify that there is only instance of this bean CompilationMXBean mb2 = ManagementFactory.getCompilationMXBean(); assertNotNull(mb2); assertSame(mb, mb2); }
public void testNewPlatformMXBeanProxy_CompilationMXBean() throws Exception { CompilationMXBean proxy = ManagementFactory.newPlatformMXBeanProxy( ManagementFactory.getPlatformMBeanServer(), "java.lang:type=Compilation", CompilationMXBean.class); assertNotNull(proxy); CompilationMXBean mb = ManagementFactory.getCompilationMXBean(); assertEquals(mb.getName(), proxy.getName()); assertEquals(mb.isCompilationTimeMonitoringSupported(), proxy .isCompilationTimeMonitoringSupported()); }
@Override public boolean checkSupport(List<String> msgs) { CompilationMXBean comp = ManagementFactory.getCompilationMXBean(); if (comp.isCompilationTimeMonitoringSupported()) { return true; } else { msgs.add("The MXBean is available, but compilation time monitoring is disabled."); return false; } }
@Override public void beforeIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams) { CompilationMXBean comp = ManagementFactory.getCompilationMXBean(); try { startCompTime = comp.getTotalCompilationTime(); } catch (UnsupportedOperationException e) { startCompTime = -1; } }
@Override public Collection<? extends Result> afterIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams) { long compTime = -startCompTime; CompilationMXBean comp = ManagementFactory.getCompilationMXBean(); try { compTime += comp.getTotalCompilationTime(); } catch (UnsupportedOperationException e) { compTime = -1; } return Arrays.asList( new ProfilerResult("@compiler.time.profiled", compTime, "ms", AggregationPolicy.SUM), new ProfilerResult("@compiler.time.total", comp.getTotalCompilationTime(), "ms", AggregationPolicy.MAX) ); }
@Override public void run() { CompilationMXBean compilationMXBean = ManagementFactory.getCompilationMXBean(); if (compilationMXBean == null) { output.println("Couldn't get the runtime bean!"); return; } output.println(compilationMXBean.getTotalCompilationTime()); }
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(); }
private static CompilationMXBean getCompilationMXBean() { return ManagementFactory.getCompilationMXBean(); }
public static void main(String[] args) { CompilationMXBean compilationMXBean = ManagementFactory.getCompilationMXBean(); System.out.println("Total compilation time: " + compilationMXBean.getTotalCompilationTime()); }
protected Class<CompilationMXBean> getMXBeanClass() { return CompilationMXBean.class; }
protected long getValueFromBean(Object bean) { return ((CompilationMXBean) bean).getTotalCompilationTime(); }