Java Code Examples for java.lang.management.ClassLoadingMXBean#getTotalLoadedClassCount()

The following examples show how to use java.lang.management.ClassLoadingMXBean#getTotalLoadedClassCount() . 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: ClassLoadingSampler.java    From kieker with 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.createJVMClassLoadSignature())) {
		return new IMonitoringRecord[] {};
	}

	final ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();
	return new IMonitoringRecord[] { new ClassLoadingRecord(timestamp, hostname, vmName, classLoadingBean.getTotalLoadedClassCount(),
			classLoadingBean.getLoadedClassCount(), classLoadingBean.getUnloadedClassCount()), };
}
 
Example 2
Source File: DiagnosticTask.java    From netbeans with 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();
    }
 
Example 3
Source File: ClassData.java    From openjdk-systemtest with Apache License 2.0 4 votes vote down vote up
/**
 * This method writes the data retrieved from the ClassLoading and
 * Compilation MXBeans to the ClassData's log using the MXBeans directly or
 * through a proxy.
 * 
 * @param clb
 *            The ClassLoading MXBean used to retrieve information about
 *            loaded classes.
 * @param cb
 *            The Compilation MXBean used to retrieve compilation
 *            information.
 * @param rb
 *            The Runtime MXBean used to retrieve general information about
 *            the runtime used.
 * @param append
 *            If the append value is true the data is appended to the log,
 *            otherwise the log is overwritten.
 */
public void writeData(ClassLoadingMXBean clb, CompilationMXBean cb, RuntimeMXBean rb, boolean append)
		throws UndeclaredThrowableException {
	if ((clb == null)) {
		Assert.fail("ClassLoadingMXBean is null");
	}

	openLogFile(append);
	DecimalFormat df = new DecimalFormat("#0.00"); // Print out all times to 2 d.p.

	try {
		// Record the time and whether the verbose output is enabled
		out.println("Class Loading and Compilation Information Retrieved at "
				+ DateFormat.getDateTimeInstance().format(new Date()));
		out.println("");

		// Get stats for the class loader, check the values and write them to a file
		int load_cls_cnt = clb.getLoadedClassCount();
		long unload_cls_cnt = clb.getUnloadedClassCount();
		long total_cls_cnt = clb.getTotalLoadedClassCount();

		// Check the class counts are valid
		checkClassCounts("proxy", load_cls_cnt, unload_cls_cnt, total_cls_cnt);

		// Print the results to the log
		out.println("CLASS LOADING STATS");
		out.println("  Current Loaded Class Count:  " + load_cls_cnt);
		out.println("  Total Unloaded Class Count:  " + unload_cls_cnt);
		out.println("  Total Loaded Class Count:    " + total_cls_cnt);
		out.print("  Verbose output enabled:      ");

		if (clb.isVerbose()) {
			out.println("Yes");
		} else {
			out.println("No");
		}
		out.println("");
		out.println("");

		// If there is a compiler get the info
		Map<String, String> props = rb.getSystemProperties();
		String sys_comp = props.get("java.compiler");

		if ((sys_comp != null) && (!(sys_comp.equals("")))) {
			// Get the info for the compiler and write to file
			out.println("COMPILER INFORMATION");

			String mxbean_comp = cb.getName();

			// Check if the compiler matches the compiler specified in the system properties
			checkCompiler("proxy", sys_comp, mxbean_comp);
			out.println("  Just-in-time (JIT) compiler: " + mxbean_comp);

			if (cb.isCompilationTimeMonitoringSupported()) {
				out.println("  Total Compilation Time:      " + df.format(cb.getTotalCompilationTime() * 1e-3)
				+ " seconds"); // Convert milliseconds to seconds
			}
			out.println("");
			out.println("");
		}
		closeLogFile();
	} catch (UnsupportedOperationException uoe) {
		Message.logOut("One of the operations you tried is not supported");
		uoe.printStackTrace();
		Assert.fail("One of the operations you tried is not supported");
	}
}
 
Example 4
Source File: TelemetryDataProvider.java    From jsonde with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void run() {

        TelemetryDataDto telemetryDataDto = new TelemetryDataDto();

        telemetryDataDto.time = System.currentTimeMillis();

        Runtime runtime = Runtime.getRuntime();

        telemetryDataDto.freeMemory = runtime.freeMemory();
        telemetryDataDto.maxMemory = runtime.maxMemory();
        telemetryDataDto.totalMemory = runtime.totalMemory();

        ClassLoadingMXBean classLoadingMXBean = ManagementFactory.getClassLoadingMXBean();

        telemetryDataDto.loadedClassCount = classLoadingMXBean.getLoadedClassCount();
        telemetryDataDto.classCount = classLoadingMXBean.getTotalLoadedClassCount();
        telemetryDataDto.unloadedClassCount = classLoadingMXBean.getUnloadedClassCount();

        CompilationMXBean compilationMXBean = ManagementFactory.getCompilationMXBean();

        telemetryDataDto.totalCompilationTime = compilationMXBean.getTotalCompilationTime();

        if (null != profiler)
            profiler.sendMessage(new TelemetryDataMessage(telemetryDataDto));

    }