Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wpilibj] Watchdog Alert Linking #7160

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

oh-yes-0-fps
Copy link
Contributor

Allows linking an Alert to a Watchdog.

A linked alert will be activated every time the watchdog times out. On timeout the activation time will be reset and the text of the alert will be updated to "<alert-text> [xN]" where N is the number of overruns that have occurred.

@oh-yes-0-fps oh-yes-0-fps requested a review from a team as a code owner October 3, 2024 23:46
@oh-yes-0-fps
Copy link
Contributor Author

I had a more performant way of creating the new alert text but removed it in favor of String#format(...) for easier readability and maintainability. If people think perf is a concern I can bring back the faster way.

@oh-yes-0-fps
Copy link
Contributor Author

This can work hand in hand with #7099

If both are merged there should be a way to make the default watchdogs not print to the console so you can have NT only timing diagnostics.

Comment on lines +247 to +249
alert.m_active = true;
alert.m_activeStartTime = nowSeconds;
alert.m_text = String.format("%s [x%d]", m_originalAlertText, m_overruns);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alert already has methods for setting the alert and updating the text, use those.

Why is the start time when the watchdog was last fed? The problem started when the watchdog ran out, not when it was last fed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now is not when last fed, its when the notifier unblocks.

I needed a way to get the alerts original text. And the alternative to directly accessing the m_active and m_activeStartTime is pulling the alert low then high every cycle.

I thought package private would just be easier, along with unit tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now is not when last fed, it's when the notifier unblocks.

Yep, sorry.

Why does start time need to be reset?

To get the original text you can add a getter to Alert. In general, exposing internal data for the purpose of unit testing is a code smell.

return;
}
Alert alert = m_alert.get();
alert.m_active = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alert is never reset.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't matter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alert will always be active after the first time the watchdog times out. This makes it useless.

private double m_lastTimeoutPrintSeconds;

int m_overruns;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this package private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests

Comment on lines +59 to +71
m_timeoutSeconds = timeoutSeconds;
m_callback = d -> callback.run();
m_tracer = new Tracer();
}

/**
* Watchdog constructor.
*
* @param timeoutSeconds The watchdog's timeout in seconds with microsecond resolution.
* @param callback This function is called with the time in seconds since the watchdog was last
* fed when the timeout expires.
*/
public Watchdog(double timeoutSeconds, DoubleConsumer callback) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change?

// Set expiration flag before calling the callback so any
// manipulation of the flag in the callback (e.g., calling
// Disable()) isn't clobbered.
watchdog.m_isExpired = true;

m_queueMutex.unlock();
watchdog.m_callback.run();
watchdog.m_callback.accept(now - watchdog.m_startTimeSeconds);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change?

@rzblue
Copy link
Member

rzblue commented Oct 4, 2024

We also need to be cautious of where we are tying APIs to Alert, as it is an incubating api that will likely change in the short term. I think this is probably fine though.

@jwbonner
Copy link
Member

jwbonner commented Oct 4, 2024

I think it's really important that any WPILib/vendor logic tied to Alert gives users the option to use the default alert group only for user alerts (see here for details). I would say that WPILib alerts should use a different group, or at a minimum there needs to be an easy way for users to disable built-in alerts like this.

@rzblue
Copy link
Member

rzblue commented Oct 4, 2024

This also will need a c++ version eventually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants