From f1d28546936ce382358cf4133273aefda22e4a70 Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Sat, 27 Feb 2021 12:57:54 +0100 Subject: [PATCH 1/3] report duration for file history cache updates --- .../org/opengrok/indexer/history/FileHistoryCache.java | 9 ++++++++- .../main/java/org/opengrok/indexer/util/Statistics.java | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) 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..a37e84af373 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 @@ -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 @@ -102,6 +103,8 @@ private void doFileHistory(String filename, List historyEntries, Repository repository, File srcFile, File root, boolean renamed) throws HistoryException { + Statistics statRepoHist = new Statistics(); + File file = new File(root, filename); // Only store directory history for the top-level directory. if (file.isDirectory() && !filename.equals(repository.getDirectoryName())) { @@ -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 From 1b5cf3edebd0e12ed3faba8da039d8ae21996741 Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Sat, 27 Feb 2021 13:02:18 +0100 Subject: [PATCH 2/3] do not create Statistics object unnecessarily --- .../java/org/opengrok/indexer/history/FileHistoryCache.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 a37e84af373..564a7507258 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 @@ -103,8 +103,6 @@ private void doFileHistory(String filename, List historyEntries, Repository repository, File srcFile, File root, boolean renamed) throws HistoryException { - Statistics statRepoHist = new Statistics(); - File file = new File(root, filename); // Only store directory history for the top-level directory. if (file.isDirectory() && !filename.equals(repository.getDirectoryName())) { @@ -112,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 From e5068ba614db8a503efb626a8acc9f350dcc9c96 Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Sat, 27 Feb 2021 13:02:39 +0100 Subject: [PATCH 3/3] bump year --- .../java/org/opengrok/indexer/history/FileHistoryCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 564a7507258..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;