Mercurial > hg > blitz_condensed
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.blitz.disk; | |
2 | |
3 import java.util.logging.Level; | |
4 | |
5 class IOStats { | |
6 private int theAsyncInCount; | |
7 private int theAsyncOutCount; | |
8 | |
9 private double theSampleStartTime; | |
10 | |
11 private double theTimePerOut; | |
12 private double theTimePerIn; | |
13 | |
14 private double theInOutLag; | |
15 private double theInOutRatio; | |
16 | |
17 private int theQueueSize; | |
18 | |
19 double getTimePerIn() { | |
20 return theTimePerIn; | |
21 } | |
22 | |
23 double getTimePerOut() { | |
24 return theTimePerOut; | |
25 } | |
26 | |
27 double getInOutRatio() { | |
28 return theInOutRatio; | |
29 } | |
30 | |
31 void incAsyncInCount() { | |
32 synchronized(this) { | |
33 ++theAsyncInCount; | |
34 ++theQueueSize; | |
35 } | |
36 } | |
37 | |
38 int getQueueSize() { | |
39 synchronized(this) { | |
40 return theQueueSize; | |
41 } | |
42 } | |
43 | |
44 /** | |
45 @return <code>true</code> if the io statistics were updated, <code> | |
46 false</code> otherwise. | |
47 */ | |
48 boolean incAsyncOutCount() { | |
49 synchronized(this) { | |
50 if (theAsyncOutCount == 0) | |
51 theSampleStartTime = (double) System.currentTimeMillis(); | |
52 | |
53 ++theAsyncOutCount; | |
54 --theQueueSize; | |
55 | |
56 /* | |
57 Probably this should be based on low watermark so the | |
58 calculation is available before the high watermark is hit. | |
59 Probably ought to remove desired pending count as well at some | |
60 point. | |
61 */ | |
62 if (theAsyncOutCount == 1000) { | |
63 double myDuration = (double) System.currentTimeMillis() - | |
64 theSampleStartTime; | |
65 | |
66 theTimePerOut = myDuration / 1000.0; | |
67 theTimePerIn = myDuration / (double) theAsyncInCount; | |
68 | |
69 theInOutLag = theTimePerOut - theTimePerIn; | |
70 theInOutRatio = theTimePerOut / theTimePerIn; | |
71 | |
72 theAsyncOutCount = theAsyncInCount = 0; | |
73 | |
74 return true; | |
75 } | |
76 | |
77 return false; | |
78 } | |
79 } | |
80 | |
81 void dumpStats() { | |
82 synchronized(this) { | |
83 WriteDaemon.theLogger.log(Level.INFO, "TPI: " + theTimePerIn + | |
84 " TPO: " + theTimePerOut + " IOL: " + theInOutLag + | |
85 " IOR: " + theInOutRatio + " QSZ: " + theQueueSize); | |
86 } | |
87 } | |
88 } |