Skip to content

Commit e7b6023

Browse files
author
Vladimir Kotal
committed
Merge pull request #803 from vladak/indexer_times
add elapsed time reporting for 2nd phase of indexing and report total ti...
2 parents 2741926 + 2b65c8c commit e7b6023

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

src/org/opensolaris/opengrok/history/HistoryGuru.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.opensolaris.opengrok.configuration.Configuration.RemoteSCM;
4343
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
4444
import org.opensolaris.opengrok.index.IgnoredNames;
45+
import org.opensolaris.opengrok.util.Statistics;
4546
import org.opensolaris.opengrok.util.StringUtils;
4647

4748
/**
@@ -484,7 +485,7 @@ private void createCache(Repository repository, String sinceRevision) {
484485

485486
if (repository.isWorking()) {
486487
boolean verbose = RuntimeEnvironment.getInstance().isVerbose();
487-
long start = System.currentTimeMillis();
488+
Statistics elapsed = new Statistics();
488489

489490
if (verbose) {
490491
log.log(Level.INFO, "Creating historycache for {0} ({1})",
@@ -500,10 +501,7 @@ private void createCache(Repository repository, String sinceRevision) {
500501
}
501502

502503
if (verbose) {
503-
long stop = System.currentTimeMillis();
504-
String time_str = StringUtils.getReadableTime(stop - start);
505-
log.log(Level.INFO, "Done historycache for {0} (took {1})",
506-
new Object[]{path, time_str});
504+
elapsed.report(log, "Done historycache for " + path);
507505
}
508506
} else {
509507
log.log(Level.WARNING, "Skipping creation of historycache of "
@@ -512,7 +510,7 @@ private void createCache(Repository repository, String sinceRevision) {
512510
}
513511

514512
private void createCacheReal(Collection<Repository> repositories) {
515-
long start = System.currentTimeMillis();
513+
Statistics elapsed = new Statistics();
516514
ExecutorService executor = RuntimeEnvironment.getHistoryExecutor();
517515
// Since we know each repository object from the repositories
518516
// collection is unique, we can abuse HashMap to create a list of
@@ -596,10 +594,7 @@ public void run() {
596594
OpenGrokLogger.getLogger().log(Level.WARNING,
597595
"Failed optimizing the history cache database", he);
598596
}
599-
long stop = System.currentTimeMillis();
600-
String time_str = StringUtils.getReadableTime(stop - start);
601-
log.log(Level.INFO, "Done historycache for all repositories (took {0})",
602-
time_str);
597+
elapsed.report(log, "Done historycache for all repositories");
603598
historyCache.setHistoryIndexDone();
604599
}
605600

src/org/opensolaris/opengrok/index/IndexDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public void update() throws IOException, HistoryException {
322322
}
323323
}
324324

325-
try {
325+
try {
326326
Analyzer analyzer = AnalyzerGuru.getAnalyzer();
327327
IndexWriterConfig iwc = new IndexWriterConfig(SearchEngine.LUCENE_VERSION, analyzer);
328328
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);

src/org/opensolaris/opengrok/index/Indexer.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,14 @@ public static void main(String argv[]) {
577577

578578
}
579579

580-
// PMD wants us to use length() > 0 && charAt(0) instead of startsWith()
581-
// for performance. We prefer clarity over performance here, so silence it.
580+
/*
581+
* This is the first phase of the indexing where history cache is being
582+
* generated for repositories (at least for those which support getting
583+
* history per directory).
584+
*
585+
* PMD wants us to use length() > 0 && charAt(0) instead of startsWith()
586+
* for performance. We prefer clarity over performance here, so silence it.
587+
*/
582588
@SuppressWarnings("PMD.SimplifyStartsWith")
583589
public void prepareIndexer(RuntimeEnvironment env,
584590
boolean searchRepositories,
@@ -743,9 +749,16 @@ public int compare(Project p1, Project p2) {
743749
}
744750
}
745751

752+
/*
753+
* This is the second phase of the indexer which generates Lucene index
754+
* by passing source code files through Exuberant ctags, generating xrefs
755+
* and storing data from the source files in the index (along with history,
756+
* if any).
757+
*/
746758
public void doIndexerExecution(final boolean update, int noThreads, List<String> subFiles,
747759
IndexChangedListener progress)
748760
throws IOException {
761+
Statistics elapsed = new Statistics();
749762
RuntimeEnvironment env = RuntimeEnvironment.getInstance().register();
750763
log.info("Starting indexing");
751764

@@ -826,7 +839,7 @@ public void run() {
826839
log.log(Level.SEVERE,
827840
"destroying of renamed thread pool failed", ex);
828841
}
829-
log.info("Done indexing");
842+
elapsed.report(log, "Done indexing data of all repositories");
830843
}
831844

832845
public void sendToConfigHost(RuntimeEnvironment env, String configHost) {
@@ -838,7 +851,8 @@ public void sendToConfigHost(RuntimeEnvironment env, String configHost) {
838851
InetAddress host = InetAddress.getByName(cfg[0]);
839852
env.writeConfiguration(host, Integer.parseInt(cfg[1]));
840853
} catch (Exception ex) {
841-
log.log(Level.SEVERE, "Failed to send configuration to " + configHost + " (is web application server running with opengrok deployed?)", ex);
854+
log.log(Level.SEVERE, "Failed to send configuration to "
855+
+ configHost + " (is web application server running with opengrok deployed?)", ex);
842856
}
843857
} else {
844858
log.severe("Syntax error: ");

src/org/opensolaris/opengrok/util/Statistics.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public Statistics() {
3535
startTime = System.currentTimeMillis();
3636
}
3737

38+
public void report(Logger log, String msg) {
39+
long stopTime = System.currentTimeMillis();
40+
String time_str = StringUtils.getReadableTime(stopTime - startTime);
41+
log.log(Level.INFO, msg + " (took {0})", time_str);
42+
}
43+
3844
public void report(Logger log) {
3945
long stopTime = System.currentTimeMillis() - startTime;
4046
log.log(Level.INFO, "Total time: {0}", getReadableTime(stopTime));

0 commit comments

Comments
 (0)