Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <a href="http://java.sun.com/javase/6/docs/api/java/lang/management/package-summary.html" rel="noreferrer">java.lang.management</a> package does give you a whole lot more info than Runtime - for example it will give you heap memory (<code>ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()</code>) separate from non-heap memory (<code>ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage()</code>).</p> <p>You can also get process CPU usage (without writing your own JNI code), but you need to cast the <code>java.lang.management.OperatingSystemMXBean</code> to a <code>com.sun.management.OperatingSystemMXBean</code>. This works on Windows and Linux, I haven't tested it elsewhere.</p> <p>For example ... call the get getCpuUsage() method more frequently to get more accurate readings.</p> <pre><code>public class PerformanceMonitor { private int availableProcessors = getOperatingSystemMXBean().getAvailableProcessors(); private long lastSystemTime = 0; private long lastProcessCpuTime = 0; public synchronized double getCpuUsage() { if ( lastSystemTime == 0 ) { baselineCounters(); return; } long systemTime = System.nanoTime(); long processCpuTime = 0; if ( getOperatingSystemMXBean() instanceof OperatingSystemMXBean ) { processCpuTime = ( (OperatingSystemMXBean) getOperatingSystemMXBean() ).getProcessCpuTime(); } double cpuUsage = (double) ( processCpuTime - lastProcessCpuTime ) / ( systemTime - lastSystemTime ); lastSystemTime = systemTime; lastProcessCpuTime = processCpuTime; return cpuUsage / availableProcessors; } private void baselineCounters() { lastSystemTime = System.nanoTime(); if ( getOperatingSystemMXBean() instanceof OperatingSystemMXBean ) { lastProcessCpuTime = ( (OperatingSystemMXBean) getOperatingSystemMXBean() ).getProcessCpuTime(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload