/** * Attempts to enable thread contention monitoring. * * @return true if thread contention monitoring is enabled, false otherwise */ protected static boolean enableContentionTimes() { if (!TMX.isThreadContentionMonitoringSupported()) return false; if (TMX.isThreadContentionMonitoringEnabled()) return true; try { TMX.setThreadContentionMonitoringEnabled(true); } catch (Throwable t) { } return TMX.isThreadContentionMonitoringEnabled(); }
/** * 利用するメソッド、MXBeanの初期化を行います。 * * @param config Javelinの設定 */ public static void init(JavelinConfig config) { try { // OracleASを利用した場合、Thead#getThreadID()からスレッドIDを取得すると、 // 常に固定値が出力されるので、Threadクラスのフィールドから取得する。 // また、IBMのVMを利用した利用した場合には、"tid"というフィールドがないため、"uniqueId"を利用する。 try { tidField__ = Thread.class.getDeclaredField("tid"); } catch (SecurityException se) { SystemLogger.getInstance().debug(se); } catch (NoSuchFieldException nsfe) { tidField__ = Thread.class.getDeclaredField("uniqueId"); } try { getLockedSynchronizersMethod__ = ThreadInfo.class.getDeclaredMethod("getLockedSynchronizers"); getLockInfoMethod__ = ThreadInfo.class.getDeclaredMethod("getLockInfo"); getLockedMonitorsMethod__ = ThreadInfo.class.getDeclaredMethod("getLockedMonitors"); try { Class<?> monitorInfoClass = Class.forName("java.lang.management.MonitorInfo"); getLockedStackDepthMethod__ = monitorInfoClass.getDeclaredMethod("getLockedStackDepth"); } catch (ClassNotFoundException cne) { SystemLogger.getInstance().debug(cne); } } catch (SecurityException se) { SystemLogger.getInstance().debug(se); } catch (NoSuchMethodException nme) { SystemLogger.getInstance().debug(nme); } if (tidField__ != null) { tidField__.setAccessible(true); } if (config.isThreadContentionMonitor() && threadMBean__.isThreadContentionMonitoringSupported()) { threadMBean__.setThreadContentionMonitoringEnabled(true); } if (threadMBean__.isThreadCpuTimeSupported()) { threadMBean__.setThreadCpuTimeEnabled(true); } } catch (Exception ex) { SystemLogger.getInstance().warn(ex); } }
public ThreadEfficiencyMonitor() { bean = ManagementFactory.getThreadMXBean(); // get the bean, and start tracking if (bean.isThreadContentionMonitoringSupported()) bean.setThreadContentionMonitoringEnabled(true); else logger.warn( "Thread contention monitoring not supported, we cannot track GATK multi-threaded efficiency"); // bean.setThreadCpuTimeEnabled(true); if (bean.isThreadCpuTimeSupported()) bean.setThreadCpuTimeEnabled(true); else logger.warn( "Thread CPU monitoring not supported, we cannot track GATK multi-threaded efficiency"); // initialize times to 0 for (final State state : State.values()) times.put(state, 0l); }
static { String logging = "hazelcast.logging.type"; if (System.getProperty(logging) == null) { System.setProperty(logging, "log4j"); } if (System.getProperty(TestEnvironment.HAZELCAST_TEST_USE_NETWORK) == null) { System.setProperty(TestEnvironment.HAZELCAST_TEST_USE_NETWORK, "false"); } System.setProperty("hazelcast.phone.home.enabled", "false"); System.setProperty("hazelcast.mancenter.enabled", "false"); System.setProperty("hazelcast.wait.seconds.before.join", "1"); System.setProperty("hazelcast.local.localAddress", "127.0.0.1"); System.setProperty("java.net.preferIPv4Stack", "true"); // randomize multicast group Random rand = new Random(); int g1 = rand.nextInt(255); int g2 = rand.nextInt(255); int g3 = rand.nextInt(255); System.setProperty("hazelcast.multicast.group", "224." + g1 + "." + g2 + "." + g3); ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); boolean threadCPUTimeInfoAvailable = false; if (threadMXBean.isThreadCpuTimeSupported()) { try { threadMXBean.setThreadCpuTimeEnabled(true); threadCPUTimeInfoAvailable = true; } catch (Throwable t) { } } THREAD_CPU_TIME_INFO_AVAILABLE = threadCPUTimeInfoAvailable; boolean threadContentionInfoAvailable = false; if (threadMXBean.isThreadContentionMonitoringSupported()) { try { threadMXBean.setThreadContentionMonitoringEnabled(true); threadContentionInfoAvailable = true; } catch (Throwable t) { } } THREAD_CONTENTION_INFO_AVAILABLE = threadContentionInfoAvailable; }
/** * Create a new factory generating threads whose runtime and contention behavior is tracked in * this factory. * * @param nThreadsToCreate the number of threads we will create in the factory before it's * considered complete // TODO -- remove argument when we figure out how to implement this * capability */ public StateMonitoringThreadFactory(final int nThreadsToCreate) { if (nThreadsToCreate <= 0) throw new IllegalArgumentException("nThreadsToCreate <= 0: " + nThreadsToCreate); this.nThreadsToCreate = nThreadsToCreate; activeThreads = new ArrayList<Thread>(nThreadsToCreate); // initialize times to 0 for (final Thread.State state : Thread.State.values()) times.put(state, 0l); // get the bean, and start tracking bean = ManagementFactory.getThreadMXBean(); if (bean.isThreadContentionMonitoringSupported()) bean.setThreadContentionMonitoringEnabled(true); else logger.warn( "Thread contention monitoring not supported, we cannot track GATK multi-threaded efficiency"); // bean.setThreadCpuTimeEnabled(true); countDownLatch = new CountDownLatch(nThreadsToCreate); }
/** * Retrieve a JVM information text formatted using the given StringManager. * * @param requestedSm the StringManager to use * @return the formatted JVM information text */ private static String getVMInfo(StringManager requestedSm) { StringBuilder sb = new StringBuilder(); synchronized (timeformat) { sb.append(timeformat.format(new Date())); } sb.append(CRLF); sb.append(requestedSm.getString("diagnostics.vmInfoRuntime")); sb.append(":" + CRLF); sb.append(INDENT1 + "vmName: " + runtimeMXBean.getVmName() + CRLF); sb.append(INDENT1 + "vmVersion: " + runtimeMXBean.getVmVersion() + CRLF); sb.append(INDENT1 + "vmVendor: " + runtimeMXBean.getVmVendor() + CRLF); sb.append(INDENT1 + "specName: " + runtimeMXBean.getSpecName() + CRLF); sb.append(INDENT1 + "specVersion: " + runtimeMXBean.getSpecVersion() + CRLF); sb.append(INDENT1 + "specVendor: " + runtimeMXBean.getSpecVendor() + CRLF); sb.append( INDENT1 + "managementSpecVersion: " + runtimeMXBean.getManagementSpecVersion() + CRLF); sb.append(INDENT1 + "name: " + runtimeMXBean.getName() + CRLF); sb.append(INDENT1 + "startTime: " + runtimeMXBean.getStartTime() + CRLF); sb.append(INDENT1 + "uptime: " + runtimeMXBean.getUptime() + CRLF); sb.append( INDENT1 + "isBootClassPathSupported: " + runtimeMXBean.isBootClassPathSupported() + CRLF); sb.append(CRLF); sb.append(requestedSm.getString("diagnostics.vmInfoOs")); sb.append(":" + CRLF); sb.append(INDENT1 + "name: " + operatingSystemMXBean.getName() + CRLF); sb.append(INDENT1 + "version: " + operatingSystemMXBean.getVersion() + CRLF); sb.append(INDENT1 + "architecture: " + operatingSystemMXBean.getArch() + CRLF); sb.append( INDENT1 + "availableProcessors: " + operatingSystemMXBean.getAvailableProcessors() + CRLF); sb.append( INDENT1 + "systemLoadAverage: " + operatingSystemMXBean.getSystemLoadAverage() + CRLF); sb.append(CRLF); sb.append(requestedSm.getString("diagnostics.vmInfoThreadMxBean")); sb.append(":" + CRLF); sb.append( INDENT1 + "isCurrentThreadCpuTimeSupported: " + threadMXBean.isCurrentThreadCpuTimeSupported() + CRLF); sb.append( INDENT1 + "isThreadCpuTimeSupported: " + threadMXBean.isThreadCpuTimeSupported() + CRLF); sb.append(INDENT1 + "isThreadCpuTimeEnabled: " + threadMXBean.isThreadCpuTimeEnabled() + CRLF); sb.append( INDENT1 + "isObjectMonitorUsageSupported: " + threadMXBean.isObjectMonitorUsageSupported() + CRLF); sb.append( INDENT1 + "isSynchronizerUsageSupported: " + threadMXBean.isSynchronizerUsageSupported() + CRLF); sb.append( INDENT1 + "isThreadContentionMonitoringSupported: " + threadMXBean.isThreadContentionMonitoringSupported() + CRLF); sb.append( INDENT1 + "isThreadContentionMonitoringEnabled: " + threadMXBean.isThreadContentionMonitoringEnabled() + CRLF); sb.append(CRLF); sb.append(requestedSm.getString("diagnostics.vmInfoThreadCounts")); sb.append(":" + CRLF); sb.append(INDENT1 + "daemon: " + threadMXBean.getDaemonThreadCount() + CRLF); sb.append(INDENT1 + "total: " + threadMXBean.getThreadCount() + CRLF); sb.append(INDENT1 + "peak: " + threadMXBean.getPeakThreadCount() + CRLF); sb.append(INDENT1 + "totalStarted: " + threadMXBean.getTotalStartedThreadCount() + CRLF); sb.append(CRLF); sb.append(requestedSm.getString("diagnostics.vmInfoStartup")); sb.append(":" + CRLF); for (String arg : runtimeMXBean.getInputArguments()) { sb.append(INDENT1 + arg + CRLF); } sb.append(CRLF); sb.append(requestedSm.getString("diagnostics.vmInfoPath")); sb.append(":" + CRLF); sb.append(INDENT1 + "bootClassPath: " + runtimeMXBean.getBootClassPath() + CRLF); sb.append(INDENT1 + "classPath: " + runtimeMXBean.getClassPath() + CRLF); sb.append(INDENT1 + "libraryPath: " + runtimeMXBean.getLibraryPath() + CRLF); sb.append(CRLF); sb.append(requestedSm.getString("diagnostics.vmInfoClassLoading")); sb.append(":" + CRLF); sb.append(INDENT1 + "loaded: " + classLoadingMXBean.getLoadedClassCount() + CRLF); sb.append(INDENT1 + "unloaded: " + classLoadingMXBean.getUnloadedClassCount() + CRLF); sb.append(INDENT1 + "totalLoaded: " + classLoadingMXBean.getTotalLoadedClassCount() + CRLF); sb.append(INDENT1 + "isVerbose: " + classLoadingMXBean.isVerbose() + CRLF); sb.append(CRLF); sb.append(requestedSm.getString("diagnostics.vmInfoClassCompilation")); sb.append(":" + CRLF); sb.append(INDENT1 + "name: " + compilationMXBean.getName() + CRLF); sb.append( INDENT1 + "totalCompilationTime: " + compilationMXBean.getTotalCompilationTime() + CRLF); sb.append( INDENT1 + "isCompilationTimeMonitoringSupported: " + compilationMXBean.isCompilationTimeMonitoringSupported() + CRLF); sb.append(CRLF); for (MemoryManagerMXBean mbean : memoryManagerMXBeans) { sb.append(requestedSm.getString("diagnostics.vmInfoMemoryManagers", mbean.getName())); sb.append(":" + CRLF); sb.append(INDENT1 + "isValid: " + mbean.isValid() + CRLF); sb.append(INDENT1 + "mbean.getMemoryPoolNames: " + CRLF); String[] names = mbean.getMemoryPoolNames(); Arrays.sort(names); for (String name : names) { sb.append(INDENT2 + name + CRLF); } sb.append(CRLF); } for (GarbageCollectorMXBean mbean : garbageCollectorMXBeans) { sb.append(requestedSm.getString("diagnostics.vmInfoGarbageCollectors", mbean.getName())); sb.append(":" + CRLF); sb.append(INDENT1 + "isValid: " + mbean.isValid() + CRLF); sb.append(INDENT1 + "mbean.getMemoryPoolNames: " + CRLF); String[] names = mbean.getMemoryPoolNames(); Arrays.sort(names); for (String name : names) { sb.append(INDENT2 + name + CRLF); } sb.append(INDENT1 + "getCollectionCount: " + mbean.getCollectionCount() + CRLF); sb.append(INDENT1 + "getCollectionTime: " + mbean.getCollectionTime() + CRLF); sb.append(CRLF); } sb.append(requestedSm.getString("diagnostics.vmInfoMemory")); sb.append(":" + CRLF); sb.append(INDENT1 + "isVerbose: " + memoryMXBean.isVerbose() + CRLF); sb.append( INDENT1 + "getObjectPendingFinalizationCount: " + memoryMXBean.getObjectPendingFinalizationCount() + CRLF); sb.append(formatMemoryUsage("heap", memoryMXBean.getHeapMemoryUsage())); sb.append(formatMemoryUsage("non-heap", memoryMXBean.getNonHeapMemoryUsage())); sb.append(CRLF); for (MemoryPoolMXBean mbean : memoryPoolMXBeans) { sb.append(requestedSm.getString("diagnostics.vmInfoMemoryPools", mbean.getName())); sb.append(":" + CRLF); sb.append(INDENT1 + "isValid: " + mbean.isValid() + CRLF); sb.append(INDENT1 + "getType: " + mbean.getType() + CRLF); sb.append(INDENT1 + "mbean.getMemoryManagerNames: " + CRLF); String[] names = mbean.getMemoryManagerNames(); Arrays.sort(names); for (String name : names) { sb.append(INDENT2 + name + CRLF); } sb.append(INDENT1 + "isUsageThresholdSupported: " + mbean.isUsageThresholdSupported() + CRLF); try { sb.append(INDENT1 + "isUsageThresholdExceeded: " + mbean.isUsageThresholdExceeded() + CRLF); } catch (UnsupportedOperationException ex) { // IGNORE } sb.append( INDENT1 + "isCollectionUsageThresholdSupported: " + mbean.isCollectionUsageThresholdSupported() + CRLF); try { sb.append( INDENT1 + "isCollectionUsageThresholdExceeded: " + mbean.isCollectionUsageThresholdExceeded() + CRLF); } catch (UnsupportedOperationException ex) { // IGNORE } try { sb.append(INDENT1 + "getUsageThreshold: " + mbean.getUsageThreshold() + CRLF); } catch (UnsupportedOperationException ex) { // IGNORE } try { sb.append(INDENT1 + "getUsageThresholdCount: " + mbean.getUsageThresholdCount() + CRLF); } catch (UnsupportedOperationException ex) { // IGNORE } try { sb.append( INDENT1 + "getCollectionUsageThreshold: " + mbean.getCollectionUsageThreshold() + CRLF); } catch (UnsupportedOperationException ex) { // IGNORE } try { sb.append( INDENT1 + "getCollectionUsageThresholdCount: " + mbean.getCollectionUsageThresholdCount() + CRLF); } catch (UnsupportedOperationException ex) { // IGNORE } sb.append(formatMemoryUsage("current", mbean.getUsage())); sb.append(formatMemoryUsage("collection", mbean.getCollectionUsage())); sb.append(formatMemoryUsage("peak", mbean.getPeakUsage())); sb.append(CRLF); } sb.append(requestedSm.getString("diagnostics.vmInfoSystem")); sb.append(":" + CRLF); Map<String, String> props = runtimeMXBean.getSystemProperties(); ArrayList<String> keys = new ArrayList<String>(props.keySet()); Collections.sort(keys); for (String prop : keys) { sb.append(INDENT1 + prop + ": " + props.get(prop) + CRLF); } sb.append(CRLF); sb.append(requestedSm.getString("diagnostics.vmInfoLogger")); sb.append(":" + CRLF); List<String> loggers = loggingMXBean.getLoggerNames(); Collections.sort(loggers); for (String logger : loggers) { sb.append( INDENT1 + logger + ": level=" + loggingMXBean.getLoggerLevel(logger) + ", parent=" + loggingMXBean.getParentLoggerName(logger) + CRLF); } sb.append(CRLF); return sb.toString(); }