Replace boilerplate with static method.

This commit is contained in:
akwizgran
2018-06-15 16:17:08 +01:00
parent 0d2a91289f
commit abe14f19e6
19 changed files with 91 additions and 136 deletions

View File

@@ -1,5 +1,9 @@
package org.briarproject.bramble.util;
import java.util.logging.Logger;
import static java.util.logging.Level.FINE;
public class TimeUtils {
private static final int NANOS_PER_MILLI = 1000 * 1000;
@@ -11,4 +15,17 @@ public class TimeUtils {
public static long now() {
return System.nanoTime() / NANOS_PER_MILLI;
}
/**
* Logs the duration of a task.
* @param logger the logger to use
* @param task a description of the task
* @param start the start time of the task, as returned by {@link #now()}
*/
public static void logDuration(Logger logger, String task, long start) {
if (logger.isLoggable(FINE)) {
long duration = now() - start;
logger.fine(task + " took " + duration + " ms");
}
}
}