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");

View File

@@ -113,9 +113,8 @@ abstract class BaseControllerImpl extends DbControllerImpl
long start = now();
Collection<BlogPostHeader> headers =
blogManager.getPostHeaders(groupId);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Loading headers took " + duration + " ms");
LOG.fine("Loading headers took " + (now() - start) + " ms");
Collection<BlogPostItem> items = new ArrayList<>(headers.size());
start = now();
for (BlogPostHeader h : headers) {
@@ -123,9 +122,8 @@ abstract class BaseControllerImpl extends DbControllerImpl
BlogPostItem item = getItem(h);
items.add(item);
}
duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Loading bodies took " + duration + " ms");
LOG.fine("Loading bodies took " + (now() - start) + " ms");
return items;
}
@@ -143,9 +141,8 @@ abstract class BaseControllerImpl extends DbControllerImpl
try {
long start = now();
BlogPostItem item = getItem(header);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Loading body took " + duration + " ms");
LOG.fine("Loading body took " + (now() - start) + " ms");
handler.onResult(item);
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
@@ -170,9 +167,8 @@ abstract class BaseControllerImpl extends DbControllerImpl
long start = now();
BlogPostHeader header1 = getPostHeader(g, m);
BlogPostItem item = getItem(header1);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Loading post took " + duration + " ms");
LOG.fine("Loading post took " + (now() - start) + " ms");
handler.onResult(item);
} catch (DbException e) {
if (LOG.isLoggable(WARNING))

View File

@@ -161,9 +161,8 @@ class BlogControllerImpl extends BaseControllerImpl
boolean ours = a.getId().equals(b.getAuthor().getId());
boolean removable = blogManager.canBeRemoved(b);
BlogItem blog = new BlogItem(b, ours, removable);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Loading blog took " + duration + " ms");
LOG.fine("Loading blog took " + (now() - start) + " ms");
handler.onResult(blog);
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
@@ -181,9 +180,8 @@ class BlogControllerImpl extends BaseControllerImpl
long start = now();
Blog b = blogManager.getBlog(groupId);
blogManager.removeBlog(b);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Removing blog took " + duration + " ms");
LOG.fine("Removing blog took " + (now() - start) + " ms");
handler.onResult(null);
} catch (DbException e) {
if (LOG.isLoggable(WARNING))

View File

@@ -110,9 +110,10 @@ class FeedControllerImpl extends BaseControllerImpl
LOG.log(WARNING, e.toString(), e);
}
}
long duration = now() - start;
if (LOG.isLoggable(FINE))
if (LOG.isLoggable(FINE)) {
long duration = now() - start;
LOG.fine("Loading all posts took " + duration + " ms");
}
handler.onResult(posts);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);

View File

@@ -209,9 +209,8 @@ public class ContactListFragment extends BaseFragment implements EventListener {
// Continue
}
}
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Full load took " + duration + " ms");
LOG.fine("Full load took " + (now() - start) + " ms");
displayContacts(revision, contacts);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);

View File

@@ -298,9 +298,8 @@ public class ConversationActivity extends BriarActivity
contactName = contact.getAuthor().getName();
contactAuthorId = contact.getAuthor().getId();
}
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Loading contact took " + duration + " ms");
LOG.fine("Loading contact took " + (now() - start) + " ms");
loadMessages();
displayContactDetails();
} catch (NoSuchContactException e) {
@@ -359,9 +358,10 @@ public class ConversationActivity extends BriarActivity
invitations.addAll(forumInvitations);
invitations.addAll(blogInvitations);
invitations.addAll(groupInvitations);
long duration = now() - start;
if (LOG.isLoggable(FINE))
if (LOG.isLoggable(FINE)) {
long duration = now() - start;
LOG.fine("Loading messages took " + duration + " ms");
}
displayMessages(revision, headers, introductions, invitations);
} catch (NoSuchContactException e) {
finishOnUiThread();
@@ -442,9 +442,8 @@ public class ConversationActivity extends BriarActivity
try {
long start = now();
String body = messagingManager.getMessageBody(m);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Loading body took " + duration + " ms");
LOG.fine("Loading body took " + (now() - start) + " ms");
displayMessageBody(m, body);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
@@ -693,9 +692,8 @@ public class ConversationActivity extends BriarActivity
try {
long start = now();
messagingManager.addLocalMessage(m);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Storing message took " + duration + " ms");
LOG.fine("Storing message took " + (now() - start) + " ms");
Message message = m.getMessage();
PrivateMessageHeader h = new PrivateMessageHeader(
message.getId(), message.getGroupId(),
@@ -820,9 +818,8 @@ public class ConversationActivity extends BriarActivity
try {
long start = now();
messagingManager.setReadFlag(g, m, true);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Marking read took " + duration + " ms");
LOG.fine("Marking read took " + (now() - start) + " ms");
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
}

View File

@@ -125,9 +125,8 @@ public class CreateForumActivity extends BriarActivity {
try {
long start = now();
Forum f = forumManager.addForum(name);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Storing forum took " + duration + " ms");
LOG.fine("Storing forum took " + (now() - start) + " ms");
displayForum(f);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);

View File

@@ -169,9 +169,8 @@ public class ForumListFragment extends BaseEventFragment implements
// Continue
}
}
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Full load took " + duration + " ms");
LOG.fine("Full load took " + (now() - start) + " ms");
displayForums(revision, forums);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
@@ -197,9 +196,10 @@ public class ForumListFragment extends BaseEventFragment implements
try {
long start = now();
int available = forumSharingManager.getInvitations().size();
long duration = now() - start;
if (LOG.isLoggable(FINE))
if (LOG.isLoggable(FINE)) {
long duration = now() - start;
LOG.fine("Loading available took " + duration + " ms");
}
displayAvailableForums(available);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);

View File

@@ -89,9 +89,8 @@ public class PasswordControllerImpl extends ConfigControllerImpl
String encryptDatabaseKey(SecretKey key, String password) {
long start = now();
byte[] encrypted = crypto.encryptWithPassword(key.getBytes(), password);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Key derivation took " + duration + " ms");
LOG.fine("Key derivation took " + (now() - start) + " ms");
return StringUtils.toHexString(encrypted);
}
}

View File

@@ -162,9 +162,8 @@ class GroupListControllerImpl extends DbControllerImpl
// Continue
}
}
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Loading groups took " + duration + " ms");
LOG.fine("Loading groups took " + (now() - start) + " ms");
handler.onResult(items);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
@@ -179,9 +178,8 @@ class GroupListControllerImpl extends DbControllerImpl
try {
long start = now();
groupManager.removePrivateGroup(g);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Removing group took " + duration + " ms");
LOG.fine("Removing group took " + (now() - start) + " ms");
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
handler.onException(e);

View File

@@ -249,9 +249,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
Settings btSettings = settingsManager.getSettings(BT_NAMESPACE);
Settings torSettings =
settingsManager.getSettings(TOR_NAMESPACE);
long duration = now() - start;
if (LOG.isLoggable(FINE))
if (LOG.isLoggable(FINE)) {
long duration = now() - start;
LOG.fine("Loading settings took " + duration + " ms");
}
boolean btSetting =
btSettings.getBoolean(PREF_BT_ENABLE, false);
int torSetting = torSettings.getInt(PREF_TOR_NETWORK,
@@ -439,9 +440,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
s.putInt(PREF_TOR_NETWORK, torSetting);
long start = now();
settingsManager.mergeSettings(s, TOR_NAMESPACE);
long duration = now() - start;
if (LOG.isLoggable(FINE))
if (LOG.isLoggable(FINE)) {
long duration = now() - start;
LOG.fine("Merging settings took " + duration + " ms");
}
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
}
@@ -455,9 +457,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
s.putBoolean(PREF_BT_ENABLE, btSetting);
long start = now();
settingsManager.mergeSettings(s, BT_NAMESPACE);
long duration = now() - start;
if (LOG.isLoggable(FINE))
if (LOG.isLoggable(FINE)) {
long duration = now() - start;
LOG.fine("Merging settings took " + duration + " ms");
}
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
}
@@ -469,9 +472,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
try {
long start = now();
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
long duration = now() - start;
if (LOG.isLoggable(FINE))
if (LOG.isLoggable(FINE)) {
long duration = now() - start;
LOG.fine("Merging settings took " + duration + " ms");
}
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
}

View File

@@ -98,9 +98,10 @@ public abstract class InvitationControllerImpl<I extends InvitationItem>
try {
long start = now();
Collection<I> invitations = new ArrayList<>(getInvitations());
long duration = now() - start;
if (LOG.isLoggable(FINE))
if (LOG.isLoggable(FINE)) {
long duration = now() - start;
LOG.fine("Loading invitations took " + duration + " ms");
}
handler.onResult(invitations);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);

View File

@@ -135,9 +135,8 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
try {
long start = now();
G groupItem = loadNamedGroup();
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Loading group took " + duration + " ms");
LOG.fine("Loading group took " + (now() - start) + " ms");
handler.onResult(groupItem);
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
@@ -159,9 +158,8 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
// Load headers
long start = now();
Collection<H> headers = loadHeaders();
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Loading headers took " + duration + " ms");
LOG.fine("Loading headers took " + (now() - start) + " ms");
// Load bodies into cache
start = now();
@@ -171,9 +169,8 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
loadMessageBody(header));
}
}
duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Loading bodies took " + duration + " ms");
LOG.fine("Loading bodies took " + (now() - start) + " ms");
// Build and hand over items
handler.onResult(buildItems(headers));
@@ -203,9 +200,8 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
for (I i : items) {
markRead(i.getId());
}
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Marking read took " + duration + " ms");
LOG.fine("Marking read took " + (now() - start) + " ms");
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
}
@@ -222,9 +218,8 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
long start = now();
H header = addLocalMessage(msg);
bodyCache.put(msg.getMessage().getId(), body);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Storing message took " + duration + " ms");
LOG.fine("Storing message took " + (now() - start) + " ms");
resultHandler.onResult(buildItem(header, body));
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
@@ -243,9 +238,8 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
long start = now();
G groupItem = loadNamedGroup();
deleteNamedGroup(groupItem);
long duration = now() - start;
if (LOG.isLoggable(FINE))
LOG.fine("Removing group took " + duration + " ms");
LOG.fine("Removing group took " + (now() - start) + " ms");
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
handler.onException(e);