Class CpuStat


  • @ThreadSafe
    public final class CpuStat
    extends java.lang.Object
    Utility to read CPU statistics from /proc/stat
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private CpuStat()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long getBootTime()
      Gets the boot time from /proc/stat
      static long getContextSwitches()
      Gets the number of context switches from /proc/stat
      static long getInterrupts()
      Gets the number of interrupts from /proc/stat
      static long[][] getProcessorCpuLoadTicks​(int logicalProcessorCount)
      Gets an arrya of Processor CPU ticks array from /proc/stat
      static long[] getSystemCpuLoadTicks()
      Gets the System CPU ticks array from /proc/stat
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CpuStat

        private CpuStat()
    • Method Detail

      • getSystemCpuLoadTicks

        public static long[] getSystemCpuLoadTicks()
        Gets the System CPU ticks array from /proc/stat
        Returns:
        Array of CPU ticks
      • getProcessorCpuLoadTicks

        public static long[][] getProcessorCpuLoadTicks​(int logicalProcessorCount)
        Gets an arrya of Processor CPU ticks array from /proc/stat
        Parameters:
        logicalProcessorCount - The number of logical processors, which corresponds to the number of lines to read from the file.
        Returns:
        Array of CPU ticks for each processor
      • getContextSwitches

        public static long getContextSwitches()
        Gets the number of context switches from /proc/stat
        Returns:
        The number of context switches if available, -1 otherwise
      • getInterrupts

        public static long getInterrupts()
        Gets the number of interrupts from /proc/stat
        Returns:
        The number of interrupts if available, -1 otherwise
      • getBootTime

        public static long getBootTime()
        Gets the boot time from /proc/stat
        Returns:
        The boot time if available, 0 otherwise