Skip to content

report duration for file history cache updates #3438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cfraire@me.com>.
*/
package org.opengrok.indexer.history;
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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
Expand All @@ -109,6 +110,8 @@ private void doFileHistory(String filename, List<HistoryEntry> 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
Expand Down Expand Up @@ -138,6 +141,10 @@ private void doFileHistory(String filename, List<HistoryEntry> historyEntries,
}

storeFile(hist, file, repository, !renamed);

statRepoHist.report(LOGGER, Level.FINER,
String.format("Done storing history cache for '%s'", filename),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, the String.format() will be evaluated every time. Thinking of introducing static method Statistics.eligible(LogLevel level) that would do something like:

return (LOGGER.isLoggable(level) || Metrics.getRegistry());

"filehistorycache.history");
}

private boolean isRenamedFile(String filename, Repository repository, History history)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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
Expand Down