Class LoadSampler

java.lang.Object
io.deephaven.util.process.LoadSampler

public final class LoadSampler extends Object
Periodic sampling of load statistics, including load average, cpu utilization percentage, and free memory.
  • Constructor Details

    • LoadSampler

      public LoadSampler(long loadSamplePeriodMillis, com.fishlib.io.logger.Logger log)
      Creates a new LoadSampler with the given sampling period and the associated log
      Parameters:
      loadSamplePeriodMillis - a period in milliseconds. New samples won't be taken more frequently than this value, unless forced.
      log - a logger where to execute maybeLog() calls
  • Method Details

    • toMiBStr

      public static String toMiBStr(long ramBytes)
      Format an amount of bytes as a MiBs string
      Parameters:
      ramBytes - the number of bytes
      Returns:
      a string with the number of MiB
    • isEnabled

      public boolean isEnabled()
    • getSample

      public boolean getSample(long nowMillis, LoadSampler.Sample toCopy)
      Gets a copy of the current sample. If the current sample is expired, it refreshes the current sample before making the copy.
      Parameters:
      nowMillis - the current time
      toCopy - the sample object where to copy the sampled data
      Returns:
      true if the current sample was refreshed, false otherwise.
    • refreshAndGetSample

      public void refreshAndGetSample(long nowMillis, LoadSampler.Sample toCopy)
    • getSampleOrNull

      public LoadSampler.Sample getSampleOrNull(long nowMillis)
      If the current sample is expired takes a new sample and returns a copy of that, null otherwise.
      Parameters:
      nowMillis - the current time
      Returns:
      A copy of a freshly taken sample.
    • getSample

      public LoadSampler.Sample getSample(long nowMillis)
      Gets a copy of the current sample. If the current sample is expired, it refreshes the current sample before making the copy.
      Parameters:
      nowMillis - the current time
      Returns:
      a newly created object with a copy of the sampled data
    • getConstants

      public LoadSampler.Constants getConstants()
    • maybeLog

      public void maybeLog()
      Log an info line with load sample data, but only if the current sample is expired, otherwise do nothing.