void (CentralProcessor processor) { long[] prevTicks = processor.getSystemCpuLoadTicks(); long[][] prevProcTicks = processor.getProcessorCpuLoadTicks(); // Wait a second... Util.sleep(1000); long[] ticks = processor.getSystemCpuLoadTicks(); long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()]; long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()]; long sys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()]; long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()]; long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()]; long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()]; long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()]; long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()]; long totalCpu = user + nice + sys + idle + iowait + irq + softirq + steal; info.add(String.format( "User: %.1f%% Nice: %.1f%% System: %.1f%% Idle: %.1f%% IOwait: %.1f%% IRQ: %.1f%% SoftIRQ: %.1f%% Steal: %.1f%%", 100d * user / totalCpu, 100d * nice / totalCpu, 100d * sys / totalCpu, 100d * idle / totalCpu, 100d * iowait / totalCpu, 100d * irq / totalCpu, 100d * softirq / totalCpu, 100d * steal / totalCpu)); info.add(String.format("CPU load: %.1f%%", processor.getSystemCpuLoadBetweenTicks(prevTicks) * 100)); double[] loadAverage = processor.getSystemLoadAverage(3); info.add("CPU load averages:" + (loadAverage[0] < 0 ? " N/A" : String.format(" %.2f", loadAverage[0])) + (loadAverage[1] < 0 ? " N/A" : String.format(" %.2f", loadAverage[1])) + (loadAverage[2] < 0 ? " N/A" : String.format(" %.2f", loadAverage[2]))); // per core CPU StringBuilder procCpu = new StringBuilder("CPU load per processor:"); double[] load = processor.getProcessorCpuLoadBetweenTicks(prevProcTicks); for (double avg : load) { procCpu.append(String.format(" %.1f%%", avg * 100)); } info.add(procCpu.toString()); long freq = processor.getProcessorIdentifier().getVendorFreq(); if (freq > 0) { info.add("Vendor Frequency: " + FormatUtil.formatHertz(freq)); } freq = processor.getMaxFreq(); if (freq > 0) { info.add("Max Frequency: " + FormatUtil.formatHertz(freq)); } long[] freqs = processor.getCurrentFreq(); if (freqs[0] > 0) { StringBuilder sb = new StringBuilder("Current Frequencies: "); for (int i = 0; i < freqs.length; i++) { if (i > 0) { sb.append(", "); } sb.append(FormatUtil.formatHertz(freqs[i])); } info.add(sb.toString()); } }