Class SystemLoadMonitor

java.lang.Object
frc.spectrumLib.telemetry.SystemLoadMonitor

public class SystemLoadMonitor extends Object
Watches the things that made the robot fall behind on 2026-09-05 and says so on the dashboard.

That day the roboRIO CPU sat at 92 to 95 percent and the loop ran at 30 ms, and nothing on the Driver Station said so: the overrun watchdog is set to 200 ms and the CPU figure is buried in the DS log viewer. This publishes the numbers once a second and raises an Alert when one of them has been bad for long enough to matter:

  • CPU from /proc/stat, alert after 10.0 s at or above 85.0 percent.
  • Loop overruns: the share of loops longer than ms, alert after 5.0 s above 50.0 percent.
  • Loop stall: a single loop over 200.0 ms while enabled, latched for 10.0 s so it is seen. Stalls while disabled are PathPlanner warmup and are ignored.
  • GC: collector time from the JVM, alert when one second carried 100.0 ms or more of it while enabled.
  • Memory: MemAvailable from /proc/meminfo, alert after 10.0 s under 24.0 MB.

Call periodic() once per loop, first thing in robotPeriodic(). Per loop it does a subtraction; once a second it reads two small files under /proc. Off the rio (no /proc) the CPU and memory channels go quiet and the rest keeps working.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    CPU percent that starts the CPU alert clock.
    static final double
    CPU percent below which the CPU alert clears.
    static final double
    Seconds the CPU must stay high before the alert shows.
    static final double
    Collector milliseconds inside one second, while enabled, that raise the GC alert.
    static final double
    How long a one-shot alert (stall, GC) stays up so someone sees it.
    static final double
    Share of overrunning loops that starts the loop alert timer.
    static final double
    Share of overrunning loops below which the loop alert clears.
    static final double
    A loop longer than this many periods counts as an overrun.
    static final double
    Seconds the overrun share must stay high before the loop alert shows.
    static final double
    A single enabled loop longer than this is a stall worth an error.
    static final double
    Available memory below which the memory alert clock starts.
    static final double
    Seconds memory must stay low before the alert shows.
    static final double
    Seconds between samples and dashboard publishes.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Records this loop and, once a second, samples the system and updates the alerts.
    static void
    Prints the thread ids that appeared since the last call, labelled, to the console (the journal on the robot).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SAMPLE_PERIOD_SECONDS

      public static final double SAMPLE_PERIOD_SECONDS
      Seconds between samples and dashboard publishes.
      See Also:
    • LOOP_OVERRUN_FACTOR

      public static final double LOOP_OVERRUN_FACTOR
      A loop longer than this many periods counts as an overrun.
      See Also:
    • LOOP_OVERRUN_ALERT_PERCENT

      public static final double LOOP_OVERRUN_ALERT_PERCENT
      Share of overrunning loops that starts the loop alert timer.
      See Also:
    • LOOP_OVERRUN_CLEAR_PERCENT

      public static final double LOOP_OVERRUN_CLEAR_PERCENT
      Share of overrunning loops below which the loop alert clears.
      See Also:
    • LOOP_OVERRUN_HOLD_SECONDS

      public static final double LOOP_OVERRUN_HOLD_SECONDS
      Seconds the overrun share must stay high before the loop alert shows.
      See Also:
    • LOOP_STALL_MS

      public static final double LOOP_STALL_MS
      A single enabled loop longer than this is a stall worth an error.
      See Also:
    • CPU_ALERT_PERCENT

      public static final double CPU_ALERT_PERCENT
      CPU percent that starts the CPU alert clock. 2026-09-05 ran at 92 to 95; a loop with a real margin needs the two cores under about 80.
      See Also:
    • CPU_CLEAR_PERCENT

      public static final double CPU_CLEAR_PERCENT
      CPU percent below which the CPU alert clears.
      See Also:
    • CPU_HOLD_SECONDS

      public static final double CPU_HOLD_SECONDS
      Seconds the CPU must stay high before the alert shows.
      See Also:
    • GC_ALERT_MS_PER_SECOND

      public static final double GC_ALERT_MS_PER_SECOND
      Collector milliseconds inside one second, while enabled, that raise the GC alert.
      See Also:
    • MEMORY_ALERT_MB

      public static final double MEMORY_ALERT_MB
      Available memory below which the memory alert clock starts.
      See Also:
    • MEMORY_HOLD_SECONDS

      public static final double MEMORY_HOLD_SECONDS
      Seconds memory must stay low before the alert shows.
      See Also:
    • LATCH_SECONDS

      public static final double LATCH_SECONDS
      How long a one-shot alert (stall, GC) stays up so someone sees it.
      See Also:
  • Constructor Details

    • SystemLoadMonitor

      public SystemLoadMonitor()
  • Method Details

    • periodic

      public void periodic()
      Records this loop and, once a second, samples the system and updates the alerts.

      Call once per loop, before anything else in robotPeriodic(), so the loop period it measures is the whole period.

    • threadCensus

      public static void threadCensus(String label)
      Prints the thread ids that appeared since the last call, labelled, to the console (the journal on the robot). Native threads have no useful name in /proc; this ties the ids that System/TopThreads reports back to the library that started them. Boot-time only.