preperation for displaying en-de-crypted bytes per second

This commit is contained in:
Martin Beyer
2020-07-20 11:00:59 +02:00
parent 3519346df9
commit ff2fa70bd6
4 changed files with 91 additions and 11 deletions

View File

@@ -3,9 +3,11 @@ package org.cryptomator.common.vaults;
import javafx.application.Platform;
import javafx.beans.Observable;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.LongProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleLongProperty;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.ScheduledService;
@@ -31,7 +33,11 @@ public class VaultStats {
private final ScheduledService<Optional<CryptoFileSystemStats>> updateService;
private final LongProperty bytesPerSecondRead = new SimpleLongProperty();
private final LongProperty bytesPerSecondWritten = new SimpleLongProperty();
private final LongProperty bytesPerSecondEncrypted = new SimpleLongProperty();
private final LongProperty bytesPerSecondDecrypted = new SimpleLongProperty();
private final DoubleProperty cacheHitRate = new SimpleDoubleProperty();
//private final IntegerProperty filesRead = new SimpleIntegerProperty();
//private final IntegerProperty filesWritten = new SimpleIntegerProperty();
@Inject
VaultStats(AtomicReference<CryptoFileSystem> fs, ObjectProperty<VaultState> state, ExecutorService executor) {
@@ -60,6 +66,8 @@ public class VaultStats {
bytesPerSecondRead.set(stats.map(CryptoFileSystemStats::pollBytesRead).orElse(0l));
bytesPerSecondWritten.set(stats.map(CryptoFileSystemStats::pollBytesWritten).orElse(0l));
cacheHitRate.set(stats.map(this::getCacheHitRate).orElse(0.0));
bytesPerSecondDecrypted.set(stats.map(CryptoFileSystemStats::pollBytesDecrypted).orElse(0l));
bytesPerSecondEncrypted.set(stats.map(CryptoFileSystemStats::pollBytesEncrypted).orElse(0l));
}
private double getCacheHitRate(CryptoFileSystemStats stats) {
@@ -110,6 +118,22 @@ public class VaultStats {
return bytesPerSecondWritten.get();
}
public LongProperty bytesPerSecondEncryptedProperty() {
return bytesPerSecondEncrypted;
}
public long getBytesPerSecondEnrypted() {
return bytesPerSecondEncrypted.get();
}
public LongProperty bytesPerSecondDecryptedProperty() {
return bytesPerSecondDecrypted;
}
public long getBytesPerSecondDecrypted() {
return bytesPerSecondDecrypted.get();
}
public DoubleProperty cacheHitRateProperty() {
return cacheHitRate;
}
@@ -117,5 +141,6 @@ public class VaultStats {
public double getCacheHitRate() {
return cacheHitRate.get();
}
}

View File

@@ -1,6 +1,7 @@
package org.cryptomator.ui.common;
import javafx.beans.binding.DoubleBinding;
import javafx.beans.binding.IntegerBinding;
import javafx.beans.binding.LongBinding;
import javafx.beans.binding.StringBinding;
import javafx.beans.value.ObservableObjectValue;
@@ -70,4 +71,23 @@ public final class WeakBindings {
};
}
/**
* Create a new IntegerBinding that listens to changes from the given observable without being strongly referenced by it.
*
* @param observable The observable
* @return a IntegerBinding weakly referenced from the given observable
*/
public static IntegerBinding bindInterger(ObservableValue<Number> observable) {
return new IntegerBinding() {
{
bind(observable);
}
@Override
protected int computeValue() {
return observable.getValue().intValue();
}
};
}
}

View File

@@ -5,6 +5,7 @@ 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.event.ActionEvent;
import javafx.event.EventHandler;
@@ -40,6 +41,10 @@ public class VaultStatisticsController implements FxController {
private final DoubleBinding cacheHitRate;
private final DoubleBinding cacheHitDregrees;
private final DoubleBinding cacheHitPercentage;
/*private final IntegerBinding filesRead;
private final IntegerBinding filesWritten;*/
private final LongBinding bpsEncrypted;
private final LongBinding bpsDecrypted;
public AreaChart<Number, Number> readChart;
public AreaChart<Number, Number> writeChart;
@@ -58,6 +63,10 @@ public class VaultStatisticsController implements FxController {
this.cacheHitRate = WeakBindings.bindDouble(stats.cacheHitRateProperty());
this.cacheHitDregrees = cacheHitRate.multiply(-270);
this.cacheHitPercentage = cacheHitRate.multiply(100);
/*this.filesRead = WeakBindings.bindInterger();
this.filesWritten = WeakBindings.bindInterger();*/
this.bpsEncrypted = WeakBindings.bindLong(stats.bytesPerSecondEncryptedProperty());
this.bpsDecrypted = WeakBindings.bindLong(stats.bytesPerSecondDecryptedProperty());
this.ioAnimation = new Timeline(); //TODO Research better timer
ioAnimation.getKeyFrames().add(new KeyFrame(Duration.seconds(IO_SAMPLING_INTERVAL), new IoSamplingAnimationHandler(readData, writeData)));
@@ -157,4 +166,20 @@ public class VaultStatisticsController implements FxController {
public double getCacheHitDregrees() {
return cacheHitDregrees.get();
}
public LongBinding bpsEncryptedProperty() {
return bpsEncrypted;
}
public long getBpsEncrypted() {
return bpsEncrypted.get();
}
public LongBinding bpsDecryptedProperty() {
return bpsDecrypted;
}
public long getBpsDecrypted() {
return bpsDecrypted.get();
}
}

View File

@@ -19,7 +19,7 @@
<padding>
<Insets topRightBottomLeft="12"/>
</padding>
<!-- Caching -->
<VBox prefWidth="200" prefHeight="200">
<StackPane>
@@ -28,18 +28,18 @@
<Arc styleClass="cache-arc-foreground" centerX="100" centerY="100" radiusX="100" radiusY="100" startAngle="225" length="${controller.cacheHitDregrees}"/>
</Group>
<VBox StackPane.alignment="CENTER" alignment="CENTER">
<FormattedLabel styleClass="label-large" format="\%1.0f %%" arg1="${controller.cacheHitPercentage}" />
<Label text="%stats.cacheHitRate" />
<FormattedLabel styleClass="label-large" format="\%1.0f %%" arg1="${controller.cacheHitPercentage}"/>
<Label text="%stats.cacheHitRate"/>
</VBox>
</StackPane>
</VBox>
<!-- Read -->
<VBox prefWidth="200" prefHeight="200">
<HBox spacing="12">
<Label text="%stats.readDataLabel"/>
<VBox prefWidth="300" 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"
mibsFormat="%main.vaultDetail.throughput.mbps" bytesPerSecond="${controller.bpsRead}"/>
mibsFormat="%main.vaultDetail.throughput.mbps" bytesPerSecond="${controller.bpsRead}"/>
</HBox>
<AreaChart fx:id="readChart" styleClass="io-stats" createSymbols="false" animated="false">
<xAxis>
@@ -52,12 +52,18 @@
<Cursor fx:constant="DEFAULT"/>
</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}"/>-->
</VBox>
</VBox>
<!-- Write -->
<VBox prefWidth="200" prefHeight="200">
<HBox>
<Label text="%stats.writtenDataLabel"/>
<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"
mibsFormat="%main.vaultDetail.throughput.mbps" bytesPerSecond="${controller.bpsWritten}"/>
</HBox>
@@ -72,6 +78,10 @@
<Cursor fx:constant="DEFAULT"/>
</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.}"/> -->
</VBox>
</VBox>
</HBox>