From 3d982813b34f6f230baf4a467cdc37ec92a77595 Mon Sep 17 00:00:00 2001 From: netconomy Date: Fri, 17 Aug 2007 06:10:56 +0000 Subject: Performance git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@167 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../egiz/pdfas/performance/PerformanceCounter.java | 62 ++++++++++++++++++++++ .../pdfas/performance/PerformanceCounters.java | 22 ++++++++ .../egiz/pdfas/performance/PerformanceTimer.java | 48 +++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 src/main/java/at/gv/egiz/pdfas/performance/PerformanceCounter.java create mode 100644 src/main/java/at/gv/egiz/pdfas/performance/PerformanceCounters.java create mode 100644 src/main/java/at/gv/egiz/pdfas/performance/PerformanceTimer.java (limited to 'src/main/java/at/gv/egiz/pdfas/performance') diff --git a/src/main/java/at/gv/egiz/pdfas/performance/PerformanceCounter.java b/src/main/java/at/gv/egiz/pdfas/performance/PerformanceCounter.java new file mode 100644 index 0000000..2d9b461 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/performance/PerformanceCounter.java @@ -0,0 +1,62 @@ +/** + * + */ +package at.gv.egiz.pdfas.performance; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * @author wprinz + */ +public class PerformanceCounter +{ + /** + * The log. + */ + private static Log log = LogFactory.getLog(PerformanceCounter.class); + + protected String name = null; + + protected long counter = 0; + + public PerformanceCounter(String name) + { + this.name = name; + reset(); + } + + public PerformanceCounter(Class clazz) + { + this(clazz.getName()); + } + + public void increment() + { + this.counter++; + log.trace(this.name + ": incremented to " + this.counter); + } + + public void reset() + { + this.counter = 0; + log.trace(this.name + ": reset to 0"); + } + + /** + * @return the name + */ + public String getName() + { + return this.name; + } + + /** + * @return the counter + */ + public long getCounter() + { + return this.counter; + } + +} diff --git a/src/main/java/at/gv/egiz/pdfas/performance/PerformanceCounters.java b/src/main/java/at/gv/egiz/pdfas/performance/PerformanceCounters.java new file mode 100644 index 0000000..6251c55 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/performance/PerformanceCounters.java @@ -0,0 +1,22 @@ +/** + * + */ +package at.gv.egiz.pdfas.performance; + +/** + * Contains various global PerformanceCounters that provide information about the system. + * + * @author wprinz + */ +public final class PerformanceCounters +{ + /** + * Keeps track of the number of text extractions done so far. + */ + public static PerformanceCounter textExtractions = new PerformanceCounter("TextExtractions"); + + /** + * Keeps track of the number of large byte array allocations. + */ + public static PerformanceCounter byteArrays = new PerformanceCounter("ByteArrays"); +} diff --git a/src/main/java/at/gv/egiz/pdfas/performance/PerformanceTimer.java b/src/main/java/at/gv/egiz/pdfas/performance/PerformanceTimer.java new file mode 100644 index 0000000..6ebb9be --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/performance/PerformanceTimer.java @@ -0,0 +1,48 @@ +/** + * + */ +package at.gv.egiz.pdfas.performance; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * @author wprinz + * + */ +public class PerformanceTimer +{ + /** + * The log. + */ + private static Log log = LogFactory.getLog(PerformanceTimer.class); + + protected String name = null; + + protected long startTime = -1; + + protected long stopTime = -1; + + public PerformanceTimer(String name) + { + this.name = name; + } + + public void start() + { + this.startTime = System.currentTimeMillis(); + log.trace(this.name + ": started at " + this.startTime); + } + + public void stop() + { + this.stopTime = System.currentTimeMillis(); + log.trace(this.name + ": stopped at " + this.stopTime); + log.trace(this.name + ": time elapsed = " + getTimeElapsed()); + } + + public long getTimeElapsed() + { + return this.stopTime - this.startTime; + } +} -- cgit v1.2.3