diff --git a/main/ui/src/main/java/org/cryptomator/ui/controls/DataLabel.java b/main/ui/src/main/java/org/cryptomator/ui/controls/DataLabel.java new file mode 100644 index 000000000..a5834cce7 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/controls/DataLabel.java @@ -0,0 +1,88 @@ +package org.cryptomator.ui.controls; + +import javafx.beans.binding.Bindings; +import javafx.beans.binding.StringBinding; +import javafx.beans.property.LongProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.scene.control.Label; + +public class DataLabel extends Label { + + private static final long KIB_THRESHOLD = 1l << 7; // 0.128 kiB + private static final long MIB_THRESHOLD = 1l << 19; // 0.512 MiB + private static final long GIB_THRESHOLD = 1l << 29; // 0.512 GiB + + private final StringProperty byteFormat = new SimpleStringProperty("-"); + private final StringProperty kibFormat = new SimpleStringProperty("%.3f"); + private final StringProperty mibFormat = new SimpleStringProperty("%.3f"); + private final StringProperty gibFormat = new SimpleStringProperty("%.3f"); + private final LongProperty dataInBytes = new SimpleLongProperty(); + + public DataLabel() { + textProperty().bind(createStringBinding()); + } + + protected StringBinding createStringBinding() { + return Bindings.createStringBinding(this::updateText, kibFormat, mibFormat, gibFormat, dataInBytes); + } + + private String updateText() { + long data = dataInBytes.get(); + if (data > GIB_THRESHOLD) { + double giB = ((double) data) / 1024.0 / 1024.0 / 1024.0; + return String.format(gibFormat.get(), giB); + } else if (data > MIB_THRESHOLD) { + double miB = ((double) data) / 1024.0 / 1024.0; + return String.format(mibFormat.get(), miB); + } else if (data > KIB_THRESHOLD) { + double kiB = ((double) data) / 1024.0; + return String.format(kibFormat.get(), kiB); + } else { + return String.format(byteFormat.get(), data); + } + } + + public StringProperty byteFormatProperty() { return byteFormat; } + + public String getByteFormat() { return byteFormat.get(); } + + public void setByteFormat(String byteFormat) { + this.byteFormat.set(byteFormat); + } + + public StringProperty kibFormatProperty() { return kibFormat; } + + public String getKibFormat() { return kibFormat.get(); } + + public void setKibFormat(String kibFormat) { + this.kibFormat.set(kibFormat); + } + + public StringProperty mibFormatProperty() { return mibFormat; } + + public String getMibFormat() { return mibFormat.get(); } + + public void setMibFormat(String mibFormat) { + this.mibFormat.set(mibFormat); + } + + public StringProperty gibFormatProperty() { return gibFormat; } + + public String getGibFormat() { return gibFormat.get(); } + + public void setGibFormat(String gibFormat) { + this.gibFormat.set(gibFormat); + } + + public LongProperty dataInBytesProperty() { return dataInBytes; } + + public long getDataInBytes() { + return dataInBytes.get(); + } + + public void setDataInBytes(long dataInBytes) { this.dataInBytes.set(dataInBytes); } + + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/stats/VaultStatisticsController.java b/main/ui/src/main/java/org/cryptomator/ui/stats/VaultStatisticsController.java index cc747b8f6..20218d100 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/stats/VaultStatisticsController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/stats/VaultStatisticsController.java @@ -3,15 +3,13 @@ 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.IntegerBinding; import javafx.beans.binding.LongBinding; +import javafx.beans.property.LongProperty; 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; @@ -41,6 +39,10 @@ public class VaultStatisticsController implements FxController { private final DoubleBinding cacheHitRate; private final DoubleBinding cacheHitDregrees; private final DoubleBinding cacheHitPercentage; + private final LongBinding totalBytesRead; + private final LongBinding totalBytesWritten; + private final LongBinding totalBytesEncrypted; + private final LongBinding totalBytesDecrypted; /*private final IntegerBinding filesRead; private final IntegerBinding filesWritten;*/ private final LongBinding bpsEncrypted; @@ -63,6 +65,10 @@ public class VaultStatisticsController implements FxController { this.cacheHitRate = WeakBindings.bindDouble(stats.cacheHitRateProperty()); this.cacheHitDregrees = cacheHitRate.multiply(-270); this.cacheHitPercentage = cacheHitRate.multiply(100); + this.totalBytesRead = WeakBindings.bindLong(stats.toalBytesReadProperty()); + this.totalBytesWritten = WeakBindings.bindLong(stats.toalBytesWrittenProperty()); + this.totalBytesDecrypted = WeakBindings.bindLong(stats.totalBytesDecryptedProperty()); + this.totalBytesEncrypted = WeakBindings.bindLong(stats.totalBytesEncryptedProperty()); /*this.filesRead = WeakBindings.bindInterger(); this.filesWritten = WeakBindings.bindInterger();*/ this.bpsEncrypted = WeakBindings.bindLong(stats.bytesPerSecondEncryptedProperty()); @@ -89,7 +95,7 @@ public class VaultStatisticsController implements FxController { private class IoSamplingAnimationHandler implements EventHandler { 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 decryptedBytesRead; private final Series encryptedBytesWrite; @@ -114,7 +120,7 @@ public class VaultStatisticsController implements FxController { 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); @@ -122,7 +128,7 @@ public class VaultStatisticsController implements FxController { // 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); @@ -155,9 +161,7 @@ public class VaultStatisticsController implements FxController { return cacheHitPercentage; } - public double getCacheHitPercentage() { - return cacheHitPercentage.get(); - } + public double getCacheHitPercentage() { return cacheHitPercentage.get(); } public DoubleBinding cacheHitDregreesProperty() { return cacheHitDregrees; @@ -167,6 +171,22 @@ public class VaultStatisticsController implements FxController { return cacheHitDregrees.get(); } + public LongBinding totalBytesReadProperty() { return totalBytesRead;} + + public long getTotalBytesRead() { return totalBytesRead.get();} + + public LongBinding totalBytesWrittenProperty() { return totalBytesWritten;} + + public long getTotalBytesWritten() { return totalBytesWritten.get();} + + public LongBinding totalBytesEncryptedProperty() {return totalBytesEncrypted;} + + public long getTotalBytesEncrypted() { return totalBytesEncrypted.get();} + + public LongBinding totalBytesDecryptedProperty() {return totalBytesDecrypted;} + + public long getTotalBytesDecrypted() { return totalBytesDecrypted.get();} + public LongBinding bpsEncryptedProperty() { return bpsEncrypted; } diff --git a/main/ui/src/main/resources/fxml/stats.fxml b/main/ui/src/main/resources/fxml/stats.fxml index 85ea52efb..dfeca90af 100644 --- a/main/ui/src/main/resources/fxml/stats.fxml +++ b/main/ui/src/main/resources/fxml/stats.fxml @@ -12,10 +12,11 @@ + + prefWidth="1000.0" spacing="12"> @@ -35,7 +36,7 @@ - + - + diff --git a/main/ui/src/main/resources/i18n/strings.properties b/main/ui/src/main/resources/i18n/strings.properties index 1209e5485..3e30c16fb 100644 --- a/main/ui/src/main/resources/i18n/strings.properties +++ b/main/ui/src/main/resources/i18n/strings.properties @@ -165,9 +165,17 @@ stats.title=Statistics for %s stats.readDataLabel=Read Data stats.writtenDataLabel=Written Data stats.cacheHitRate=Cache Hit Rate -stats.totalMiB=Total: %s MiB +stats.totalMiBRead=Total Read: +stats.totalMiBWritten=Total Written: +stats.totalMiBEncrypted=Total Encypted: +stats.totalMiBDecrypted=Total Decrypted: stats.totalReads=Number of Reads: %s stats.totalWrites=Number of Writes: %s +stats.data.bytes=%s Bytes +stats.data.kiB=%.1f KiB +stats.data.miB=%.1f MiB +stats.data.giB=%.1f GiB + # Main Window main.closeBtn.tooltip=Close