Skip to content

Commit

Permalink
Restored I/O graph
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Jan 28, 2016
1 parent 6af4ee0 commit 26aa18d
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 92 deletions.
4 changes: 0 additions & 4 deletions main/filesystem-stats/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
<groupId>org.cryptomator</groupId>
<artifactId>filesystem-api</artifactId>
</dependency>
<dependency>
<groupId>org.cryptomator</groupId>
<artifactId>commons</artifactId>
</dependency>

<!-- Tests -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,12 @@ private StatsFileSystem(Folder root, LongAdder read, LongAdder written) {
this.written = written;
}

public long getBytesRead() {
return read.sum();
public long getThenResetBytesRead() {
return read.sumThenReset();
}

public void resetBytesRead() {
read.reset();
}

public long getBytesWritten() {
return written.sum();
}

public void resetBytesWritten() {
written.reset();
public long getThenResetBytesWritten() {
return written.sumThenReset();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,24 @@ public void testReadAndWriteCounters() {
statsFs.folder("foo").create();
File testFile = statsFs.folder("foo").file("bar");

Assert.assertEquals(0l, statsFs.getBytesRead());
Assert.assertEquals(0l, statsFs.getBytesWritten());
Assert.assertEquals(0l, statsFs.getThenResetBytesRead());
Assert.assertEquals(0l, statsFs.getThenResetBytesWritten());

try (WritableFile w = testFile.openWritable()) {
w.write(ByteBuffer.allocate(15));
}

Assert.assertEquals(0l, statsFs.getBytesRead());
Assert.assertEquals(15l, statsFs.getBytesWritten());

statsFs.resetBytesWritten();

Assert.assertEquals(0l, statsFs.getBytesRead());
Assert.assertEquals(0l, statsFs.getBytesWritten());
Assert.assertEquals(0l, statsFs.getThenResetBytesRead());
Assert.assertEquals(15l, statsFs.getThenResetBytesWritten());
Assert.assertEquals(0l, statsFs.getThenResetBytesWritten());

try (ReadableFile r = testFile.openReadable()) {
r.read(ByteBuffer.allocate(3));
}

Assert.assertEquals(3l, statsFs.getBytesRead());
Assert.assertEquals(0l, statsFs.getBytesWritten());

statsFs.resetBytesRead();

Assert.assertEquals(0l, statsFs.getBytesRead());
Assert.assertEquals(0l, statsFs.getBytesWritten());
Assert.assertEquals(3l, statsFs.getThenResetBytesRead());
Assert.assertEquals(0l, statsFs.getThenResetBytesRead());
Assert.assertEquals(0l, statsFs.getThenResetBytesWritten());
}

}
5 changes: 5 additions & 0 deletions main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
<artifactId>filesystem-crypto</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.cryptomator</groupId>
<artifactId>filesystem-stats</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.cryptomator</groupId>
Expand Down
4 changes: 4 additions & 0 deletions main/ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<groupId>org.cryptomator</groupId>
<artifactId>filesystem-crypto</artifactId>
</dependency>
<dependency>
<groupId>org.cryptomator</groupId>
<artifactId>filesystem-stats</artifactId>
</dependency>
<dependency>
<groupId>org.cryptomator</groupId>
<artifactId>frontend-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javafx.fxml.FXML;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.chart.XYChart.Series;
import javafx.scene.control.Label;
import javafx.stage.Stage;
Expand Down Expand Up @@ -126,7 +127,7 @@ private void macWarningsDidChange(ListChangeListener.Change<? extends String> ch
// IO Graph
// ****************************************

private void startIoSampling(final Object sampler) {
private void startIoSampling() {
final Series<Number, Number> decryptedBytes = new Series<>();
decryptedBytes.setName("decrypted");
final Series<Number, Number> encryptedBytes = new Series<>();
Expand All @@ -136,7 +137,7 @@ private void startIoSampling(final Object sampler) {
ioGraph.getData().add(encryptedBytes);

ioAnimation = new Timeline();
ioAnimation.getKeyFrames().add(new KeyFrame(Duration.seconds(IO_SAMPLING_INTERVAL), new IoSamplingAnimationHandler(sampler, decryptedBytes, encryptedBytes)));
ioAnimation.getKeyFrames().add(new KeyFrame(Duration.seconds(IO_SAMPLING_INTERVAL), new IoSamplingAnimationHandler(decryptedBytes, encryptedBytes)));
ioAnimation.setCycleCount(Animation.INDEFINITE);
ioAnimation.play();
}
Expand All @@ -153,45 +154,41 @@ private class IoSamplingAnimationHandler implements EventHandler<ActionEvent> {
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 Object sampler;
private final Series<Number, Number> decryptedBytes;
private final Series<Number, Number> encryptedBytes;
private final int step = 0;
private final long oldDecBytes = 0;
private final long oldEncBytes = 0;
private int step = 0;
private long oldDecBytes = 0;
private long oldEncBytes = 0;

public IoSamplingAnimationHandler(Object sampler, Series<Number, Number> decryptedBytes, Series<Number, Number> encryptedBytes) {
this.sampler = sampler;
public IoSamplingAnimationHandler(Series<Number, Number> decryptedBytes, Series<Number, Number> encryptedBytes) {
this.decryptedBytes = decryptedBytes;
this.encryptedBytes = encryptedBytes;
}

@Override
public void handle(ActionEvent event) {
/*
* step++;
*
* final long decBytes = sampler.pollDecryptedBytes(true);
* 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<Number, Number>(step, smoothedDecMb));
* if (decryptedBytes.getData().size() > IO_SAMPLING_STEPS) {
* decryptedBytes.getData().remove(0);
* }
*
* final long encBytes = sampler.pollEncryptedBytes(true);
* 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<Number, Number>(step, smoothedEncMb));
* if (encryptedBytes.getData().size() > IO_SAMPLING_STEPS) {
* encryptedBytes.getData().remove(0);
* }
*
* xAxis.setLowerBound(step - IO_SAMPLING_STEPS);
* xAxis.setUpperBound(step);
*/
step++;

final long decBytes = vault.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<Number, Number>(step, smoothedDecMb));
if (decryptedBytes.getData().size() > IO_SAMPLING_STEPS) {
decryptedBytes.getData().remove(0);
}

final long encBytes = vault.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<Number, Number>(step, smoothedEncMb));
if (encryptedBytes.getData().size() > IO_SAMPLING_STEPS) {
encryptedBytes.getData().remove(0);
}

xAxis.setLowerBound(step - IO_SAMPLING_STEPS);
xAxis.setUpperBound(step);
}
}

Expand All @@ -214,15 +211,9 @@ public void setVault(Vault vault) {
}
});

// sample crypto-throughput:
/*
* stopIoSampling();
* if (vault.getCryptor() instanceof CryptorIOSampling) {
* startIoSampling((CryptorIOSampling) vault.getCryptor());
* } else {
* ioGraph.setVisible(false);
* }
*/
// (re)start throughput statistics:
stopIoSampling();
startIoSampling();
}

public LockListener getListener() {
Expand Down
60 changes: 41 additions & 19 deletions main/ui/src/main/java/org/cryptomator/ui/model/Vault.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.cryptomator.filesystem.crypto.CryptoFileSystemDelegate;
import org.cryptomator.filesystem.crypto.CryptoFileSystemFactory;
import org.cryptomator.filesystem.nio.NioFileSystem;
import org.cryptomator.filesystem.stats.StatsFileSystem;
import org.cryptomator.frontend.CommandFailedException;
import org.cryptomator.frontend.Frontend;
import org.cryptomator.frontend.Frontend.MountParam;
Expand All @@ -42,7 +43,6 @@ public class Vault implements Serializable, CryptoFileSystemDelegate {

private static final long serialVersionUID = 3754487289683599469L;

@Deprecated
public static final String VAULT_FILE_EXTENSION = ".cryptomator";

@Deprecated
Expand All @@ -58,6 +58,7 @@ public class Vault implements Serializable, CryptoFileSystemDelegate {

private String mountName;
private Character winDriveLetter;
private Optional<StatsFileSystem> statsFileSystem = Optional.empty();
private DeferredClosable<Frontend> filesystemFrontend = DeferredClosable.empty();

/**
Expand All @@ -76,14 +77,10 @@ public class Vault implements Serializable, CryptoFileSystemDelegate {
}
}

public boolean isValidVaultDirectory() {
return Files.isDirectory(path) && path.getFileName().toString().endsWith(VAULT_FILE_EXTENSION);
}

public boolean containsMasterKey() throws IOException {
final Path masterKeyPath = path.resolve(VAULT_MASTERKEY_FILE);
return Files.isRegularFile(masterKeyPath);
}
/*
* ******************************************************************************
* Commands
********************************************************************************/

public void create(CharSequence passphrase) throws IOException {
try {
Expand All @@ -110,18 +107,21 @@ public synchronized void activateFrontend(CharSequence passphrase) throws Fronte
try {
FileSystem fs = NioFileSystem.rootedAt(path);
FileSystem cryptoFs = cryptoFileSystemFactory.unlockExisting(fs, passphrase, this);
StatsFileSystem statsFs = new StatsFileSystem(cryptoFs);
statsFileSystem = Optional.of(statsFs);
String contextPath = StringUtils.prependIfMissing(mountName, "/");
Frontend frontend = frontendFactory.get().create(cryptoFs, contextPath);
Frontend frontend = frontendFactory.get().create(statsFs, contextPath);
filesystemFrontend = closer.closeLater(frontend);
setUnlocked(true);
unlocked.set(true);
} catch (UncheckedIOException e) {
throw new FrontendCreationFailedException(e);
}
}

public synchronized void deactivateFrontend() {
filesystemFrontend.close();
setUnlocked(false);
statsFileSystem = Optional.empty();
unlocked.set(false);
}

private Map<MountParam, Optional<String>> getMountParams() {
Expand Down Expand Up @@ -150,7 +150,10 @@ public void unmount() throws CommandFailedException {
Optionals.ifPresent(filesystemFrontend.get(), Frontend::unmount);
}

/* Delegate Methods */
/*
* ******************************************************************************
* Delegate methods
********************************************************************************/

@Override
public void authenticationFailed(String cleartextPath) {
Expand All @@ -162,7 +165,10 @@ public boolean shouldSkipAuthentication(String cleartextPath) {
return namesOfResourcesWithInvalidMac.contains(cleartextPath);
}

/* Getter/Setter */
/*
* ******************************************************************************
* Getter/Setter
********************************************************************************/

public Path getPath() {
return path;
Expand All @@ -175,6 +181,15 @@ public String getName() {
return StringUtils.removeEnd(path.getFileName().toString(), VAULT_FILE_EXTENSION);
}

public boolean isValidVaultDirectory() {
return Files.isDirectory(path) && path.getFileName().toString().endsWith(VAULT_FILE_EXTENSION);
}

public boolean containsMasterKey() throws IOException {
final Path masterKeyPath = path.resolve(VAULT_MASTERKEY_FILE);
return Files.isRegularFile(masterKeyPath);
}

public ObjectProperty<Boolean> unlockedProperty() {
return unlocked;
}
Expand All @@ -183,10 +198,6 @@ public boolean isUnlocked() {
return unlocked.get();
}

public void setUnlocked(boolean unlocked) {
this.unlocked.set(unlocked);
}

public ObservableList<String> getNamesOfResourcesWithInvalidMac() {
return namesOfResourcesWithInvalidMac;
}
Expand All @@ -195,6 +206,14 @@ public Set<String> getWhitelistedResourcesWithInvalidMac() {
return whitelistedResourcesWithInvalidMac;
}

public long pollBytesRead() {
return statsFileSystem.map(StatsFileSystem::getThenResetBytesRead).orElse(0l);
}

public long pollBytesWritten() {
return statsFileSystem.map(StatsFileSystem::getThenResetBytesWritten).orElse(0l);
}

/**
* Tries to form a similar string using the regular latin alphabet.
*
Expand Down Expand Up @@ -247,7 +266,10 @@ public void setWinDriveLetter(Character winDriveLetter) {
this.winDriveLetter = winDriveLetter;
}

/* hashcode/equals */
/*
* ******************************************************************************
* Hashcode / Equals
********************************************************************************/

@Override
public int hashCode() {
Expand Down

0 comments on commit 26aa18d

Please sign in to comment.