mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Log the timing of startup tasks so we can find bottlenecks.
This commit is contained in:
@@ -16,12 +16,14 @@ import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.lifecycle.Service;
|
||||
import org.briarproject.api.system.Clock;
|
||||
|
||||
class LifecycleManagerImpl implements LifecycleManager {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(LifecycleManagerImpl.class.getName());
|
||||
|
||||
private final Clock clock;
|
||||
private final DatabaseComponent db;
|
||||
private final Collection<Service> services;
|
||||
private final Collection<ExecutorService> executors;
|
||||
@@ -30,7 +32,8 @@ class LifecycleManagerImpl implements LifecycleManager {
|
||||
private final CountDownLatch shutdownLatch = new CountDownLatch(1);
|
||||
|
||||
@Inject
|
||||
LifecycleManagerImpl(DatabaseComponent db) {
|
||||
LifecycleManagerImpl(Clock clock, DatabaseComponent db) {
|
||||
this.clock = clock;
|
||||
this.db = db;
|
||||
services = new CopyOnWriteArrayList<Service>();
|
||||
executors = new CopyOnWriteArrayList<ExecutorService>();
|
||||
@@ -51,20 +54,30 @@ class LifecycleManagerImpl implements LifecycleManager {
|
||||
public boolean startServices() {
|
||||
try {
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Starting");
|
||||
long start = clock.currentTimeMillis();
|
||||
boolean reopened = db.open();
|
||||
long duration = clock.currentTimeMillis() - start;
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
if(reopened) LOG.info("Database reopened");
|
||||
else LOG.info("Database created");
|
||||
if(reopened)
|
||||
LOG.info("Reopening database took " + duration + " ms");
|
||||
else LOG.info("Creating database took " + duration + " ms");
|
||||
}
|
||||
dbLatch.countDown();
|
||||
for(Service s : services) {
|
||||
start = clock.currentTimeMillis();
|
||||
boolean started = s.start();
|
||||
duration = clock.currentTimeMillis() - start;
|
||||
if(!started) {
|
||||
if(LOG.isLoggable(WARNING)) {
|
||||
String name = s.getClass().getName();
|
||||
LOG.warning(name + " did not start");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
String name = s.getClass().getName();
|
||||
if(started) LOG.info("Service started: " + name);
|
||||
else LOG.info("Service failed to start: " + name);
|
||||
LOG.info("Starting " + name + " took " + duration + " ms");
|
||||
}
|
||||
if(!started) return false;
|
||||
}
|
||||
startupLatch.countDown();
|
||||
return true;
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.briarproject.api.plugins.simplex.SimplexPluginConfig;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginFactory;
|
||||
import org.briarproject.api.plugins.simplex.SimplexTransportReader;
|
||||
import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
|
||||
import org.briarproject.api.system.Clock;
|
||||
import org.briarproject.api.transport.ConnectionDispatcher;
|
||||
import org.briarproject.api.ui.UiCallback;
|
||||
|
||||
@@ -50,6 +51,7 @@ class PluginManagerImpl implements PluginManager {
|
||||
private final Executor pluginExecutor;
|
||||
private final SimplexPluginConfig simplexPluginConfig;
|
||||
private final DuplexPluginConfig duplexPluginConfig;
|
||||
private final Clock clock;
|
||||
private final DatabaseComponent db;
|
||||
private final Poller poller;
|
||||
private final ConnectionDispatcher dispatcher;
|
||||
@@ -60,12 +62,13 @@ class PluginManagerImpl implements PluginManager {
|
||||
@Inject
|
||||
PluginManagerImpl(@PluginExecutor Executor pluginExecutor,
|
||||
SimplexPluginConfig simplexPluginConfig,
|
||||
DuplexPluginConfig duplexPluginConfig, DatabaseComponent db,
|
||||
Poller poller, ConnectionDispatcher dispatcher,
|
||||
UiCallback uiCallback) {
|
||||
DuplexPluginConfig duplexPluginConfig, Clock clock,
|
||||
DatabaseComponent db, Poller poller,
|
||||
ConnectionDispatcher dispatcher, UiCallback uiCallback) {
|
||||
this.pluginExecutor = pluginExecutor;
|
||||
this.simplexPluginConfig = simplexPluginConfig;
|
||||
this.duplexPluginConfig = duplexPluginConfig;
|
||||
this.clock = clock;
|
||||
this.db = db;
|
||||
this.poller = poller;
|
||||
this.dispatcher = dispatcher;
|
||||
@@ -167,19 +170,31 @@ class PluginManagerImpl implements PluginManager {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
long start = clock.currentTimeMillis();
|
||||
db.addTransport(id, plugin.getMaxLatency());
|
||||
long duration = clock.currentTimeMillis() - start;
|
||||
if(LOG.isLoggable(INFO))
|
||||
LOG.info("Adding transport took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if(plugin.start()) {
|
||||
long start = clock.currentTimeMillis();
|
||||
boolean started = plugin.start();
|
||||
long duration = clock.currentTimeMillis() - start;
|
||||
if(started) {
|
||||
simplexPlugins.add(plugin);
|
||||
} else {
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.info(name + " did not start");
|
||||
LOG.info("Starting " + name + " took " +
|
||||
duration + " ms");
|
||||
}
|
||||
} else {
|
||||
if(LOG.isLoggable(WARNING)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.warning(name + " did not start");
|
||||
}
|
||||
}
|
||||
} catch(IOException e) {
|
||||
@@ -216,19 +231,31 @@ class PluginManagerImpl implements PluginManager {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
long start = clock.currentTimeMillis();
|
||||
db.addTransport(id, plugin.getMaxLatency());
|
||||
long duration = clock.currentTimeMillis() - start;
|
||||
if(LOG.isLoggable(INFO))
|
||||
LOG.info("Adding transport took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if(plugin.start()) {
|
||||
long start = clock.currentTimeMillis();
|
||||
boolean started = plugin.start();
|
||||
long duration = clock.currentTimeMillis() - start;
|
||||
if(started) {
|
||||
duplexPlugins.add(plugin);
|
||||
} else {
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.info(name + " did not start");
|
||||
LOG.info("Starting " + name + " took " +
|
||||
duration + " ms");
|
||||
}
|
||||
} else {
|
||||
if(LOG.isLoggable(WARNING)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.warning(name + " did not start");
|
||||
}
|
||||
}
|
||||
} catch(IOException e) {
|
||||
@@ -253,7 +280,13 @@ class PluginManagerImpl implements PluginManager {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
long start = clock.currentTimeMillis();
|
||||
plugin.stop();
|
||||
long duration = clock.currentTimeMillis() - start;
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.info("Stopping " + name + " took " + duration + " ms");
|
||||
}
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user