(CentralProcessor processor)
| 207 | } |
| 208 | |
| 209 | private static void printCpu(CentralProcessor processor) { |
| 210 | oshi.add("Context Switches/Interrupts: " + processor.getContextSwitches() + " / " + processor.getInterrupts()); |
| 211 | |
| 212 | long[] prevTicks = processor.getSystemCpuLoadTicks(); |
| 213 | long[][] prevProcTicks = processor.getProcessorCpuLoadTicks(); |
| 214 | oshi.add("CPU, IOWait, and IRQ ticks @ 0 sec:" + Arrays.toString(prevTicks)); |
| 215 | // Wait a second... |
| 216 | Util.sleep(1000); |
| 217 | long[] ticks = processor.getSystemCpuLoadTicks(); |
| 218 | oshi.add("CPU, IOWait, and IRQ ticks @ 1 sec:" + Arrays.toString(ticks)); |
| 219 | long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()]; |
| 220 | long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()]; |
| 221 | long sys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()]; |
| 222 | long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()]; |
| 223 | long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()]; |
| 224 | long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()]; |
| 225 | long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()]; |
| 226 | long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()]; |
| 227 | long totalCpu = user + nice + sys + idle + iowait + irq + softirq + steal; |
| 228 | |
| 229 | oshi.add(String.format( |
| 230 | "User: %.1f%% Nice: %.1f%% System: %.1f%% Idle: %.1f%% IOwait: %.1f%% IRQ: %.1f%% SoftIRQ: %.1f%% Steal: %.1f%%", |
| 231 | 100d * user / totalCpu, 100d * nice / totalCpu, 100d * sys / totalCpu, 100d * idle / totalCpu, |
| 232 | 100d * iowait / totalCpu, 100d * irq / totalCpu, 100d * softirq / totalCpu, 100d * steal / totalCpu)); |
| 233 | oshi.add(String.format("CPU load: %.1f%%", processor.getSystemCpuLoadBetweenTicks(prevTicks) * 100)); |
| 234 | double[] loadAverage = processor.getSystemLoadAverage(3); |
| 235 | oshi.add("CPU load averages:" + (loadAverage[0] < 0 ? " N/A" : String.format(" %.2f", loadAverage[0])) |
| 236 | + (loadAverage[1] < 0 ? " N/A" : String.format(" %.2f", loadAverage[1])) |
| 237 | + (loadAverage[2] < 0 ? " N/A" : String.format(" %.2f", loadAverage[2]))); |
| 238 | // per core CPU |
| 239 | StringBuilder procCpu = new StringBuilder("CPU load per processor:"); |
| 240 | double[] load = processor.getProcessorCpuLoadBetweenTicks(prevProcTicks); |
| 241 | for (double avg : load) { |
| 242 | procCpu.append(String.format(" %.1f%%", avg * 100)); |
| 243 | } |
| 244 | oshi.add(procCpu.toString()); |
| 245 | long freq = processor.getProcessorIdentifier().getVendorFreq(); |
| 246 | if (freq > 0) { |
| 247 | oshi.add("Vendor Frequency: " + FormatUtil.formatHertz(freq)); |
| 248 | } |
| 249 | freq = processor.getMaxFreq(); |
| 250 | if (freq > 0) { |
| 251 | oshi.add("Max Frequency: " + FormatUtil.formatHertz(freq)); |
| 252 | } |
| 253 | long[] freqs = processor.getCurrentFreq(); |
| 254 | if (freqs[0] > 0) { |
| 255 | StringBuilder sb = new StringBuilder("Current Frequencies: "); |
| 256 | for (int i = 0; i < freqs.length; i++) { |
| 257 | if (i > 0) { |
| 258 | sb.append(", "); |
| 259 | } |
| 260 | sb.append(FormatUtil.formatHertz(freqs[i])); |
| 261 | } |
| 262 | oshi.add(sb.toString()); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | private static void printProcesses(OperatingSystem os, GlobalMemory memory) { |
no test coverage detected