Skip to content

Commit 5752d8b

Browse files
Vladimir Kotalahornace
authored andcommitted
report duration for file history cache updates
1 parent 5f88acb commit 5752d8b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/FileHistoryCache.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.opengrok.indexer.logger.LoggerFactory;
6161
import org.opengrok.indexer.util.ForbiddenSymlinkException;
6262
import org.opengrok.indexer.util.IOUtils;
63+
import org.opengrok.indexer.util.Statistics;
6364
import org.opengrok.indexer.util.TandemPath;
6465

6566
/**
@@ -90,7 +91,7 @@ public boolean isHistoryIndexDone() {
9091
}
9192

9293
/**
93-
* Generate history for single file.
94+
* Generate history cache for single file or directory.
9495
* @param filename name of the file
9596
* @param historyEntries list of HistoryEntry objects forming the (incremental) history of the file
9697
* @param repository repository object in which the file belongs
@@ -102,6 +103,8 @@ private void doFileHistory(String filename, List<HistoryEntry> historyEntries,
102103
Repository repository, File srcFile, File root, boolean renamed)
103104
throws HistoryException {
104105

106+
Statistics statRepoHist = new Statistics();
107+
105108
File file = new File(root, filename);
106109
// Only store directory history for the top-level directory.
107110
if (file.isDirectory() && !filename.equals(repository.getDirectoryName())) {
@@ -138,6 +141,10 @@ private void doFileHistory(String filename, List<HistoryEntry> historyEntries,
138141
}
139142

140143
storeFile(hist, file, repository, !renamed);
144+
145+
statRepoHist.report(LOGGER, Level.FINER,
146+
String.format("Done storing history cache for '%s'", filename),
147+
"filehistorycache.history");
141148
}
142149

143150
private boolean isRenamedFile(String filename, Repository repository, History history)

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
import java.util.logging.Level;
3232
import java.util.logging.Logger;
3333

34+
/**
35+
* This class is handy for logging messages (and updating metrics)
36+
* about duration of a task.
37+
*/
3438
public class Statistics {
3539

3640
private final Instant startTime;
@@ -55,11 +59,13 @@ public void report(Logger logger, Level logLevel, String msg) {
5559
}
5660

5761
/**
58-
* Log a message and trigger statsd message along with how much time it took since the constructor was called.
62+
* Log a message along with how much time it took since the constructor was called.
63+
* If there is a metrics registry, it will update the timer specified by the meter name.
5964
* @param logger logger instance
6065
* @param logLevel log level
6166
* @param msg message string
6267
* @param meterName name of the meter
68+
* @see Metrics#getRegistry()
6369
*/
6470
public void report(Logger logger, Level logLevel, String msg, String meterName) {
6571
Duration duration = Duration.between(startTime, Instant.now());
@@ -76,6 +82,7 @@ public void report(Logger logger, Level logLevel, String msg, String meterName)
7682

7783
/**
7884
* log a message along with how much time it took since the constructor was called.
85+
* If there is a metrics registry, it will update the timer specified by the meter name.
7986
* The log level is {@code INFO}.
8087
* @param logger logger instance
8188
* @param msg message string

0 commit comments

Comments
 (0)