diff --git a/core/src/main/java/edu/wpi/grip/core/Step.java b/core/src/main/java/edu/wpi/grip/core/Step.java index d1c18a9565..9ad8161b66 100644 --- a/core/src/main/java/edu/wpi/grip/core/Step.java +++ b/core/src/main/java/edu/wpi/grip/core/Step.java @@ -106,11 +106,11 @@ protected final void runPerformIfPossible() { * InputSocket#getValue()} are not empty. If one input is invalid then the perform method will not * run and all output sockets will be assigned to their default values. * - * @param inBenchmark if this step is being benchmarked. The operation's perform method will be - * called if every input is valid regardless of 'dirtiness' if it's being - * benchmarked. + * @param benchmarking if this step is being benchmarked. The operation's perform method will be + * called if every input is valid regardless of 'dirtiness' if it's being + * benchmarked. */ - protected final void runPerform(boolean inBenchmark) { + protected final void runPerform(boolean benchmarking) { boolean anyDirty = false; // Keeps track of if there are sockets that are dirty for (InputSocket inputSocket : inputSockets) { @@ -125,7 +125,7 @@ protected final void runPerform(boolean inBenchmark) { // If one value is true then this will stay true anyDirty |= inputSocket.dirtied(); } - if (!inBenchmark && !anyDirty) { + if (!benchmarking && !anyDirty) { // If there aren't any dirty inputs don't clear the exceptions, just return return; } diff --git a/core/src/main/java/edu/wpi/grip/core/events/BenchmarkEvent.java b/core/src/main/java/edu/wpi/grip/core/events/BenchmarkEvent.java index 4c025efb0a..14cfa28c3f 100644 --- a/core/src/main/java/edu/wpi/grip/core/events/BenchmarkEvent.java +++ b/core/src/main/java/edu/wpi/grip/core/events/BenchmarkEvent.java @@ -3,7 +3,7 @@ /** * An event posted before and after a pipeline is benchmarked. */ -public class BenchmarkEvent { +public final class BenchmarkEvent { private final boolean isStart; diff --git a/core/src/main/java/edu/wpi/grip/core/metrics/BenchmarkRunner.java b/core/src/main/java/edu/wpi/grip/core/metrics/BenchmarkRunner.java index f70b9a6213..e077f36004 100644 --- a/core/src/main/java/edu/wpi/grip/core/metrics/BenchmarkRunner.java +++ b/core/src/main/java/edu/wpi/grip/core/metrics/BenchmarkRunner.java @@ -1,6 +1,5 @@ package edu.wpi.grip.core.metrics; -import edu.wpi.grip.core.Pipeline; import edu.wpi.grip.core.events.BenchmarkEvent; import edu.wpi.grip.core.events.BenchmarkRunEvent; import edu.wpi.grip.core.events.RunStartedEvent; @@ -26,8 +25,6 @@ public class BenchmarkRunner { @Inject private EventBus eventBus; - @Inject - private Pipeline pipeline; private AtomicBoolean isBenchmarking = new AtomicBoolean(false); private AtomicInteger runsRemaining = new AtomicInteger(0); @@ -46,6 +43,7 @@ public void run(int numRuns) { } @Subscribe + @SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.UnusedFormalParameter"}) private void onRunStart(@Nullable RunStartedEvent event) { if (!isBenchmarking.get()) { return; @@ -54,6 +52,7 @@ private void onRunStart(@Nullable RunStartedEvent event) { } @Subscribe + @SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.UnusedFormalParameter"}) private void onRunStop(@Nullable RunStoppedEvent event) { if (!isBenchmarking.get()) { return; @@ -66,7 +65,12 @@ private void onRunStop(@Nullable RunStoppedEvent event) { } } + /** + * Resets the runner if a "finished" benchmark event is posted while a benchmark is being run. + * This is used to kill the runner if the analysis window is closed or the application is exited. + */ @Subscribe + @SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.UnusedFormalParameter"}) private void onBenchmarkEvent(BenchmarkEvent event) { if (isBenchmarking.get() && !event.isStart()) { isBenchmarking.set(false); diff --git a/ui/src/main/java/edu/wpi/grip/ui/MainWindowController.java b/ui/src/main/java/edu/wpi/grip/ui/MainWindowController.java index b398f97cfb..9dd65fda8a 100644 --- a/ui/src/main/java/edu/wpi/grip/ui/MainWindowController.java +++ b/ui/src/main/java/edu/wpi/grip/ui/MainWindowController.java @@ -294,6 +294,7 @@ private void updateElapsedTimeLabel(long elapsed) { } @FXML + @SuppressWarnings({"PMD.UnusedPrivateMethod"}) private void showAnalysis() { Stage analysisStage = new Stage(); try { @@ -304,7 +305,7 @@ private void showAnalysis() { controller.setBenchmarker(benchmarkRunner); eventBus.register(controller); } catch (IOException e) { - throw new RuntimeException(e); + throw new AssertionError("Analysis window FXML is not present or readable", e); } analysisStage.initModality(Modality.WINDOW_MODAL); analysisStage.initOwner(root.getScene().getWindow()); @@ -314,6 +315,5 @@ private void showAnalysis() { eventBus.post(BenchmarkEvent.finished()); }); analysisStage.showAndWait(); - System.out.println("User finished analysis"); } } diff --git a/ui/src/main/java/edu/wpi/grip/ui/analysis/AnalysisWindowController.java b/ui/src/main/java/edu/wpi/grip/ui/analysis/AnalysisWindowController.java index 391e5d91cd..e8b3db4a54 100644 --- a/ui/src/main/java/edu/wpi/grip/ui/analysis/AnalysisWindowController.java +++ b/ui/src/main/java/edu/wpi/grip/ui/analysis/AnalysisWindowController.java @@ -81,7 +81,7 @@ public void initialize() { table.setItems(tableItems); benchmarkRunsField.textProperty().addListener((observable, oldValue, newValue) -> { - if ((oldValue.isEmpty() && newValue.equals("0")) || !newValue.matches("[\\d]*")) { + if ((oldValue.isEmpty() && "0".equals(newValue)) || !newValue.matches("[\\d]*")) { benchmarkRunsField.setText(oldValue); return; } @@ -90,6 +90,7 @@ public void initialize() { } @Subscribe + @SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.UnusedFormalParameter"}) private void onRun(TimerEvent event) { if (event.getSource() instanceof Step) { Step source = (Step) event.getSource(); @@ -99,6 +100,7 @@ private void onRun(TimerEvent event) { } @Subscribe + @SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.UnusedFormalParameter"}) private void onStepRemoved(StepRemovedEvent event) { stepData.stream() .filter(p -> p.getLeft() == event.getStep()) // Want reference equality @@ -108,6 +110,7 @@ private void onStepRemoved(StepRemovedEvent event) { } @Subscribe + @SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.UnusedFormalParameter"}) private void onPipelineFinish(@Nullable RunStoppedEvent event) { // Update the table after the pipeline finishes tableItems.clear(); @@ -119,6 +122,7 @@ private void onPipelineFinish(@Nullable RunStoppedEvent event) { } @Subscribe + @SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.UnusedFormalParameter"}) private void onBenchmark(BenchmarkEvent event) { benchmarkButton.setDisable(event.isStart()); benchmarkRunsField.setDisable(event.isStart()); @@ -129,6 +133,7 @@ public void setBenchmarker(BenchmarkRunner benchmarker) { } @FXML + @SuppressWarnings("PMD.UnusedPrivateMethod") private void runBenchmark() { if (benchmarkRunsField.getText().length() > 0) { benchmarker.run(Integer.parseInt(benchmarkRunsField.getText())); @@ -143,16 +148,14 @@ private static class TimeView extends HBox { private final ProgressBar progressBar = new ProgressBar(); TimeView(double time, double relativeAmount, double hotness) { + super(); text.setText(String.format("%.1fms", time / 1e3)); progressBar.setProgress(relativeAmount); progressBar.setPrefWidth(BAR_LENGTH); progressBar.setPadding(new Insets(0, 10, 0, 5)); if (hotness > 0) { final double max = 3; // highest value before being clamped - if (hotness > max) { - hotness = max; // clamp - } - double h = ((max - hotness) * 270 / max) - 45; + double h = ((max - Math.min(hotness, max)) * 270 / max) - 45; final String formatStyle = "-fx-accent: hsb(%.2f, 100%%, 100%%);"; progressBar.setStyle(String.format(formatStyle, h)); }