23
23
24
24
package org .opengrok .indexer .util ;
25
25
26
+ import java .time .Duration ;
27
+ import java .time .Instant ;
26
28
import java .util .logging .Level ;
27
29
import java .util .logging .Logger ;
28
30
import static org .opengrok .indexer .util .StringUtils .getReadableTime ;
29
31
30
32
public class Statistics {
31
33
32
- private final long startTime ;
34
+ private final Instant startTime ;
33
35
34
36
public Statistics () {
35
- startTime = System . currentTimeMillis ();
37
+ startTime = Instant . now ();
36
38
}
37
39
38
40
/**
@@ -42,14 +44,13 @@ public Statistics() {
42
44
* @param msg message string
43
45
*/
44
46
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 );
48
49
}
49
50
50
51
/**
51
52
* 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} .
53
54
* @param logger logger instance
54
55
* @param msg message string
55
56
*/
@@ -59,11 +60,12 @@ public void report(Logger logger, String msg) {
59
60
60
61
/**
61
62
* 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
63
65
*/
64
66
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 () ));
67
69
68
70
System .gc ();
69
71
Runtime r = Runtime .getRuntime ();
0 commit comments