CpuUsageSampler { public static long getProcessCpuTimeNanos() { com.sun.management.OperatingSystemMXBean sunJdkOSMBean = OperatingSystem.getSunJdkOSMBean(); if (sunJdkOSMBean != null) { return sunJdkOSMBean.getProcessCpuTime(); } else { return -1; } } private  CpuUsageSampler(); static long getProcessCpuTimeNanos(); @JmxExport static synchronized void start(@JmxExport("sampleTimeMillis") final int sampleTime); @JmxExport static synchronized void stop(); @JmxExport static synchronized boolean isStarted();  }
@Test public void testCpuUsageSample() { Assume.assumeFalse(org.spf4j.base.Runtime.isWindows()); long processCpuTimeNanos = CpuUsageSampler.getProcessCpuTimeNanos(); Assert.assertTrue(processCpuTimeNanos > 0); }