Don't calculate duration unless needed.

This commit is contained in:
akwizgran
2018-06-15 15:52:05 +01:00
parent 08931e64cb
commit 0d2a91289f
17 changed files with 65 additions and 87 deletions

View File

@@ -136,9 +136,8 @@ class CryptoComponentImpl implements CryptoComponent {
byte allZero = 0;
for (byte b : secret) allZero |= b;
if (allZero == 0) throw new GeneralSecurityException();
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Deriving shared secret took " + duration + " ms");
LOG.fine("Deriving shared secret took " + (now() - start) + " ms");
return secret;
}

View File

@@ -56,9 +56,10 @@ class ScryptKdf implements PasswordBasedKdf {
byte[] passwordBytes = StringUtils.toUtf8(password);
SecretKey k = new SecretKey(SCrypt.generate(passwordBytes, salt, cost,
BLOCK_SIZE, PARALLELIZATION, SecretKey.LENGTH));
long duration = now() - start;
if (LOG.isLoggable(FINE))
if (LOG.isLoggable(FINE)) {
long duration = now() - start;
LOG.fine("Deriving key from password took " + duration + " ms");
}
return k;
}
}

View File

@@ -81,9 +81,8 @@ class Sec1KeyParser implements KeyParser {
// Construct a public key from the point (x, y) and the params
ECPublicKeyParameters k = new ECPublicKeyParameters(pub, params);
PublicKey p = new Sec1PublicKey(k);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Parsing public key took " + duration + " ms");
LOG.fine("Parsing public key took " + (now() - start) + " ms");
return p;
}
@@ -100,9 +99,8 @@ class Sec1KeyParser implements KeyParser {
// Construct a private key from the private value and the params
ECPrivateKeyParameters k = new ECPrivateKeyParameters(d, params);
PrivateKey p = new Sec1PrivateKey(k, keyBits);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Parsing private key took " + duration + " ms");
LOG.fine("Parsing private key took " + (now() - start) + " ms");
return p;
}
}

View File

@@ -109,18 +109,18 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
byte[] privateKey = keyPair.getPrivate().getEncoded();
LocalAuthor localAuthor = authorFactory
.createLocalAuthor(nickname, publicKey, privateKey);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Creating local author took " + duration + " ms");
LOG.fine("Creating local author took " + (now() - start) + " ms");
return localAuthor;
}
private void registerLocalAuthor(LocalAuthor author) throws DbException {
long start = now();
identityManager.registerLocalAuthor(author);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Registering local author took " + duration + " ms");
if (LOG.isLoggable(FINE)) {
LOG.fine("Registering local author took " + (now() - start)
+ " ms");
}
}
@Override
@@ -134,8 +134,8 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
long start = now();
boolean reopened = db.open(this);
long duration = now() - start;
if (LOG.isLoggable(FINE)) {
long duration = now() - start;
if (reopened)
LOG.fine("Reopening database took " + duration + " ms");
else LOG.fine("Creating database took " + duration + " ms");
@@ -154,11 +154,10 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
for (Client c : clients) {
start = now();
c.createLocalState(txn);
duration = now() - start;
if (LOG.isLoggable(FINE)) {
LOG.fine("Starting client "
+ c.getClass().getSimpleName()
+ " took " + duration + " ms");
+ " took " + (now() - start) + " ms");
}
}
db.commitTransaction(txn);
@@ -168,10 +167,9 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
for (Service s : services) {
start = now();
s.startService();
duration = now() - start;
if (LOG.isLoggable(FINE)) {
LOG.fine("Starting service " + s.getClass().getSimpleName()
+ " took " + duration + " ms");
+ " took " + (now() - start) + " ms");
}
}
@@ -217,10 +215,9 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
for (Service s : services) {
long start = now();
s.stopService();
long duration = now() - start;
if (LOG.isLoggable(FINE)) {
LOG.fine("Stopping service " + s.getClass().getSimpleName()
+ " took " + duration + " ms");
+ " took " + (now() - start) + " ms");
}
}
for (ExecutorService e : executors) {
@@ -232,9 +229,8 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
}
long start = now();
db.close();
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Closing database took " + duration + " ms");
LOG.fine("Closing database took " + (now() - start) + " ms");
shutdownLatch.countDown();
} catch (DbException | ServiceException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);

View File

@@ -209,10 +209,9 @@ class PluginManagerImpl implements PluginManager, Service {
try {
long start = now();
plugin.start();
long duration = now() - start;
if (LOG.isLoggable(FINE)) {
LOG.fine("Starting plugin " + plugin.getId() + " took " +
duration + " ms");
LOG.fine("Starting plugin " + plugin.getId()
+ " took " + (now() - start) + " ms");
}
} catch (PluginException e) {
if (LOG.isLoggable(WARNING)) {
@@ -247,10 +246,9 @@ class PluginManagerImpl implements PluginManager, Service {
// Stop the plugin
long start = now();
plugin.stop();
long duration = now() - start;
if (LOG.isLoggable(FINE)) {
LOG.fine("Stopping plugin " + plugin.getId()
+ " took " + duration + " ms");
+ " took " + (now() - start) + " ms");
}
} catch (InterruptedException e) {
LOG.warning("Interrupted while waiting for plugin to stop");