Class SystemLoadMonitor
java.lang.Object
frc.spectrumLib.telemetry.SystemLoadMonitor
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:
MemAvailablefrom/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
FieldsModifier and TypeFieldDescriptionstatic final doubleCPU percent that starts the CPU alert clock.static final doubleCPU percent below which the CPU alert clears.static final doubleSeconds the CPU must stay high before the alert shows.static final doubleCollector milliseconds inside one second, while enabled, that raise the GC alert.static final doubleHow long a one-shot alert (stall, GC) stays up so someone sees it.static final doubleShare of overrunning loops that starts the loop alert timer.static final doubleShare of overrunning loops below which the loop alert clears.static final doubleA loop longer than this many periods counts as an overrun.static final doubleSeconds the overrun share must stay high before the loop alert shows.static final doubleA single enabled loop longer than this is a stall worth an error.static final doubleAvailable memory below which the memory alert clock starts.static final doubleSeconds memory must stay low before the alert shows.static final doubleSeconds between samples and dashboard publishes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidperiodic()Records this loop and, once a second, samples the system and updates the alerts.static voidthreadCensus(String label) Prints the thread ids that appeared since the last call, labelled, to the console (the journal on the robot).
-
Field Details
-
SAMPLE_PERIOD_SECONDS
public static final double SAMPLE_PERIOD_SECONDSSeconds between samples and dashboard publishes.- See Also:
-
LOOP_OVERRUN_FACTOR
public static final double LOOP_OVERRUN_FACTORA loop longer than this many periods counts as an overrun.- See Also:
-
LOOP_OVERRUN_ALERT_PERCENT
public static final double LOOP_OVERRUN_ALERT_PERCENTShare of overrunning loops that starts the loop alert timer.- See Also:
-
LOOP_OVERRUN_CLEAR_PERCENT
public static final double LOOP_OVERRUN_CLEAR_PERCENTShare of overrunning loops below which the loop alert clears.- See Also:
-
LOOP_OVERRUN_HOLD_SECONDS
public static final double LOOP_OVERRUN_HOLD_SECONDSSeconds the overrun share must stay high before the loop alert shows.- See Also:
-
LOOP_STALL_MS
public static final double LOOP_STALL_MSA single enabled loop longer than this is a stall worth an error.- See Also:
-
CPU_ALERT_PERCENT
public static final double CPU_ALERT_PERCENTCPU 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_PERCENTCPU percent below which the CPU alert clears.- See Also:
-
CPU_HOLD_SECONDS
public static final double CPU_HOLD_SECONDSSeconds the CPU must stay high before the alert shows.- See Also:
-
GC_ALERT_MS_PER_SECOND
public static final double GC_ALERT_MS_PER_SECONDCollector milliseconds inside one second, while enabled, that raise the GC alert.- See Also:
-
MEMORY_ALERT_MB
public static final double MEMORY_ALERT_MBAvailable memory below which the memory alert clock starts.- See Also:
-
MEMORY_HOLD_SECONDS
public static final double MEMORY_HOLD_SECONDSSeconds memory must stay low before the alert shows.- See Also:
-
LATCH_SECONDS
public static final double LATCH_SECONDSHow 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
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 thatSystem/TopThreadsreports back to the library that started them. Boot-time only.
-