diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/FileHistoryCache.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/FileHistoryCache.java index d70c28500ac..c103cfe2b72 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/FileHistoryCache.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/FileHistoryCache.java @@ -18,7 +18,7 @@ */ /* - * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved. * Portions Copyright (c) 2018, 2020, Chris Fraire . */ package org.opengrok.indexer.history; @@ -60,6 +60,7 @@ import org.opengrok.indexer.logger.LoggerFactory; import org.opengrok.indexer.util.ForbiddenSymlinkException; import org.opengrok.indexer.util.IOUtils; +import org.opengrok.indexer.util.Statistics; import org.opengrok.indexer.util.TandemPath; /** @@ -90,7 +91,7 @@ public boolean isHistoryIndexDone() { } /** - * Generate history for single file. + * Generate history cache for single file or directory. * @param filename name of the file * @param historyEntries list of HistoryEntry objects forming the (incremental) history of the file * @param repository repository object in which the file belongs @@ -109,6 +110,8 @@ private void doFileHistory(String filename, List historyEntries, return; } + Statistics statRepoHist = new Statistics(); + /* * If the file was renamed (in the changesets that are being indexed), * its history is not stored in the historyEntries so it needs to be acquired @@ -138,6 +141,10 @@ private void doFileHistory(String filename, List historyEntries, } storeFile(hist, file, repository, !renamed); + + statRepoHist.report(LOGGER, Level.FINER, + String.format("Done storing history cache for '%s'", filename), + "filehistorycache.history"); } private boolean isRenamedFile(String filename, Repository repository, History history) diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/util/Statistics.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/util/Statistics.java index 6e2e2533061..269bd00dff3 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/util/Statistics.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/util/Statistics.java @@ -31,6 +31,10 @@ import java.util.logging.Level; import java.util.logging.Logger; +/** + * This class is handy for logging messages (and updating metrics) + * about duration of a task. + */ public class Statistics { private final Instant startTime; @@ -55,11 +59,13 @@ public void report(Logger logger, Level logLevel, String msg) { } /** - * Log a message and trigger statsd message along with how much time it took since the constructor was called. + * Log a message along with how much time it took since the constructor was called. + * If there is a metrics registry, it will update the timer specified by the meter name. * @param logger logger instance * @param logLevel log level * @param msg message string * @param meterName name of the meter + * @see Metrics#getRegistry() */ public void report(Logger logger, Level logLevel, String msg, String meterName) { Duration duration = Duration.between(startTime, Instant.now()); @@ -76,6 +82,7 @@ public void report(Logger logger, Level logLevel, String msg, String meterName) /** * log a message along with how much time it took since the constructor was called. + * If there is a metrics registry, it will update the timer specified by the meter name. * The log level is {@code INFO}. * @param logger logger instance * @param msg message string