diff --git a/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/EpilogueGenerator.java b/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/EpilogueGenerator.java index 741c2d58b4..866bfdf676 100644 --- a/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/EpilogueGenerator.java +++ b/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/EpilogueGenerator.java @@ -140,6 +140,25 @@ public class EpilogueGenerator { for (TypeElement mainRobotClass : mainRobotClasses) { String robotClassName = mainRobotClass.getQualifiedName().toString(); + out.println(); + out.print( + """ + /** + * Updates Epilogue. This must be called periodically in order for Epilogue to record + * new values. Alternatively, {@code bind()} can be used to update at an offset from + * the main robot loop. + */ + """); + out.println(" public static void update(" + robotClassName + " robot) {"); + out.println(" long start = System.nanoTime();"); + out.println( + " " + + StringUtils.loggerFieldName(mainRobotClass) + + ".tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler);"); + out.println( + " config.dataLogger.log(\"Epilogue/Stats/Last Run\", (System.nanoTime() - start) / 1e6);"); + out.println(" }"); + out.println(); out.print( """ @@ -161,13 +180,7 @@ public class EpilogueGenerator { out.println(" }"); out.println(); out.println(" robot.addPeriodic(() -> {"); - out.println(" long start = System.nanoTime();"); - out.println( - " " - + StringUtils.loggerFieldName(mainRobotClass) - + ".tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler);"); - out.println( - " config.dataLogger.log(\"Epilogue/Stats/Last Run\", (System.nanoTime() - start) / 1e6);"); + out.println(" update(robot);"); out.println( " }, config.loggingPeriod.in(Seconds), config.loggingPeriodOffset.in(Seconds));"); out.println(" }"); diff --git a/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/EpilogueGeneratorTest.java b/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/EpilogueGeneratorTest.java index 1c8c6ef131..a51345f49e 100644 --- a/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/EpilogueGeneratorTest.java +++ b/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/EpilogueGeneratorTest.java @@ -147,6 +147,17 @@ class EpilogueGeneratorTest { return importance.compareTo(config.minimumImportance) >= 0; } + /** + * Updates Epilogue. This must be called periodically in order for Epilogue to record + * new values. Alternatively, {@code bind()} can be used to update at an offset from + * the main robot loop. + */ + public static void update(edu.wpi.first.epilogue.Example robot) { + long start = System.nanoTime(); + exampleLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler); + config.dataLogger.log(\"Epilogue/Stats/Last Run\", (System.nanoTime() - start) / 1e6); + } + /** * Binds Epilogue updates to a timed robot's update period. Log calls will be made at the * same update rate as the robot's loop function, but will be offset by a full phase @@ -164,9 +175,7 @@ class EpilogueGeneratorTest { } robot.addPeriodic(() -> { - long start = System.nanoTime(); - exampleLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler); - config.dataLogger.log(\"Epilogue/Stats/Last Run\", (System.nanoTime() - start) / 1e6); + update(robot); }, config.loggingPeriod.in(Seconds), config.loggingPeriodOffset.in(Seconds)); } } @@ -218,6 +227,17 @@ class EpilogueGeneratorTest { return importance.compareTo(config.minimumImportance) >= 0; } + /** + * Updates Epilogue. This must be called periodically in order for Epilogue to record + * new values. Alternatively, {@code bind()} can be used to update at an offset from + * the main robot loop. + */ + public static void update(edu.wpi.first.epilogue.AlphaBot robot) { + long start = System.nanoTime(); + alphaBotLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler); + config.dataLogger.log(\"Epilogue/Stats/Last Run\", (System.nanoTime() - start) / 1e6); + } + /** * Binds Epilogue updates to a timed robot's update period. Log calls will be made at the * same update rate as the robot's loop function, but will be offset by a full phase @@ -235,12 +255,21 @@ class EpilogueGeneratorTest { } robot.addPeriodic(() -> { - long start = System.nanoTime(); - alphaBotLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler); - config.dataLogger.log(\"Epilogue/Stats/Last Run\", (System.nanoTime() - start) / 1e6); + update(robot); }, config.loggingPeriod.in(Seconds), config.loggingPeriodOffset.in(Seconds)); } + /** + * Updates Epilogue. This must be called periodically in order for Epilogue to record + * new values. Alternatively, {@code bind()} can be used to update at an offset from + * the main robot loop. + */ + public static void update(edu.wpi.first.epilogue.BetaBot robot) { + long start = System.nanoTime(); + betaBotLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler); + config.dataLogger.log(\"Epilogue/Stats/Last Run\", (System.nanoTime() - start) / 1e6); + } + /** * Binds Epilogue updates to a timed robot's update period. Log calls will be made at the * same update rate as the robot's loop function, but will be offset by a full phase @@ -258,9 +287,7 @@ class EpilogueGeneratorTest { } robot.addPeriodic(() -> { - long start = System.nanoTime(); - betaBotLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler); - config.dataLogger.log("Epilogue/Stats/Last Run", (System.nanoTime() - start) / 1e6); + update(robot); }, config.loggingPeriod.in(Seconds), config.loggingPeriodOffset.in(Seconds)); } }