The patch adds a quite simple profiler.
It can be enabled by setting its log level to
uk.me.parabola.util.Profiler.level=INFO.
Adds some time measurings for different tasks to the end of the logfile.
More time measurings can and should be added easily. Please send
suggestions (patches?).
WanMil
Index: src/uk/me/parabola/mkgmap/main/Main.java
===================================================================
--- src/uk/me/parabola/mkgmap/main/Main.java (revision 1916)
+++ src/uk/me/parabola/mkgmap/main/Main.java (working copy)
@@ -60,6 +60,7 @@
import uk.me.parabola.mkgmap.reader.overview.OverviewMapDataSource;
import uk.me.parabola.mkgmap.scan.SyntaxException;
import uk.me.parabola.mkgmap.srt.SrtTextReader;
+import uk.me.parabola.util.Profiler;
/**
* The new main program. There can be many file names to process and there can
@@ -94,6 +95,8 @@
*/
public static void main(String[] args) {
+ Profiler.start("mkgmap");
+
// Temporary test for version 1.6. During a transition period we are
// compiling with target 1.5 so that it will run with 1.5 long enough
// to give an error message.
@@ -130,6 +133,9 @@
} catch (ExitException e) {
System.err.println(e.getMessage());
}
+
+ Profiler.stop("mkgmap");
+ Profiler.finish();
}
/**
Index: src/uk/me/parabola/util/Profiler.java
===================================================================
--- src/uk/me/parabola/util/Profiler.java (revision 0)
+++ src/uk/me/parabola/util/Profiler.java (revision 0)
@@ -0,0 +1,84 @@
+package uk.me.parabola.util;
+
+import java.util.Hashtable;
+import java.util.Map.Entry;
+
+import uk.me.parabola.log.Logger;
+
+public final class Profiler {
+
+ private static final Logger log = Logger.getLogger(Profiler.class);
+
+ private static final class Timing {
+ private final long startTime;
+ private long stopTime;
+
+ public Timing() {
+ startTime = System.currentTimeMillis();
+ stopTime = -1;
+ }
+
+ public void stop() {
+ stopTime = System.currentTimeMillis();
+ }
+
+ public long getTime() {
+ if (stopTime == -1) {
+ return -1;
+ } else {
+ return stopTime - startTime;
+ }
+ }
+ }
+
+ private static final Hashtable<String, Timing> times = new Hashtable<String, Timing>();
+
+ public static boolean isProfilerEnabled() {
+ return log.isInfoEnabled();
+ }
+
+ private static String getThreadName() {
+ String threadname = log.threadTag();
+ return (threadname == null ? Thread.currentThread().getName()
+ : threadname);
+ }
+
+ private static String getKey(String stepname) {
+ return stepname + "_" + getThreadName();
+ }
+
+ public static void start(String stepname) {
+ if (isProfilerEnabled() == false) {
+ return;
+ }
+ Timing oldTiming = times.put(getKey(stepname), new Timing());
+ if (oldTiming != null) {
+ log.error("Duplicate timing for " + getKey(stepname),
+ new Exception());
+ }
+ }
+
+ public static void stop(String stepname) {
+ if (isProfilerEnabled() == false) {
+ return;
+ }
+ Timing oldTiming = times.get(getKey(stepname));
+ if (oldTiming == null) {
+ log.error("Can't stop unknown timing step: " + getKey(stepname),
+ new Exception());
+ } else {
+ oldTiming.stop();
+ }
+ }
+
+ public static void finish() {
+ if (isProfilerEnabled() == false) {
+ return;
+ }
+
+ for (Entry<String, Timing> profStep : times.entrySet()) {
+ log.info("Step: " + profStep.getKey() + " Timing: "
+ + profStep.getValue().getTime());
+ }
+ }
+}
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev