summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/persistent/AbstractPageFile.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/persistent/AbstractPageFile.java')
-rw-r--r--src/de/lmu/ifi/dbs/elki/persistent/AbstractPageFile.java58
1 files changed, 40 insertions, 18 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/persistent/AbstractPageFile.java b/src/de/lmu/ifi/dbs/elki/persistent/AbstractPageFile.java
index e05c20c3..d6e750b8 100644
--- a/src/de/lmu/ifi/dbs/elki/persistent/AbstractPageFile.java
+++ b/src/de/lmu/ifi/dbs/elki/persistent/AbstractPageFile.java
@@ -1,10 +1,13 @@
package de.lmu.ifi.dbs.elki.persistent;
+import de.lmu.ifi.dbs.elki.logging.Logging;
+import de.lmu.ifi.dbs.elki.logging.statistics.Counter;
+
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2012
+ Copyright (C) 2013
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,7 +26,6 @@ package de.lmu.ifi.dbs.elki.persistent;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
/**
* Abstract base class for the page file API for both caches and true page files
* (in-memory and on-disk).
@@ -36,23 +38,31 @@ public abstract class AbstractPageFile<P extends Page> implements PageFile<P> {
/**
* The read I/O-Access of this file.
*/
- protected long readAccess;
+ private Counter readAccess;
/**
* The write I/O-Access of this file.
*/
- protected long writeAccess;
+ private Counter writeAccess;
/**
* Constructor.
*/
public AbstractPageFile() {
super();
- this.readAccess = 0;
- this.writeAccess = 0;
+ Logging log = getLogger();
+ this.readAccess = log.isStatistics() ? log.newCounter(this.getClass().getName() + ".reads") : null;
+ this.writeAccess = log.isStatistics() ? log.newCounter(this.getClass().getName() + ".writes") : null;
}
/**
+ * Get the class logger.
+ *
+ * @return Logger
+ */
+ abstract protected Logging getLogger();
+
+ /**
* Writes a page into this file. The method tests if the page has already an
* id, otherwise a new id is assigned and returned.
*
@@ -78,20 +88,32 @@ public abstract class AbstractPageFile<P extends Page> implements PageFile<P> {
public void close() {
clear();
}
-
+
@Override
- public final long getReadOperations() {
- return readAccess;
+ public void logStatistics() {
+ if (readAccess != null) {
+ getLogger().statistics(readAccess);
+ }
+ if (writeAccess != null) {
+ getLogger().statistics(writeAccess);
+ }
}
-
- @Override
- public final long getWriteOperations() {
- return writeAccess;
+
+ /**
+ * Count a page read access.
+ */
+ protected void countRead() {
+ if (readAccess != null) {
+ readAccess.increment();
+ }
}
- @Override
- public final void resetPageAccess() {
- this.readAccess = 0;
- this.writeAccess = 0;
+ /**
+ * Count a page write access.
+ */
+ protected void countWrite() {
+ if (writeAccess != null) {
+ writeAccess.increment();
+ }
}
-} \ No newline at end of file
+}