Skip to content

Commit

Permalink
rework tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
oh-yes-0-fps committed Sep 19, 2024
1 parent 97c6c86 commit 427d3c1
Show file tree
Hide file tree
Showing 5 changed files with 270 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ public double getPeriod() {

/** Loop function. */
protected void loopFunc() {
Tracer.startTrace("RobotLoop");

DriverStation.refreshData();
m_watchdog.reset();

Expand Down Expand Up @@ -344,23 +346,19 @@ protected void loopFunc() {
switch (mode) {
case kDisabled -> {
disabledInit();
m_watchdog.addEpoch("disabledInit()");
}
case kAutonomous -> {
autonomousInit();
m_watchdog.addEpoch("autonomousInit()");
}
case kTeleop -> {
teleopInit();
m_watchdog.addEpoch("teleopInit()");
}
case kTest -> {
if (m_lwEnabledInTest) {
LiveWindow.setEnabled(true);
Shuffleboard.enableActuatorWidgets();
}
testInit();
m_watchdog.addEpoch("testInit()");
}
default -> {
// NOP
Expand All @@ -374,44 +372,35 @@ protected void loopFunc() {
switch (mode) {
case kDisabled -> {
DriverStationJNI.observeUserProgramDisabled();
disabledPeriodic();
m_watchdog.addEpoch("disabledPeriodic()");
Tracer.traceFunc("DisabledPeriodic", this::disabledPeriodic);
}
case kAutonomous -> {
DriverStationJNI.observeUserProgramAutonomous();
autonomousPeriodic();
m_watchdog.addEpoch("autonomousPeriodic()");
Tracer.traceFunc("AutonomousPeriodic", this::autonomousPeriodic);
}
case kTeleop -> {
DriverStationJNI.observeUserProgramTeleop();
teleopPeriodic();
m_watchdog.addEpoch("teleopPeriodic()");
Tracer.traceFunc("TeleopPeriodic", this::teleopPeriodic);
}
case kTest -> {
DriverStationJNI.observeUserProgramTest();
testPeriodic();
m_watchdog.addEpoch("testPeriodic()");
Tracer.traceFunc("TestPeriodic", this::testPeriodic);
}
default -> {
// NOP
}
}

robotPeriodic();
m_watchdog.addEpoch("robotPeriodic()");
Tracer.traceFunc("RobotPeriodic", this::robotPeriodic);

SmartDashboard.updateValues();
m_watchdog.addEpoch("SmartDashboard.updateValues()");
LiveWindow.updateValues();
m_watchdog.addEpoch("LiveWindow.updateValues()");
Shuffleboard.update();
m_watchdog.addEpoch("Shuffleboard.update()");

if (isSimulation()) {
HAL.simPeriodicBefore();
simulationPeriodic();
Tracer.traceFunc("SimulationPeriodic", this::simulationPeriodic);
HAL.simPeriodicAfter();
m_watchdog.addEpoch("simulationPeriodic()");
}

m_watchdog.disable();
Expand All @@ -421,15 +410,7 @@ protected void loopFunc() {
NetworkTableInstance.getDefault().flushLocal();
}

// Warn on loop time overruns
if (m_watchdog.isExpired()) {
m_watchdog.printEpochs();
}
}

/** Prints list of epochs added so far and their times. */
public void printWatchdogEpochs() {
m_watchdog.printEpochs();
Tracer.endTrace();
}

private void printLoopOverrunMessage() {
Expand Down
4 changes: 4 additions & 0 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/TimedRobot.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public void startCompetition() {
break;
}

Tracer.startTrace("TimedRobot");

callback.func.run();

// Increment the expiration time by the number of full periods it's behind
Expand All @@ -150,6 +152,8 @@ public void startCompetition() {
+ (currentTime - callback.expirationTime) / callback.period * callback.period;
m_callbacks.add(callback);
}

Tracer.endTrace();
}
}

Expand Down
Loading

0 comments on commit 427d3c1

Please sign in to comment.