src/org/objectweb/cjdbc/common/util/Stats.java

説明を見る。
00001 00025 package org.objectweb.cjdbc.common.util; 00026 00043 public class Stats 00044 { 00046 private int count; 00047 00049 private int error; 00050 00052 private int cacheHit; 00053 00055 private long minTime; 00056 00058 private long maxTime; 00059 00061 private long totalTime; 00062 00064 private String name; 00065 00071 public Stats(String statName) 00072 { 00073 name = statName; 00074 reset(); 00075 } 00076 00080 public synchronized void reset() 00081 { 00082 count = 0; 00083 error = 0; 00084 minTime = Long.MAX_VALUE; 00085 maxTime = Long.MIN_VALUE; 00086 totalTime = 0; 00087 } 00088 00092 public synchronized void incrementCount() 00093 { 00094 count++; 00095 } 00096 00100 public synchronized void incrementError() 00101 { 00102 error++; 00103 } 00104 00108 public synchronized void incrementCacheHit() 00109 { 00110 cacheHit++; 00111 } 00112 00119 public synchronized void updateTime(long time) 00120 { 00121 if (time < 0) 00122 { 00123 System.err.println("Negative time received in Stats.updateTime(" + time 00124 + ")\n"); 00125 return; 00126 } 00127 totalTime += time; 00128 if (time > maxTime) 00129 maxTime = time; 00130 if (time < minTime) 00131 minTime = time; 00132 } 00133 00139 public String getName() 00140 { 00141 return name; 00142 } 00143 00149 public synchronized int getCount() 00150 { 00151 return count; 00152 } 00153 00159 public synchronized int getError() 00160 { 00161 return error; 00162 } 00163 00169 public synchronized int getCacheHit() 00170 { 00171 return cacheHit; 00172 } 00173 00179 public synchronized long getMinTime() 00180 { 00181 return minTime; 00182 } 00183 00189 public synchronized long getMaxTime() 00190 { 00191 return maxTime; 00192 } 00193 00199 public synchronized long getTotalTime() 00200 { 00201 return totalTime; 00202 } 00203 00210 public synchronized void merge(Stats anotherStat) throws Exception 00211 { 00212 if (this == anotherStat) 00213 { 00214 throw new Exception("You cannot merge a stat with itself"); 00215 } 00216 00217 count += anotherStat.getCount(); 00218 error += anotherStat.getError(); 00219 cacheHit += anotherStat.getCacheHit(); 00220 if (minTime > anotherStat.getMinTime()) 00221 minTime = anotherStat.getMinTime(); 00222 if (maxTime < anotherStat.getMaxTime()) 00223 maxTime = anotherStat.getMaxTime(); 00224 totalTime += anotherStat.getTotalTime(); 00225 } 00226 00230 public void displayOnStdout() 00231 { 00232 System.out.println(multipleLineDisplay()); 00233 } 00234 00240 public String multipleLineDisplay() 00241 { 00242 String output = name + " statistics:\n" + " Count: " + count + "\n" 00243 + " Error: " + error + "\n"; 00244 if (totalTime != 0) 00245 { 00246 output += " Min time: " + minTime + " ms\n"; 00247 output += " Max time: " + maxTime + " ms\n"; 00248 } 00249 else 00250 { 00251 output += " Min time: 0 ms\n"; 00252 output += " Max time: 0 ms\n"; 00253 } 00254 if (count == 0) 00255 output += " Avg time: 0 ms\n"; 00256 else 00257 output += " Avg time: " + totalTime / count + " ms\n"; 00258 output += " Tot time: " + totalTime + " ms\n"; 00259 00260 double timeSec = totalTime / 1000; 00261 double timeMin = timeSec / 60, throup; 00262 throup = (timeMin != 0) ? (count / timeMin) : (count / timeSec); 00263 output += " Throughput: " + throup 00264 + ((timeMin != 0) ? " requests/minute" : " requests/second"); 00265 return output; 00266 } 00267 00274 public String singleLineDisplay() 00275 { 00276 String output = name + " " + count + " " + error + " " + cacheHit + " "; 00277 if (count == 0) 00278 output += "0 "; 00279 else 00280 output += ((double) cacheHit / (double) count * 100.0) + " "; 00281 if (totalTime != 0) 00282 output += minTime + " " + maxTime + " "; 00283 else 00284 output += " 0 0 "; 00285 if (count == 0) 00286 output += "0 "; 00287 else 00288 output += totalTime / count + " "; 00289 output += totalTime; 00290 double timeSec = totalTime / 1000; 00291 double timeMin = timeSec / 60, throup; 00292 throup = (timeMin != 0) ? (count / timeMin) : (count / timeSec); 00293 output += throup 00294 + ((timeMin != 0) ? " requests/minute" : " requests/second"); 00295 return output; 00296 } 00297 00304 public String[] toStringTable() 00305 { 00306 String[] foo = { 00307 name, 00308 Integer.toString(count), 00309 Integer.toString(error), 00310 Integer.toString(cacheHit), 00311 (count == 0) ? "0" : Float.toString((float) cacheHit / (float) count 00312 * (float) 100.0), Long.toString(minTime), Long.toString(maxTime), 00313 (count == 0) ? "0" : Float.toString((float) totalTime / (float) count), 00314 Long.toString(totalTime)}; 00315 return foo; 00316 } 00317 }

CJDBCversion1.0.4に対してTue Oct 12 15:15:58 2004に生成されました。 doxygen 1.3.8