Skip to content

Commit 20c879e

Browse files
Vladimir Kotalahornace
authored andcommitted
use Instant/Duration per review comment
1 parent 8b57b0e commit 20c879e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/util/Statistics.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@
2323

2424
package org.opengrok.indexer.util;
2525

26+
import java.time.Duration;
27+
import java.time.Instant;
2628
import java.util.logging.Level;
2729
import java.util.logging.Logger;
2830
import static org.opengrok.indexer.util.StringUtils.getReadableTime;
2931

3032
public class Statistics {
3133

32-
private final long startTime;
34+
private final Instant startTime;
3335

3436
public Statistics() {
35-
startTime = System.currentTimeMillis();
37+
startTime = Instant.now();
3638
}
3739

3840
/**
@@ -42,14 +44,13 @@ public Statistics() {
4244
* @param msg message string
4345
*/
4446
public void report(Logger logger, Level logLevel, String msg) {
45-
long stopTime = System.currentTimeMillis();
46-
String timeStr = StringUtils.getReadableTime(stopTime - startTime);
47-
logger.log(Level.INFO, msg + " (took {0})", timeStr);
47+
String timeStr = StringUtils.getReadableTime(Duration.between(startTime, Instant.now()).toMillis());
48+
logger.log(logLevel, msg + " (took {0})", timeStr);
4849
}
4950

5051
/**
5152
* log a message along with how much time it took since the constructor was called.
52-
* The log level is Level.INFO.
53+
* The log level is {@code INFO}.
5354
* @param logger logger instance
5455
* @param msg message string
5556
*/
@@ -59,11 +60,12 @@ public void report(Logger logger, String msg) {
5960

6061
/**
6162
* log a message along with how much time and memory it took since the constructor was called.
62-
* @param logger
63+
* The message will be logged with the {@code INFO} level.
64+
* @param logger logger instance
6365
*/
6466
public void report(Logger logger) {
65-
long stopTime = System.currentTimeMillis() - startTime;
66-
logger.log(Level.INFO, "Total time: {0}", getReadableTime(stopTime));
67+
logger.log(Level.INFO, "Total time: {0}",
68+
getReadableTime(Duration.between(startTime, Instant.now()).toMillis()));
6769

6870
System.gc();
6971
Runtime r = Runtime.getRuntime();

0 commit comments

Comments
 (0)