Class LogStorage
java.lang.Object
frc.spectrumLib.telemetry.LogStorage
Where the robot's logs go on SystemCore, and keeping them from filling its storage.
A full internal disk is a SystemCore failure other teams have hit at events: a robot that rebooted mid-match with an empty log, another that lost control with 50 MB left, deploys that deleted the robot program (wpilibsuite/SystemcoreTesting #210, #211, #156). Every log goes to internal storage when no USB stick is in, and nothing else ever deletes them; the bench unit had 408 MB of them after two days. So:
chooseFolder()waits briefly for a USB stick to mount before settling on internal storage: the robot program can start before/Uis mounted (SystemcoreTesting #341).cleanUpAtBoot()deletes the oldest logs before this boot's log exists.start()checks free space off the main thread and trims the internal folder if the disk runs short;periodic()turns the result into alerts and log values on the main thread.
SystemCore can boot with its clock behind older logs, so this boot's log can sort oldest. A
file is never deleted if it appeared after cleanUpAtBoot() or was modified within ACTIVE_WINDOW_MILLIS.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longBelow this much free space the storage alert goes red.static final longFree space cleanup keeps on the disk holding the logs.static final longMost internal storage this program's logs may use.static final Stringstatic final Stringstatic final String -
Method Summary
Modifier and TypeMethodDescriptionstatic StringThe folder to log to: the USB stick if one is (or withinUSB_WAIT_SECONDSbecomes) mounted, else internal storage.static long[]static long[]Deletes the oldest log files indiruntil they total at mostcapBytesand the disk has at leastfreeFloorBytesfree.static voidCleans the internal log folder and remembers which logs exist, so later ones are protected.static Stringfolder()The folder chosen at boot.static voidperiodic()Alerts and log values from the last background check.static voidstart()Reports the boot cleanup and starts the background free-space check.
-
Field Details
-
USB_MOUNT
- See Also:
-
USB_LOGS
- See Also:
-
LOCAL_LOGS
- See Also:
-
LOCAL_CAP_BYTES
public static final long LOCAL_CAP_BYTESMost internal storage this program's logs may use. A match log is ~50-150 MB.- See Also:
-
FREE_FLOOR_BYTES
public static final long FREE_FLOOR_BYTESFree space cleanup keeps on the disk holding the logs.- See Also:
-
FREE_ALERT_BYTES
public static final long FREE_ALERT_BYTESBelow this much free space the storage alert goes red.- See Also:
-
-
Method Details
-
chooseFolder
The folder to log to: the USB stick if one is (or withinUSB_WAIT_SECONDSbecomes) mounted, else internal storage. Blocks at most that long, and only when/Uexists.- Returns:
- the log folder, created if needed
-
cleanUp
public static long[] cleanUp(File dir, long capBytes, long freeFloorBytes, int keepNewest, Set<String> protectedNames) Deletes the oldest log files indiruntil they total at mostcapBytesand the disk has at leastfreeFloorBytesfree.- Parameters:
dir- the log foldercapBytes- most the logs may totalfreeFloorBytes- free space to leave on the diskkeepNewest- how many of the newest logs are keptprotectedNames- files never deleted- Returns:
- {count deleted, bytes deleted}
-
cleanUp
-
cleanUpAtBoot
public static void cleanUpAtBoot()Cleans the internal log folder and remembers which logs exist, so later ones are protected. Call beforeLogger.start(). -
start
public static void start()Reports the boot cleanup and starts the background free-space check. Call afterLogger.start(). -
periodic
public static void periodic()Alerts and log values from the last background check. Call once per loop; cheap. -
folder
The folder chosen at boot.
-