java.util.logging.LoggingMXBean Java Examples

The following examples show how to use java.util.logging.LoggingMXBean. 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 check out the related API usage on the sidebar.
Example #1
Source File: JvmMXBeansFactory.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an MXBean proxy for the logging system of the JVM.
 */
public synchronized LoggingMXBean getLoggingMXBean() {
    if (mbsc != null && loggingMXBean == null) {
        loggingMXBean = getMXBean(LogManager.LOGGING_MXBEAN_NAME, LoggingMXBean.class);
    }
    return loggingMXBean;
}
 
Example #2
Source File: ClassProfiler.java    From openjdk-systemtest with Apache License 2.0 4 votes vote down vote up
private void getStatsViaProxy() {
	RuntimeMXBean runtimeBean = null;
	OperatingSystemMXBean osBean = null;
	LoggingMXBean logBean = null;
	ClassLoadingMXBean classBean = null;
	CompilationMXBean compBean = null;

	// Get the proxies for the runtime, os, log and class MXBeans
	try {
		runtimeBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, ManagementFactory.RUNTIME_MXBEAN_NAME,
				RuntimeMXBean.class);

		osBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME,
				OperatingSystemMXBean.class);

		logBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, LogManager.LOGGING_MXBEAN_NAME,
				LoggingMXBean.class);

		classBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, ManagementFactory.CLASS_LOADING_MXBEAN_NAME,
				ClassLoadingMXBean.class);

		// Check the compiler is being used and get the compilation MXBean
		Map<String, String> props = runtimeBean.getSystemProperties();
		String sys_comp = props.get("java.compiler");

		if ((sys_comp != null) && (!(sys_comp.equals("")))) {
			compBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, ManagementFactory.COMPILATION_MXBEAN_NAME,
					CompilationMXBean.class);
		}
	} catch (IOException ioe) {
		Message.logOut("A communication problem occurred when accessing the MBeanServerConnection");
		ioe.printStackTrace();
		Assert.fail("A communication problem occurred when accessing the MBeanServerConnection");
	}

	try {
		Message.logOut("Starting to write data");
		// Record the environment data in the log
		this.envData.writeData(runtimeBean, osBean, logBean, false);

		// Record the number of class loaded over time in a csv and record
		// the class data in the log every 10 seconds
		int secondsCnt = 0;
		int writesCnt = 0;
		while (writesCnt < 30) {
			// Write out the threadData every 10 seconds
			if (secondsCnt == 10) {
				System.out.print(".");
				this.classData.writeData(classBean, compBean, runtimeBean, true);
				secondsCnt = 0;
				writesCnt++;
			}
			this.recordClassStats(runtimeBean, classBean);
			Thread.sleep(1000);
			secondsCnt++;
		}
	} catch (InterruptedException ie) {
		Message.logOut("The sleeping profiler was interrupted");
		ie.printStackTrace();
		Assert.fail("The sleeping profiler was interrupted");
	} catch (UndeclaredThrowableException ue) {
		Throwable cause = ue.getCause();
		Class<ConnectException> connectExcept = ConnectException.class;
		Class<UnmarshalException> unmarshalExcept = UnmarshalException.class;

		if (connectExcept.isInstance(cause) || unmarshalExcept.isInstance(cause)) {
			
			// If the exception was caused by a Connect or Unmarshal
			// Exception, assume the monitored JVM has finished. 
			this.closeCSVFile();
			Message.logOut("Exiting as JVM we are connected to has finished");
			Assert.fail("Exiting as JVM we are connected to has finished");
		} else {
			Message.logOut(ue.getMessage());
			ue.printStackTrace();
			Assert.fail(ue.getMessage());
		}
	} finally {
		this.closeCSVFile();
	}
}
 
Example #3
Source File: MemoryProfiler.java    From openjdk-systemtest with Apache License 2.0 4 votes vote down vote up
private void getStatsViaProxy() {
	RuntimeMXBean runtimeBean = null;
	OperatingSystemMXBean osBean = null;
	LoggingMXBean logBean = null;
	MemoryMXBean memoryBean = null;
	List<MemoryPoolMXBean> memPoolBeans = new ArrayList<MemoryPoolMXBean>();
	List<MemoryManagerMXBean> memMgrBeans = new ArrayList<MemoryManagerMXBean>();
	List<GarbageCollectorMXBean> gcBeans = new ArrayList<GarbageCollectorMXBean>();

	// Get the proxies for the runtime, os, log, memory MXBeans
	try {
		runtimeBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, ManagementFactory.RUNTIME_MXBEAN_NAME,
				RuntimeMXBean.class);
		osBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME,
				OperatingSystemMXBean.class);
		logBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, LogManager.LOGGING_MXBEAN_NAME,
				LoggingMXBean.class);
		memoryBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, ManagementFactory.MEMORY_MXBEAN_NAME,
				MemoryMXBean.class);

		Set<?> memPoolNames  = this.mbs.queryNames(new ObjectName(ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",*"), null);

		// Get a MXBean Proxy for each of the names returned, use the proxy to access the MXBeanS
		for (Object memPoolName : memPoolNames){
			ObjectName memPool = (ObjectName) memPoolName;
			MemoryPoolMXBean memPoolBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, memPool.toString(),
					MemoryPoolMXBean.class);
			memPoolBeans.add(memPoolBean);
		}

		Set<?> memMgrNames  = this.mbs.queryNames(new ObjectName(ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE + ",*"), null);

		// Get a MXBean Proxy for each of the names returned, use the proxy to access the MXBeanS
		for (Object memMgrName : memMgrNames){
			ObjectName memMgr = (ObjectName) memMgrName;
			MemoryManagerMXBean memMgrBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, memMgr.toString(),
					MemoryManagerMXBean.class);
			memMgrBeans.add(memMgrBean);
		}

		Set<?> gcNames  = this.mbs.queryNames(new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*"), null);

		// Get a MXBean Proxy for each of the names returned, use the proxy to access the MXBeanS
		for (Object gcName : gcNames){
			ObjectName gc = (ObjectName) gcName;
			GarbageCollectorMXBean gcBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, gc.toString(),
					GarbageCollectorMXBean.class);
			gcBeans.add(gcBean);
		}
	} catch (IOException ioe) {
		ioe.printStackTrace();
		Assert.fail("A communication problem occurred when accessing the MBeanServerConnection");
	} catch (MalformedObjectNameException mone) {
		mone.printStackTrace();
		Assert.fail("Problem with creating the ObjectName for a MXBean");
	}

	try {
		Message.logOut("Starting to write data");
		this.envData.writeData (runtimeBean, osBean, logBean, false);

		int secondsCnt = 0;
		int writesCnt = 0;
		while (writesCnt < 30) {
			// Write out the methodData every 10 seconds
			if (secondsCnt == 10) {
				System.out.print(".");
				this.memoryData.writeData(memoryBean, memMgrBeans, memPoolBeans, gcBeans, true);
				secondsCnt = 0;
				writesCnt++;
			}
			this.recordMemoryStats(runtimeBean, memoryBean, writesCnt);
			Thread.sleep(1000);
			secondsCnt++;
		}
	} catch (InterruptedException ie) {
		ie.printStackTrace();
		Assert.fail("The sleeping profiler was interrupted");
	} catch (UndeclaredThrowableException ue) {
		// If the exception was caused by a Connect or Unmarshal Exception, assume the 
		// monitored JVM has finished.
		Throwable cause = ue.getCause();
		Class<ConnectException>     connectExcept = ConnectException.class;
		Class<UnmarshalException>     unmarshalExcept = UnmarshalException.class;

		if (connectExcept.isInstance(cause) || unmarshalExcept.isInstance(cause)) {
			this.closeCSVFile();
			Message.logOut("Exiting as JVM we are connected to has finished");
		}
		else { 
			Message.logOut("Rethrowing UndeclaredThrowableException");
		}
		Assert.fail();
	} finally {
		this.closeCSVFile();
	}
}
 
Example #4
Source File: ThreadProfiler.java    From openjdk-systemtest with Apache License 2.0 4 votes vote down vote up
private void getStatsViaProxy() {
	RuntimeMXBean runtimeBean = null;
	OperatingSystemMXBean osBean = null;
	LoggingMXBean logBean = null;
	ThreadMXBean threadBean = null;
	int stackDepth = 8;

	// Get the runtime, os, log and thread MXBeans
	try {
		runtimeBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, 
				ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
		osBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, 
				ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class);
		logBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, 
				LogManager.LOGGING_MXBEAN_NAME, LoggingMXBean.class);
		threadBean = ManagementFactory.newPlatformMXBeanProxy(this.mbs, 
				ManagementFactory.THREAD_MXBEAN_NAME, ThreadMXBean.class);
	} catch (IOException ioe) {
		Message.logOut("A communication problem occurred when accessing the MBeanServerConnection");
		ioe.printStackTrace();
		Assert.fail("A communication problem occurred when accessing the MBeanServerConnection");
	}

	try {
		Message.logOut("Starting to write data");
		this.envData.writeData(runtimeBean, osBean, logBean, false);
		int secondsCnt = 0;
		int writesCnt = 0;
		while (writesCnt < 30) {
			// Write out the threadData 10 seconds
			if (secondsCnt == 10) {
				System.out.print(".");
				this.threadData.writeData(threadBean, stackDepth, true);
				secondsCnt = 0;
				writesCnt++;
			}
			this.recordThreadStats(runtimeBean, threadBean);
			Thread.sleep(1000);
			secondsCnt++;
		}
	} catch (InterruptedException ie) {
		Message.logOut("The sleeping profiler was interrupted");
		ie.printStackTrace();
		Assert.fail("The sleeping profiler was interrupted");
	} catch (UndeclaredThrowableException ue) {
		// If the exception was caused by a Connect or Unmarshal Exception
		// assume the monitored JVM has finished.
		Throwable cause = ue.getCause();
		Class<ConnectException> connectExcept = ConnectException.class;
		Class<UnmarshalException> unmarshalExcept = UnmarshalException.class;

		if (connectExcept.isInstance(cause) || unmarshalExcept.isInstance(cause)) {
			this.closeCSVFile();
			Message.logOut("Exiting as JVM we are connected to has finished");
			Assert.fail("Exiting as JVM we are connected to has finished");
		} else {
			Message.logOut(ue.getMessage());
			ue.printStackTrace();
			Assert.fail(ue.getMessage());
		}
	} finally {
		this.closeCSVFile();
	}
}
 
Example #5
Source File: JvmMXBeans.java    From visualvm with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns <tt>LoggingMXBean</tt> for managing loggers. 
 *
 * @return a {@link LoggingMXBean} object for 
 * the Java virtual machine.
 */
public LoggingMXBean getLoggingMXBean();