Mercurial > hg > blitz_stable
view src/org/dancres/blitz/disk/IOStats.java @ 23:b7e52953b7a6
Add some cache/memory statistics to help spot potential exhaustion and other tuning issues.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Fri, 28 Aug 2009 17:23:33 +0100 |
parents | 3dc0c5604566 |
children |
line wrap: on
line source
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); } } }