Skip to content

Commit 4a83e85

Browse files
committed
refactor
1 parent 9e7a7eb commit 4a83e85

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
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/Indexer.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,6 @@ public static void main(String argv[]) {
549549
System.out.println("History stored in DB and renamed file handling is on - possible performance degradation");
550550
}
551551

552-
long start = System.currentTimeMillis();
553552
getInstance().prepareIndexer(env, searchRepositories, addProjects,
554553
defaultProject, configFilename, refreshHistory,
555554
listFiles, createDict, subFiles, repositories,
@@ -562,9 +561,6 @@ public static void main(String argv[]) {
562561
getInstance().doIndexerExecution(update, noThreads, subFiles,
563562
progress);
564563
}
565-
long stop = System.currentTimeMillis();
566-
String time_str = StringUtils.getReadableTime(stop - start);
567-
log.log(Level.INFO, "Total indexing time: {0}", time_str);
568564
getInstance().sendToConfigHost(env, configHost);
569565
} catch (IndexerException ex) {
570566
log.log(Level.SEVERE, "Exception running indexer", ex);
@@ -763,7 +759,7 @@ public int compare(Project p1, Project p2) {
763759
public void doIndexerExecution(final boolean update, int noThreads, List<String> subFiles,
764760
IndexChangedListener progress)
765761
throws IOException {
766-
long start = System.currentTimeMillis();
762+
Statistics elapsed = new Statistics();
767763
RuntimeEnvironment env = RuntimeEnvironment.getInstance().register();
768764
log.info("Starting indexing");
769765

@@ -844,10 +840,7 @@ public void run() {
844840
log.log(Level.SEVERE,
845841
"destroying of renamed thread pool failed", ex);
846842
}
847-
long stop = System.currentTimeMillis();
848-
String time_str = StringUtils.getReadableTime(stop - start);
849-
log.log(Level.INFO, "Done indexing data of all repositories (took {0})",
850-
time_str);
843+
elapsed.report(log, "Done indexing data of all repositories");
851844
}
852845

853846
public void sendToConfigHost(RuntimeEnvironment env, String configHost) {
@@ -859,7 +852,8 @@ public void sendToConfigHost(RuntimeEnvironment env, String configHost) {
859852
InetAddress host = InetAddress.getByName(cfg[0]);
860853
env.writeConfiguration(host, Integer.parseInt(cfg[1]));
861854
} catch (Exception ex) {
862-
log.log(Level.SEVERE, "Failed to send configuration to " + configHost + " (is web application server running with opengrok deployed?)", ex);
855+
log.log(Level.SEVERE, "Failed to send configuration to "
856+
+ configHost + " (is web application server running with opengrok deployed?)", ex);
863857
}
864858
} else {
865859
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)