From 923e58ba1852485936d55cce62c27a6a0eafe696 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Mon, 8 Apr 2019 17:28:22 +0200 Subject: [PATCH] Simplified I/O graph calculation, reusing datapoints (might be a fix for #827, might also be related to #284) --- .../ui/controllers/UnlockedController.java | 52 +++++++++---------- main/ui/src/main/resources/fxml/unlocked.fxml | 15 ++---- 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java index b64ace29c..3171da98f 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java @@ -2,7 +2,7 @@ * Copyright (c) 2014, 2017 Sebastian Stenzel * All rights reserved. * This program and the accompanying materials are made available under the terms of the accompanying LICENSE file. - * + * * Contributors: * Sebastian Stenzel - initial API and implementation ******************************************************************************/ @@ -49,7 +49,7 @@ public class UnlockedController implements ViewController { private static final Logger LOG = LoggerFactory.getLogger(UnlockedController.class); private static final int IO_SAMPLING_STEPS = 100; - private static final double IO_SAMPLING_INTERVAL = 0.25; + private static final double IO_SAMPLING_INTERVAL = 0.5; private final Localization localization; private final ExecutorService executor; @@ -211,43 +211,42 @@ public class UnlockedController implements ViewController { private class IoSamplingAnimationHandler implements EventHandler { private static final double BYTES_TO_MEGABYTES_FACTOR = 1.0 / IO_SAMPLING_INTERVAL / 1024.0 / 1024.0; - private static final double SMOOTHING_FACTOR = 0.3; - private static final long EFFECTIVELY_ZERO = 100000; // 100kb private final Series decryptedBytes; private final Series encryptedBytes; - private int step = 0; - private long oldDecBytes = 0; - private long oldEncBytes = 0; public IoSamplingAnimationHandler(Series decryptedBytes, Series encryptedBytes) { this.decryptedBytes = decryptedBytes; this.encryptedBytes = encryptedBytes; + + // initialize data once and change value of datapoints later: + for (int i = 0; i < IO_SAMPLING_STEPS; i++) { + decryptedBytes.getData().add(new Data<>(i, 0)); + encryptedBytes.getData().add(new Data<>(i, 0)); + } + + xAxis.setLowerBound(0); + xAxis.setUpperBound(IO_SAMPLING_STEPS); } @Override public void handle(ActionEvent event) { - step++; + // move all values one step: + for (int i = 0; i < IO_SAMPLING_STEPS - 1; i++) { + int j = i + 1; + Number tmp = decryptedBytes.getData().get(j).getYValue(); + decryptedBytes.getData().get(i).setYValue(tmp); + tmp = encryptedBytes.getData().get(j).getYValue(); + encryptedBytes.getData().get(i).setYValue(tmp); + } + + // add latest value: final long decBytes = vault.get().pollBytesRead(); - final double smoothedDecBytes = oldDecBytes + SMOOTHING_FACTOR * (decBytes - oldDecBytes); - final double smoothedDecMb = smoothedDecBytes * BYTES_TO_MEGABYTES_FACTOR; - oldDecBytes = smoothedDecBytes > EFFECTIVELY_ZERO ? (long) smoothedDecBytes : 0l; - decryptedBytes.getData().add(new Data(step, smoothedDecMb)); - if (decryptedBytes.getData().size() > IO_SAMPLING_STEPS) { - decryptedBytes.getData().remove(0); - } - + final double decMb = decBytes * BYTES_TO_MEGABYTES_FACTOR; final long encBytes = vault.get().pollBytesWritten(); - final double smoothedEncBytes = oldEncBytes + SMOOTHING_FACTOR * (encBytes - oldEncBytes); - final double smoothedEncMb = smoothedEncBytes * BYTES_TO_MEGABYTES_FACTOR; - oldEncBytes = smoothedEncBytes > EFFECTIVELY_ZERO ? (long) smoothedEncBytes : 0l; - encryptedBytes.getData().add(new Data(step, smoothedEncMb)); - if (encryptedBytes.getData().size() > IO_SAMPLING_STEPS) { - encryptedBytes.getData().remove(0); - } - - xAxis.setLowerBound(step - IO_SAMPLING_STEPS); - xAxis.setUpperBound(step); + final double encMb = encBytes * BYTES_TO_MEGABYTES_FACTOR; + decryptedBytes.getData().get(IO_SAMPLING_STEPS - 1).setYValue(decMb); + encryptedBytes.getData().get(IO_SAMPLING_STEPS - 1).setYValue(encMb); } } @@ -269,6 +268,7 @@ public class UnlockedController implements ViewController { @FunctionalInterface interface LockListener { + void didLock(UnlockedController ctrl); } diff --git a/main/ui/src/main/resources/fxml/unlocked.fxml b/main/ui/src/main/resources/fxml/unlocked.fxml index d87db5000..7d83369cb 100644 --- a/main/ui/src/main/resources/fxml/unlocked.fxml +++ b/main/ui/src/main/resources/fxml/unlocked.fxml @@ -7,22 +7,17 @@ Contributors: Sebastian Stenzel - initial API and implementation --> - - - + - - - - + + - - + - +