|
@@ -1,13 +1,17 @@
|
|
|
-package org.cryptomator.ui.vaultstatistics;
|
|
|
+package org.cryptomator.ui.stats;
|
|
|
|
|
|
import javafx.animation.Animation;
|
|
|
import javafx.animation.KeyFrame;
|
|
|
import javafx.animation.Timeline;
|
|
|
+import javafx.beans.binding.Bindings;
|
|
|
+import javafx.beans.binding.DoubleBinding;
|
|
|
import javafx.beans.binding.LongBinding;
|
|
|
import javafx.event.ActionEvent;
|
|
|
import javafx.event.EventHandler;
|
|
|
import javafx.fxml.FXML;
|
|
|
+import javafx.scene.chart.AreaChart;
|
|
|
import javafx.scene.chart.LineChart;
|
|
|
+import javafx.scene.chart.NumberAxis;
|
|
|
import javafx.scene.chart.XYChart.Data;
|
|
|
import javafx.scene.chart.XYChart.Series;
|
|
|
import javafx.stage.Stage;
|
|
@@ -18,13 +22,14 @@ import org.cryptomator.ui.common.FxController;
|
|
|
import org.cryptomator.ui.common.WeakBindings;
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.ResourceBundle;
|
|
|
|
|
|
@VaultStatisticsScoped
|
|
|
public class VaultStatisticsController implements FxController {
|
|
|
|
|
|
- private static final int IO_SAMPLING_STEPS = 100;
|
|
|
- private static final double IO_SAMPLING_INTERVAL = 0.5;
|
|
|
+ private static final int IO_SAMPLING_STEPS = 30;
|
|
|
+ private static final double IO_SAMPLING_INTERVAL = 1;
|
|
|
|
|
|
private final VaultStats stats;
|
|
|
private final Series<Number, Number> readData;
|
|
@@ -32,19 +37,27 @@ public class VaultStatisticsController implements FxController {
|
|
|
private final Timeline ioAnimation;
|
|
|
private final LongBinding bpsRead;
|
|
|
private final LongBinding bpsWritten;
|
|
|
+ private final DoubleBinding cacheHitRate;
|
|
|
+ private final DoubleBinding cacheHitDregrees;
|
|
|
+ private final DoubleBinding cacheHitPercentage;
|
|
|
|
|
|
- public LineChart<Number, Number> lineGraph;
|
|
|
+ public AreaChart<Number, Number> readChart;
|
|
|
+ public AreaChart<Number, Number> writeChart;
|
|
|
+ public NumberAxis readChartXAxis;
|
|
|
+ public NumberAxis readChartYAxis;
|
|
|
+ public NumberAxis writeChartXAxis;
|
|
|
+ public NumberAxis writeChartYAxis;
|
|
|
|
|
|
@Inject
|
|
|
public VaultStatisticsController(@VaultStatisticsWindow Stage window, @VaultStatisticsWindow Vault vault, ResourceBundle resourceBundle) {
|
|
|
this.stats = vault.getStats();
|
|
|
- this.bpsRead = WeakBindings.bindLong(stats.bytesPerSecondReadProperty());
|
|
|
- this.bpsWritten = WeakBindings.bindLong(stats.bytesPerSecondWrittenProperty());
|
|
|
-
|
|
|
this.readData = new Series<>();
|
|
|
- readData.setName(resourceBundle.getString("vaultstatistics.readDataLabel"));
|
|
|
this.writeData = new Series<>();
|
|
|
- writeData.setName(resourceBundle.getString("vaultstatistics.writtenDataLabel"));
|
|
|
+ this.bpsRead = WeakBindings.bindLong(stats.bytesPerSecondReadProperty());
|
|
|
+ this.bpsWritten = WeakBindings.bindLong(stats.bytesPerSecondWrittenProperty());
|
|
|
+ this.cacheHitRate = WeakBindings.bindDouble(stats.cacheHitRateProperty());
|
|
|
+ this.cacheHitDregrees = cacheHitRate.multiply(-270);
|
|
|
+ this.cacheHitPercentage = cacheHitRate.multiply(100);
|
|
|
|
|
|
this.ioAnimation = new Timeline(); //TODO Research better timer
|
|
|
ioAnimation.getKeyFrames().add(new KeyFrame(Duration.seconds(IO_SAMPLING_INTERVAL), new IoSamplingAnimationHandler(readData, writeData)));
|
|
@@ -60,14 +73,18 @@ public class VaultStatisticsController implements FxController {
|
|
|
|
|
|
@FXML
|
|
|
public void initialize() {
|
|
|
- lineGraph.getData().addAll(readData, writeData);
|
|
|
+ readChart.getData().addAll(readData);
|
|
|
+ writeChart.getData().addAll(writeData);
|
|
|
}
|
|
|
|
|
|
private class IoSamplingAnimationHandler implements EventHandler<ActionEvent> {
|
|
|
|
|
|
private static final double BYTES_TO_MEGABYTES_FACTOR = 1.0 / IO_SAMPLING_INTERVAL / 1024.0 / 1024.0;
|
|
|
+
|
|
|
+ private long step = IO_SAMPLING_STEPS;
|
|
|
private final Series<Number, Number> decryptedBytesRead;
|
|
|
private final Series<Number, Number> encryptedBytesWrite;
|
|
|
+ private final long[] maxBuf = new long[IO_SAMPLING_STEPS];
|
|
|
|
|
|
public IoSamplingAnimationHandler(Series<Number, Number> readData, Series<Number, Number> writeData) {
|
|
|
this.decryptedBytesRead = readData;
|
|
@@ -82,23 +99,28 @@ public class VaultStatisticsController implements FxController {
|
|
|
|
|
|
@Override
|
|
|
public void handle(ActionEvent event) {
|
|
|
- // move all values one step:
|
|
|
- for (int i = 0; i < IO_SAMPLING_STEPS - 1; i++) {
|
|
|
- int j = i + 1;
|
|
|
- Number tmp = decryptedBytesRead.getData().get(j).getYValue();
|
|
|
- decryptedBytesRead.getData().get(i).setYValue(tmp);
|
|
|
-
|
|
|
- tmp = encryptedBytesWrite.getData().get(j).getYValue();
|
|
|
- encryptedBytesWrite.getData().get(i).setYValue(tmp);
|
|
|
- }
|
|
|
-
|
|
|
- // add latest value:
|
|
|
+ final long currentStep = step++;
|
|
|
final long decBytes = stats.bytesPerSecondReadProperty().get();
|
|
|
- final double decMb = decBytes * BYTES_TO_MEGABYTES_FACTOR;
|
|
|
final long encBytes = stats.bytesPerSecondWrittenProperty().get();
|
|
|
- final double encMb = encBytes * BYTES_TO_MEGABYTES_FACTOR;
|
|
|
- decryptedBytesRead.getData().get(IO_SAMPLING_STEPS - 1).setYValue(decMb);
|
|
|
- encryptedBytesWrite.getData().get(IO_SAMPLING_STEPS - 1).setYValue(encMb);
|
|
|
+
|
|
|
+ maxBuf[(int) currentStep % IO_SAMPLING_STEPS] = Math.max(decBytes, encBytes);
|
|
|
+ long allTimeMax = Arrays.stream(maxBuf).max().orElse(0l);
|
|
|
+
|
|
|
+ // remove oldest value:
|
|
|
+ decryptedBytesRead.getData().remove(0);
|
|
|
+ encryptedBytesWrite.getData().remove(0);
|
|
|
+
|
|
|
+ // add latest value:
|
|
|
+ decryptedBytesRead.getData().add(new Data<>(currentStep, decBytes));
|
|
|
+ encryptedBytesWrite.getData().add(new Data<>(currentStep, encBytes));
|
|
|
+
|
|
|
+ // adjust ranges:
|
|
|
+ readChartXAxis.setLowerBound(currentStep - IO_SAMPLING_STEPS);
|
|
|
+ readChartXAxis.setUpperBound(currentStep);
|
|
|
+ readChartYAxis.setUpperBound(allTimeMax);
|
|
|
+ writeChartXAxis.setLowerBound(currentStep - IO_SAMPLING_STEPS);
|
|
|
+ writeChartXAxis.setUpperBound(currentStep);
|
|
|
+ writeChartYAxis.setUpperBound(allTimeMax);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -119,4 +141,20 @@ public class VaultStatisticsController implements FxController {
|
|
|
public long getBpsWritten() {
|
|
|
return bpsWritten.get();
|
|
|
}
|
|
|
+
|
|
|
+ public DoubleBinding cacheHitPercentageProperty() {
|
|
|
+ return cacheHitPercentage;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getCacheHitPercentage() {
|
|
|
+ return cacheHitPercentage.get();
|
|
|
+ }
|
|
|
+
|
|
|
+ public DoubleBinding cacheHitDregreesProperty() {
|
|
|
+ return cacheHitDregrees;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getCacheHitDregrees() {
|
|
|
+ return cacheHitDregrees.get();
|
|
|
+ }
|
|
|
}
|