mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Use System.nanoTime() for timing measurements.
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package org.briarproject.bramble.util;
|
||||
|
||||
public class TimeUtils {
|
||||
|
||||
private static final int NANOS_PER_MILLI = 1000 * 1000;
|
||||
|
||||
/**
|
||||
* Returns the elapsed time in milliseconds since some arbitrary
|
||||
* starting time. This is only useful for measuring elapsed time.
|
||||
*/
|
||||
public static long now() {
|
||||
return System.nanoTime() / NANOS_PER_MILLI;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import java.util.logging.Logger;
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
|
||||
/**
|
||||
* An {@link Executor} that delegates its tasks to another {@link Executor}
|
||||
@@ -46,10 +47,10 @@ public class PoliteExecutor implements Executor {
|
||||
|
||||
@Override
|
||||
public void execute(Runnable r) {
|
||||
long submitted = System.currentTimeMillis();
|
||||
long submitted = now();
|
||||
Runnable wrapped = () -> {
|
||||
if (log.isLoggable(FINE)) {
|
||||
long queued = System.currentTimeMillis() - submitted;
|
||||
long queued = now() - submitted;
|
||||
log.fine("Queue time " + queued + " ms");
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
|
||||
@NotNullByDefault
|
||||
public class TimeLoggingExecutor extends ThreadPoolExecutor {
|
||||
@@ -27,13 +28,13 @@ public class TimeLoggingExecutor extends ThreadPoolExecutor {
|
||||
@Override
|
||||
public void execute(Runnable r) {
|
||||
if (log.isLoggable(FINE)) {
|
||||
long submitted = System.currentTimeMillis();
|
||||
long submitted = now();
|
||||
super.execute(() -> {
|
||||
long started = System.currentTimeMillis();
|
||||
long started = now();
|
||||
long queued = started - submitted;
|
||||
log.fine("Queue time " + queued + " ms");
|
||||
r.run();
|
||||
long executing = System.currentTimeMillis() - started;
|
||||
long executing = now() - started;
|
||||
log.fine("Execution time " + executing + " ms");
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -33,6 +33,7 @@ import javax.inject.Inject;
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static org.briarproject.bramble.util.ByteUtils.INT_32_BYTES;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
|
||||
@NotNullByDefault
|
||||
class CryptoComponentImpl implements CryptoComponent {
|
||||
@@ -128,14 +129,14 @@ class CryptoComponentImpl implements CryptoComponent {
|
||||
throw new IllegalArgumentException();
|
||||
if (!(pub instanceof Curve25519PublicKey))
|
||||
throw new IllegalArgumentException();
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
byte[] secret = curve25519.calculateAgreement(pub.getEncoded(),
|
||||
priv.getEncoded());
|
||||
// If the shared secret is all zeroes, the public key is invalid
|
||||
byte allZero = 0;
|
||||
for (byte b : secret) allZero |= b;
|
||||
if (allZero == 0) throw new GeneralSecurityException();
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Deriving shared secret took " + duration + " ms");
|
||||
return secret;
|
||||
|
||||
@@ -11,6 +11,7 @@ import javax.inject.Inject;
|
||||
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
|
||||
class ScryptKdf implements PasswordBasedKdf {
|
||||
|
||||
@@ -51,11 +52,11 @@ class ScryptKdf implements PasswordBasedKdf {
|
||||
|
||||
@Override
|
||||
public SecretKey deriveKey(String password, byte[] salt, int cost) {
|
||||
long start = System.currentTimeMillis();
|
||||
long start = now();
|
||||
byte[] passwordBytes = StringUtils.toUtf8(password);
|
||||
SecretKey k = new SecretKey(SCrypt.generate(passwordBytes, salt, cost,
|
||||
BLOCK_SIZE, PARALLELIZATION, SecretKey.LENGTH));
|
||||
long duration = System.currentTimeMillis() - start;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Deriving key from password took " + duration + " ms");
|
||||
return k;
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.logging.Logger;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
|
||||
/**
|
||||
* A key parser that uses the encoding defined in "SEC 1: Elliptic Curve
|
||||
@@ -48,7 +49,7 @@ class Sec1KeyParser implements KeyParser {
|
||||
throws GeneralSecurityException {
|
||||
// The validation procedure comes from SEC 1, section 3.2.2.1. Note
|
||||
// that SEC 1 parameter names are used below, not RFC 5639 names
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
if (encodedKey.length != publicKeyBytes)
|
||||
throw new GeneralSecurityException();
|
||||
// The first byte must be 0x04
|
||||
@@ -80,7 +81,7 @@ 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 = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Parsing public key took " + duration + " ms");
|
||||
return p;
|
||||
@@ -89,7 +90,7 @@ class Sec1KeyParser implements KeyParser {
|
||||
@Override
|
||||
public PrivateKey parsePrivateKey(byte[] encodedKey)
|
||||
throws GeneralSecurityException {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
if (encodedKey.length != privateKeyBytes)
|
||||
throw new GeneralSecurityException();
|
||||
BigInteger d = new BigInteger(1, encodedKey); // Positive signum
|
||||
@@ -99,7 +100,7 @@ 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 = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Parsing private key took " + duration + " ms");
|
||||
return p;
|
||||
|
||||
@@ -75,6 +75,7 @@ import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.api.sync.ValidationManager.State.DELIVERED;
|
||||
import static org.briarproject.bramble.api.sync.ValidationManager.State.UNKNOWN;
|
||||
import static org.briarproject.bramble.db.DatabaseConstants.MAX_OFFERED_MESSAGES;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
@@ -125,11 +126,11 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
// Don't allow reentrant locking
|
||||
if (lock.getReadHoldCount() > 0) throw new IllegalStateException();
|
||||
if (lock.getWriteHoldCount() > 0) throw new IllegalStateException();
|
||||
long start = System.currentTimeMillis();
|
||||
long start = now();
|
||||
if (readOnly) lock.readLock().lock();
|
||||
else lock.writeLock().lock();
|
||||
if (LOG.isLoggable(FINE)) {
|
||||
long duration = System.currentTimeMillis() - start;
|
||||
long duration = now() - start;
|
||||
if (readOnly) LOG.fine("Waited " + duration + " ms for read lock");
|
||||
else LOG.fine("Waited " + duration + " ms for write lock");
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResul
|
||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.DB_ERROR;
|
||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.SERVICE_ERROR;
|
||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.SUCCESS;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
@@ -102,22 +103,22 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
|
||||
}
|
||||
|
||||
private LocalAuthor createLocalAuthor(String nickname) {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
||||
byte[] publicKey = keyPair.getPublic().getEncoded();
|
||||
byte[] privateKey = keyPair.getPrivate().getEncoded();
|
||||
LocalAuthor localAuthor = authorFactory
|
||||
.createLocalAuthor(nickname, publicKey, privateKey);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Creating local author took " + duration + " ms");
|
||||
return localAuthor;
|
||||
}
|
||||
|
||||
private void registerLocalAuthor(LocalAuthor author) throws DbException {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
identityManager.registerLocalAuthor(author);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Registering local author took " + duration + " ms");
|
||||
}
|
||||
@@ -130,10 +131,10 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
|
||||
}
|
||||
try {
|
||||
LOG.info("Starting services");
|
||||
long start = System.currentTimeMillis();
|
||||
long start = now();
|
||||
|
||||
boolean reopened = db.open(this);
|
||||
long duration = System.currentTimeMillis() - start;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE)) {
|
||||
if (reopened)
|
||||
LOG.fine("Reopening database took " + duration + " ms");
|
||||
@@ -151,9 +152,9 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
for (Client c : clients) {
|
||||
start = System.currentTimeMillis();
|
||||
start = now();
|
||||
c.createLocalState(txn);
|
||||
duration = System.currentTimeMillis() - start;
|
||||
duration = now() - start;
|
||||
if (LOG.isLoggable(FINE)) {
|
||||
LOG.fine("Starting client "
|
||||
+ c.getClass().getSimpleName()
|
||||
@@ -165,9 +166,9 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
for (Service s : services) {
|
||||
start = System.currentTimeMillis();
|
||||
start = now();
|
||||
s.startService();
|
||||
duration = System.currentTimeMillis() - start;
|
||||
duration = now() - start;
|
||||
if (LOG.isLoggable(FINE)) {
|
||||
LOG.fine("Starting service " + s.getClass().getSimpleName()
|
||||
+ " took " + duration + " ms");
|
||||
@@ -214,9 +215,9 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
|
||||
state = STOPPING;
|
||||
eventBus.broadcast(new LifecycleEvent(STOPPING));
|
||||
for (Service s : services) {
|
||||
long start = System.currentTimeMillis();
|
||||
long start = now();
|
||||
s.stopService();
|
||||
long duration = System.currentTimeMillis() - start;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE)) {
|
||||
LOG.fine("Stopping service " + s.getClass().getSimpleName()
|
||||
+ " took " + duration + " ms");
|
||||
@@ -229,9 +230,9 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
|
||||
}
|
||||
e.shutdownNow();
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
long start = now();
|
||||
db.close();
|
||||
long duration = System.currentTimeMillis() - start;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Closing database took " + duration + " ms");
|
||||
shutdownLatch.countDown();
|
||||
|
||||
@@ -52,6 +52,7 @@ import javax.inject.Inject;
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
@@ -206,9 +207,9 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
long start = now();
|
||||
plugin.start();
|
||||
long duration = System.currentTimeMillis() - start;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE)) {
|
||||
LOG.fine("Starting plugin " + plugin.getId() + " took " +
|
||||
duration + " ms");
|
||||
@@ -244,9 +245,9 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
// Wait for the plugin to finish starting
|
||||
startLatch.await();
|
||||
// Stop the plugin
|
||||
long start = System.currentTimeMillis();
|
||||
long start = now();
|
||||
plugin.stop();
|
||||
long duration = System.currentTimeMillis() - start;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE)) {
|
||||
LOG.fine("Stopping plugin " + plugin.getId()
|
||||
+ " took " + duration + " ms");
|
||||
|
||||
@@ -4,11 +4,11 @@ import android.net.TrafficStats;
|
||||
import android.os.Process;
|
||||
|
||||
import org.briarproject.bramble.api.lifecycle.Service;
|
||||
import org.briarproject.bramble.api.lifecycle.ServiceException;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
|
||||
class NetworkUsageLogger implements Service {
|
||||
|
||||
@@ -18,17 +18,17 @@ class NetworkUsageLogger implements Service {
|
||||
private volatile long startTime, rxBytes, txBytes;
|
||||
|
||||
@Override
|
||||
public void startService() throws ServiceException {
|
||||
startTime = System.currentTimeMillis();
|
||||
public void startService() {
|
||||
startTime = now();
|
||||
int uid = Process.myUid();
|
||||
rxBytes = TrafficStats.getUidRxBytes(uid);
|
||||
txBytes = TrafficStats.getUidTxBytes(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopService() throws ServiceException {
|
||||
public void stopService() {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
long sessionDuration = System.currentTimeMillis() - startTime;
|
||||
long sessionDuration = now() - startTime;
|
||||
int uid = Process.myUid();
|
||||
long rx = TrafficStats.getUidRxBytes(uid) - rxBytes;
|
||||
long tx = TrafficStats.getUidTxBytes(uid) - txBytes;
|
||||
|
||||
@@ -34,6 +34,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
import static org.briarproject.briar.util.HtmlUtils.ARTICLE;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -109,20 +110,20 @@ abstract class BaseControllerImpl extends DbControllerImpl
|
||||
}
|
||||
|
||||
Collection<BlogPostItem> loadItems(GroupId groupId) throws DbException {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
Collection<BlogPostHeader> headers =
|
||||
blogManager.getPostHeaders(groupId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading headers took " + duration + " ms");
|
||||
Collection<BlogPostItem> items = new ArrayList<>(headers.size());
|
||||
now = System.currentTimeMillis();
|
||||
start = now();
|
||||
for (BlogPostHeader h : headers) {
|
||||
headerCache.put(h.getId(), h);
|
||||
BlogPostItem item = getItem(h);
|
||||
items.add(item);
|
||||
}
|
||||
duration = System.currentTimeMillis() - now;
|
||||
duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading bodies took " + duration + " ms");
|
||||
return items;
|
||||
@@ -140,9 +141,9 @@ abstract class BaseControllerImpl extends DbControllerImpl
|
||||
}
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
BlogPostItem item = getItem(header);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading body took " + duration + " ms");
|
||||
handler.onResult(item);
|
||||
@@ -166,10 +167,10 @@ abstract class BaseControllerImpl extends DbControllerImpl
|
||||
}
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
BlogPostHeader header1 = getPostHeader(g, m);
|
||||
BlogPostItem item = getItem(header1);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading post took " + duration + " ms");
|
||||
handler.onResult(item);
|
||||
|
||||
@@ -37,6 +37,7 @@ import javax.inject.Inject;
|
||||
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -154,13 +155,13 @@ class BlogControllerImpl extends BaseControllerImpl
|
||||
if (groupId == null) throw new IllegalStateException();
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
LocalAuthor a = identityManager.getLocalAuthor();
|
||||
Blog b = blogManager.getBlog(groupId);
|
||||
boolean ours = a.getId().equals(b.getAuthor().getId());
|
||||
boolean removable = blogManager.canBeRemoved(b);
|
||||
BlogItem blog = new BlogItem(b, ours, removable);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading blog took " + duration + " ms");
|
||||
handler.onResult(blog);
|
||||
@@ -177,10 +178,10 @@ class BlogControllerImpl extends BaseControllerImpl
|
||||
if (groupId == null) throw new IllegalStateException();
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
Blog b = blogManager.getBlog(groupId);
|
||||
blogManager.removeBlog(b);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Removing blog took " + duration + " ms");
|
||||
handler.onResult(null);
|
||||
|
||||
@@ -28,6 +28,7 @@ import javax.inject.Inject;
|
||||
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -99,7 +100,7 @@ class FeedControllerImpl extends BaseControllerImpl
|
||||
ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
Collection<BlogPostItem> posts = new ArrayList<>();
|
||||
for (Blog b : blogManager.getBlogs()) {
|
||||
try {
|
||||
@@ -109,7 +110,7 @@ class FeedControllerImpl extends BaseControllerImpl
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading all posts took " + duration + " ms");
|
||||
handler.onResult(posts);
|
||||
@@ -125,10 +126,10 @@ class FeedControllerImpl extends BaseControllerImpl
|
||||
ResultExceptionHandler<Blog, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
Author a = identityManager.getLocalAuthor();
|
||||
Blog b = blogManager.getPersonalBlog(a);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading blog took " + duration + " ms");
|
||||
handler.onResult(b);
|
||||
|
||||
@@ -142,11 +142,11 @@ public class WriteBlogPostActivity extends BriarActivity
|
||||
|
||||
private void storePost(String body) {
|
||||
runOnDbThread(() -> {
|
||||
long now = System.currentTimeMillis();
|
||||
long timestamp = System.currentTimeMillis();
|
||||
try {
|
||||
LocalAuthor author = identityManager.getLocalAuthor();
|
||||
BlogPost p = blogPostFactory
|
||||
.createBlogPost(groupId, now, null, author, body);
|
||||
.createBlogPost(groupId, timestamp, null, author, body);
|
||||
blogManager.addLocalPost(p);
|
||||
postPublished();
|
||||
} catch (DbException | GeneralSecurityException
|
||||
|
||||
@@ -61,6 +61,7 @@ import static android.support.v4.app.ActivityOptionsCompat.makeSceneTransitionAn
|
||||
import static android.support.v4.view.ViewCompat.getTransitionName;
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
import static org.briarproject.briar.android.contact.ConversationActivity.CONTACT_ID;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -194,7 +195,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
int revision = adapter.getRevision();
|
||||
listener.runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
List<ContactListItem> contacts = new ArrayList<>();
|
||||
for (Contact c : contactManager.getActiveContacts()) {
|
||||
try {
|
||||
@@ -208,7 +209,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
||||
// Continue
|
||||
}
|
||||
}
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Full load took " + duration + " ms");
|
||||
displayContacts(revision, contacts);
|
||||
|
||||
@@ -107,6 +107,7 @@ import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_INTRODUCTION;
|
||||
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||
import static org.briarproject.briar.android.util.UiUtils.getAvatarTransitionName;
|
||||
@@ -291,13 +292,13 @@ public class ConversationActivity extends BriarActivity
|
||||
private void loadContactDetailsAndMessages() {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
if (contactName == null || contactAuthorId == null) {
|
||||
Contact contact = contactManager.getContact(contactId);
|
||||
contactName = contact.getAuthor().getName();
|
||||
contactAuthorId = contact.getAuthor().getId();
|
||||
}
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading contact took " + duration + " ms");
|
||||
loadMessages();
|
||||
@@ -341,7 +342,7 @@ public class ConversationActivity extends BriarActivity
|
||||
int revision = adapter.getRevision();
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
Collection<PrivateMessageHeader> headers =
|
||||
messagingManager.getMessageHeaders(contactId);
|
||||
Collection<IntroductionMessage> introductions =
|
||||
@@ -358,7 +359,7 @@ public class ConversationActivity extends BriarActivity
|
||||
invitations.addAll(forumInvitations);
|
||||
invitations.addAll(blogInvitations);
|
||||
invitations.addAll(groupInvitations);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading messages took " + duration + " ms");
|
||||
displayMessages(revision, headers, introductions, invitations);
|
||||
@@ -439,9 +440,9 @@ public class ConversationActivity extends BriarActivity
|
||||
private void loadMessageBody(MessageId m) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
String body = messagingManager.getMessageBody(m);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading body took " + duration + " ms");
|
||||
displayMessageBody(m, body);
|
||||
@@ -690,9 +691,9 @@ public class ConversationActivity extends BriarActivity
|
||||
private void storeMessage(PrivateMessage m, String body) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
messagingManager.addLocalMessage(m);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Storing message took " + duration + " ms");
|
||||
Message message = m.getMessage();
|
||||
@@ -817,9 +818,9 @@ public class ConversationActivity extends BriarActivity
|
||||
private void markMessageRead(GroupId g, MessageId m) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
messagingManager.setReadFlag(g, m, true);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Marking read took " + duration + " ms");
|
||||
} catch (DbException e) {
|
||||
|
||||
@@ -30,6 +30,7 @@ import static android.view.View.VISIBLE;
|
||||
import static android.widget.Toast.LENGTH_LONG;
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_NAME_LENGTH;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -122,9 +123,9 @@ public class CreateForumActivity extends BriarActivity {
|
||||
private void storeForum(String name) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
Forum f = forumManager.addForum(name);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Storing forum took " + duration + " ms");
|
||||
displayForum(f);
|
||||
|
||||
@@ -46,6 +46,7 @@ import javax.inject.Inject;
|
||||
import static android.support.design.widget.Snackbar.LENGTH_INDEFINITE;
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
import static org.briarproject.briar.api.forum.ForumManager.CLIENT_ID;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -157,7 +158,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
int revision = adapter.getRevision();
|
||||
listener.runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
Collection<ForumListItem> forums = new ArrayList<>();
|
||||
for (Forum f : forumManager.getForums()) {
|
||||
try {
|
||||
@@ -168,7 +169,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
// Continue
|
||||
}
|
||||
}
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Full load took " + duration + " ms");
|
||||
displayForums(revision, forums);
|
||||
@@ -194,9 +195,9 @@ public class ForumListFragment extends BaseEventFragment implements
|
||||
private void loadAvailableForums() {
|
||||
listener.runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
int available = forumSharingManager.getInvitations().size();
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading available took " + duration + " ms");
|
||||
displayAvailableForums(available);
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.logging.Logger;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
|
||||
@NotNullByDefault
|
||||
public class PasswordControllerImpl extends ConfigControllerImpl
|
||||
@@ -86,9 +87,9 @@ public class PasswordControllerImpl extends ConfigControllerImpl
|
||||
|
||||
@CryptoExecutor
|
||||
String encryptDatabaseKey(SecretKey key, String password) {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
byte[] encrypted = crypto.encryptWithPassword(key.getBytes(), password);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Key derivation took " + duration + " ms");
|
||||
return StringUtils.toHexString(encrypted);
|
||||
|
||||
@@ -38,6 +38,7 @@ import javax.inject.Inject;
|
||||
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
import static org.briarproject.briar.api.privategroup.PrivateGroupManager.CLIENT_ID;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -147,7 +148,7 @@ class GroupListControllerImpl extends DbControllerImpl
|
||||
ResultExceptionHandler<Collection<GroupItem>, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
Collection<PrivateGroup> groups =
|
||||
groupManager.getPrivateGroups();
|
||||
List<GroupItem> items = new ArrayList<>(groups.size());
|
||||
@@ -161,7 +162,7 @@ class GroupListControllerImpl extends DbControllerImpl
|
||||
// Continue
|
||||
}
|
||||
}
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading groups took " + duration + " ms");
|
||||
handler.onResult(items);
|
||||
@@ -176,9 +177,9 @@ class GroupListControllerImpl extends DbControllerImpl
|
||||
public void removeGroup(GroupId g, ExceptionHandler<DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
groupManager.removePrivateGroup(g);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Removing group took " + duration + " ms");
|
||||
} catch (DbException e) {
|
||||
|
||||
@@ -65,6 +65,7 @@ import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.api.plugin.BluetoothConstants.PREF_BT_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK_ALWAYS;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_RINGTONE;
|
||||
import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.INTENT_SIGN_OUT;
|
||||
@@ -243,12 +244,12 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
private void loadSettings() {
|
||||
listener.runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
settings = settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||
Settings btSettings = settingsManager.getSettings(BT_NAMESPACE);
|
||||
Settings torSettings =
|
||||
settingsManager.getSettings(TOR_NAMESPACE);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading settings took " + duration + " ms");
|
||||
boolean btSetting =
|
||||
@@ -436,9 +437,9 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
try {
|
||||
Settings s = new Settings();
|
||||
s.putInt(PREF_TOR_NETWORK, torSetting);
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
settingsManager.mergeSettings(s, TOR_NAMESPACE);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Merging settings took " + duration + " ms");
|
||||
} catch (DbException e) {
|
||||
@@ -452,9 +453,9 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
try {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean(PREF_BT_ENABLE, btSetting);
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
settingsManager.mergeSettings(s, BT_NAMESPACE);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Merging settings took " + duration + " ms");
|
||||
} catch (DbException e) {
|
||||
@@ -466,9 +467,9 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
private void storeSettings(Settings settings) {
|
||||
listener.runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Merging settings took " + duration + " ms");
|
||||
} catch (DbException e) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -95,9 +96,9 @@ public abstract class InvitationControllerImpl<I extends InvitationItem>
|
||||
ResultExceptionHandler<Collection<I>, DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
Collection<I> invitations = new ArrayList<>(getInvitations());
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading invitations took " + duration + " ms");
|
||||
handler.onResult(invitations);
|
||||
|
||||
@@ -37,6 +37,7 @@ import java.util.logging.Logger;
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.TimeUtils.now;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -132,9 +133,9 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
checkGroupId();
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
G groupItem = loadNamedGroup();
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading group took " + duration + " ms");
|
||||
handler.onResult(groupItem);
|
||||
@@ -156,21 +157,21 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
// Load headers
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
Collection<H> headers = loadHeaders();
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading headers took " + duration + " ms");
|
||||
|
||||
// Load bodies into cache
|
||||
now = System.currentTimeMillis();
|
||||
start = now();
|
||||
for (H header : headers) {
|
||||
if (!bodyCache.containsKey(header.getId())) {
|
||||
bodyCache.put(header.getId(),
|
||||
loadMessageBody(header));
|
||||
}
|
||||
}
|
||||
duration = System.currentTimeMillis() - now;
|
||||
duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Loading bodies took " + duration + " ms");
|
||||
|
||||
@@ -198,11 +199,11 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
public void markItemsRead(Collection<I> items) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
for (I i : items) {
|
||||
markRead(i.getId());
|
||||
}
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Marking read took " + duration + " ms");
|
||||
} catch (DbException e) {
|
||||
@@ -218,10 +219,10 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
ResultExceptionHandler<I, DbException> resultHandler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
H header = addLocalMessage(msg);
|
||||
bodyCache.put(msg.getMessage().getId(), body);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Storing message took " + duration + " ms");
|
||||
resultHandler.onResult(buildItem(header, body));
|
||||
@@ -239,10 +240,10 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
|
||||
public void deleteNamedGroup(ExceptionHandler<DbException> handler) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
long start = now();
|
||||
G groupItem = loadNamedGroup();
|
||||
deleteNamedGroup(groupItem);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
long duration = now() - start;
|
||||
if (LOG.isLoggable(FINE))
|
||||
LOG.fine("Removing group took " + duration + " ms");
|
||||
} catch (DbException e) {
|
||||
|
||||
Reference in New Issue
Block a user