Displaying additional stats with a new DataLabel

This commit is contained in:
Martin Beyer
2020-07-20 16:09:45 +02:00
parent ed77a4aacd
commit ed9f16e012
4 changed files with 154 additions and 18 deletions

View File

@@ -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); }
}

View File

@@ -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<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;
@@ -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;
}

View File

@@ -12,10 +12,11 @@
<?import org.cryptomator.ui.controls.FormattedLabel?>
<?import org.cryptomator.ui.controls.ThrougputLabel?>
<?import javafx.scene.Group?>
<?import org.cryptomator.ui.controls.DataLabel?>
<HBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.cryptomator.ui.stats.VaultStatisticsController"
prefWidth="600.0" spacing="12">
prefWidth="1000.0" spacing="12">
<padding>
<Insets topRightBottomLeft="12"/>
</padding>
@@ -35,7 +36,7 @@
</VBox>
<!-- Read -->
<VBox prefWidth="300" prefHeight="200">
<VBox prefWidth="400" prefHeight="200">
<HBox spacing="12" alignment="CENTER">
<Label styleClass="label-large" text="%stats.readDataLabel"/>
<ThrougputLabel styleClass="label-large" alignment="CENTER_RIGHT" minWidth="60" idleFormat="%main.vaultDetail.throughput.idle" kibsFormat="%main.vaultDetail.throughput.kbps"
@@ -53,15 +54,26 @@
</cursor>
</AreaChart>
<VBox spacing="12" alignment="CENTER">
<FormattedLabel styleClass="label-large" alignment="CENTER_RIGHT" minWidth="60" format="%stats.totalMiB" arg1="${controller.bpsRead}"/>
<!-- <FormattedLabel styleClass="label-large" alignment="CENTER_LEFT" minWidth="60" format="%stats.totalReads" arg1="${controller.}"/> -->
<!--<FormattedLabel styleClass="label-large" alignment="CENTER_RIGHT" minWidth="60" format="%stats.totalMiB" arg1="${controller.bpsEncrypted}"/>-->
<HBox alignment="CENTER">
<Label styleClass="label-large" text="%stats.totalMiBRead"/>
<DataLabel styleClass="label-large" alignment="CENTER_RIGHT" minWidth="60" byteFormat="%stats.data.bytes" kibFormat="%stats.data.kiB" mibFormat="%stats.data.miB" gibFormat="%stats.data.giB"
dataInBytes="${controller.totalBytesRead}"/>
</HBox>
<HBox alignment="CENTER">
<Label styleClass="label-large" text="%stats.totalMiBDecrypted"/>
<DataLabel styleClass="label-large" alignment="CENTER_RIGHT" minWidth="60" byteFormat="%stats.data.bytes" kibFormat="%stats.data.kiB" mibFormat="%stats.data.miB" gibFormat="%stats.data.giB"
dataInBytes="${controller.totalBytesDecrypted}"/>
</HBox>
<!--
<FormattedLabel styleClass="label-large" alignment="CENTER_RIGHT" minWidth="60" format="%stats.totalMiBRead" arg1="${controller.totalBytesRead}"/>
<FormattedLabel styleClass="label-large" alignment="CENTER_RIGHT" minWidth="60" format="%stats.totalMiBDecrypted" arg1="${controller.totalBytesDecrypted}"/>
-->
</VBox>
</VBox>
<!-- Write -->
<VBox prefWidth="200" prefHeight="200">
<VBox prefWidth="400" prefHeight="200">
<HBox alignment="CENTER">
<Label styleClass="label-large" text="%stats.writtenDataLabel"/>
<ThrougputLabel styleClass="label-large" alignment="CENTER_RIGHT" minWidth="60" idleFormat="%main.vaultDetail.throughput.idle" kibsFormat="%main.vaultDetail.throughput.kbps"
@@ -79,8 +91,16 @@
</cursor>
</AreaChart>
<VBox spacing="12" alignment="CENTER">
<FormattedLabel styleClass="label-large" alignment="CENTER_RIGHT" minWidth="60" format="%stats.totalMiB" arg1="${controller.bpsWritten}"/>
<!-- <FormattedLabel styleClass="label-large" alignment="CENTER_LEFT" minWidth="60" format="%stats.totalWrites" arg1="${controller.}"/> -->
<HBox alignment="CENTER">
<Label styleClass="label-large" text="%stats.totalMiBWritten"/>
<DataLabel styleClass="label-large" alignment="CENTER_RIGHT" minWidth="60" byteFormat="%stats.data.bytes" kibFormat="%stats.data.kiB" mibFormat="%stats.data.miB" gibFormat="%stats.data.giB"
dataInBytes="${controller.totalBytesWritten}"/>
</HBox>
<HBox alignment="CENTER">
<Label styleClass="label-large" text="%stats.totalMiBEncrypted"/>
<DataLabel styleClass="label-large" alignment="CENTER_RIGHT" minWidth="60" byteFormat="%stats.data.bytes" kibFormat="%stats.data.kiB" mibFormat="%stats.data.miB" gibFormat="%stats.data.giB"
dataInBytes="${controller.totalBytesEncrypted}"/>
</HBox>
</VBox>
</VBox>

View File

@@ -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