Mercurial > hg > blitz_condensed
diff src/org/dancres/blitz/disk/IOStats.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/dancres/blitz/disk/IOStats.java Sat Mar 21 11:00:06 2009 +0000 @@ -0,0 +1,88 @@ +package org.dancres.blitz.disk; + +import java.util.logging.Level; + +class IOStats { + private int theAsyncInCount; + private int theAsyncOutCount; + + private double theSampleStartTime; + + private double theTimePerOut; + private double theTimePerIn; + + private double theInOutLag; + private double theInOutRatio; + + private int theQueueSize; + + double getTimePerIn() { + return theTimePerIn; + } + + double getTimePerOut() { + return theTimePerOut; + } + + double getInOutRatio() { + return theInOutRatio; + } + + void incAsyncInCount() { + synchronized(this) { + ++theAsyncInCount; + ++theQueueSize; + } + } + + int getQueueSize() { + synchronized(this) { + return theQueueSize; + } + } + + /** + @return <code>true</code> if the io statistics were updated, <code> + false</code> otherwise. + */ + boolean incAsyncOutCount() { + synchronized(this) { + if (theAsyncOutCount == 0) + theSampleStartTime = (double) System.currentTimeMillis(); + + ++theAsyncOutCount; + --theQueueSize; + + /* + Probably this should be based on low watermark so the + calculation is available before the high watermark is hit. + Probably ought to remove desired pending count as well at some + point. + */ + if (theAsyncOutCount == 1000) { + double myDuration = (double) System.currentTimeMillis() - + theSampleStartTime; + + theTimePerOut = myDuration / 1000.0; + theTimePerIn = myDuration / (double) theAsyncInCount; + + theInOutLag = theTimePerOut - theTimePerIn; + theInOutRatio = theTimePerOut / theTimePerIn; + + theAsyncOutCount = theAsyncInCount = 0; + + return true; + } + + return false; + } + } + + void dumpStats() { + synchronized(this) { + WriteDaemon.theLogger.log(Level.INFO, "TPI: " + theTimePerIn + + " TPO: " + theTimePerOut + " IOL: " + theInOutLag + + " IOR: " + theInOutRatio + " QSZ: " + theQueueSize); + } + } +}