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

[epilogue] Allow configuring logging period and logging period offset #6893

Merged
merged 4 commits into from
Aug 14, 2024

Conversation

spacey-sooty
Copy link
Contributor

@spacey-sooty spacey-sooty commented Jul 29, 2024

Resolves #6883

@spacey-sooty spacey-sooty requested a review from a team as a code owner July 29, 2024 04:30
@spacey-sooty
Copy link
Contributor Author

/format

@spacey-sooty spacey-sooty force-pushed the epilogueconfiguration branch 16 times, most recently from dc9a788 to b0e7ca1 Compare July 29, 2024 10:25
@spacey-sooty
Copy link
Contributor Author

@SamCarlberg Can you review?

@spacey-sooty spacey-sooty force-pushed the epilogueconfiguration branch from b0e7ca1 to 608bc7c Compare July 29, 2024 15:30
Copy link
Contributor

@KangarooKoala KangarooKoala left a comment

Choose a reason for hiding this comment

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

I might be wrong, but I think the original issue said that for the offset, null should be the default value, which is interpreted as "half of whatever the logging period is" (since that isn't guaranteed to be 20ms). It'd probably also make sense to make the logging period have a default value of null that is interpreted as "whatever the robot period is" (since that isn't guaranteed to be 20ms).

@spacey-sooty
Copy link
Contributor Author

The reason I avoided making it null by default was that we would need to do an extra check on if the value is null before applying the default value. By doing this we make it a no cost operation for most cases and then have then leave it up to the user to configure it if they are running at a different speed (which if they are doing are probably already an advanced user).

@SamCarlberg
Copy link
Member

The reason I avoided making it null by default was that we would need to do an extra check on if the value is null before applying the default value. By doing this we make it a no cost operation for most cases

This is a premature optimization; null checks are already very fast

and then have then leave it up to the user to configure it if they are running at a different speed (which if they are doing are probably already an advanced user).

The issue only specified a configurable offset to keep logging at the same frequency as the main robot loop. Making the default value null means that we can log based on whatever user-configured loop frequency was specified in the robot constructor without forcing users to set it explicitly for epilogue. A configurable period on top of that is certainly strong, but means there'd be a second place to specify a loop period for users not on a 50hz frequency:

public Robot() {
  super(0.01); // 100Hz update rate

  Epilogue.configure(config -> {
    // No configuration: logging at 50hz intervals and coincide with every second main loop iteration
  });

  Epilogue.configure(config -> {
    // Both of these are required to be set in order to keep logging in sync and with the default behavior
    config.loggingPeriod = Milliseconds.of(10);
    config.loggingPeriodOffset = Milliseconds.of(5);
  });
}

versus:

public Robot() {
  super(0.01);

  Epilogue.configure(config -> {
    // No configuration: logs at 100Hz, offset by 5ms from the main loop
  });

  Epilogue.configure(config -> {
    // Configure the offset: still log at 100Hz, but synchronized with the main robot loop
    // This comes at the cost of higher CPU load
    config.loggingPeriodOffset = Milliseconds.zero();
  });
}

If users really want custom logging periods, they can add a periodic callback themselves without using bind. This is essentially what the bind method does anyway, just without tracking logging timings (which is also trivial to add)

public Robot() {
  super(0.01);

  addPeriodic(
    () -> {
      Epilogue.robotLogger.tryUpdate(
        Epilogue.getConfig().dataLogger.getSubLogger(Epilogue.getConfig().root),
        this,
        Epilogue.getConfig().errorHandler
      )
    },
    loggingPeriod,
    loggingPeriodOffset
  );
}

(As an aside, generating a logOnce or logNow method in the Epilogue class would be helpful to simplify direct usage for people not using bind)

@spacey-sooty spacey-sooty force-pushed the epilogueconfiguration branch from 608bc7c to ff7590f Compare July 31, 2024 01:40
@spacey-sooty
Copy link
Contributor Author

The issue only specified a configurable offset to keep logging at the same frequency as the main robot loop.

I am aware but adding a loggingPeriod seemed like a good addition to me as well.

@spacey-sooty spacey-sooty force-pushed the epilogueconfiguration branch from ff7590f to f3596e7 Compare July 31, 2024 01:48
@spacey-sooty spacey-sooty force-pushed the epilogueconfiguration branch from f3596e7 to 0b20370 Compare August 2, 2024 04:16
@spacey-sooty spacey-sooty force-pushed the epilogueconfiguration branch from 59ef766 to 4d7d9f1 Compare August 12, 2024 06:59
@spacey-sooty spacey-sooty requested a review from a team as a code owner August 13, 2024 14:46
@spacey-sooty spacey-sooty force-pushed the epilogueconfiguration branch from 29561d9 to e1004fe Compare August 13, 2024 14:54
@SamCarlberg
Copy link
Member

Wow, spotbugs is dumber than I remembered it being. You actually do need to disable the spotbugs warnings on the two fields since it doesn't detect usages in examples

@spacey-sooty
Copy link
Contributor Author

Wow, spotbugs is dumber than I remembered it being. You actually do need to disable the spotbugs warnings on the two fields since it doesn't detect usages in examples

Example number infinity of why spotbugs is stupid and this warning should be suppressed 🙂

@calcmogul
Copy link
Member

calcmogul commented Aug 14, 2024

We can suppress it locally via styleguide/spotbugs-exclude.xml. Suppressing it globally isn't ideal because it has caught valid issues before.

@spacey-sooty spacey-sooty force-pushed the epilogueconfiguration branch 2 times, most recently from eeb7d44 to 89c64a9 Compare August 14, 2024 01:09
@spacey-sooty spacey-sooty force-pushed the epilogueconfiguration branch from 8483162 to 0234b17 Compare August 14, 2024 04:20
@spacey-sooty spacey-sooty force-pushed the epilogueconfiguration branch from 0234b17 to 80bb082 Compare August 14, 2024 04:22
@PeterJohnson PeterJohnson merged commit 70fa41c into wpilibsuite:main Aug 14, 2024
33 checks passed
@spacey-sooty spacey-sooty deleted the epilogueconfiguration branch August 15, 2024 05:50
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.

[epilogue] Allow logging period to be configurable
5 participants