Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

org.objectweb.cjdbc.common.util.Stats Class Reference

List of all members.

Public Member Functions

 Stats (String statName)
synchronized void reset ()
synchronized void incrementCount ()
synchronized void incrementError ()
synchronized void incrementCacheHit ()
synchronized void updateTime (long time)
String getName ()
synchronized int getCount ()
synchronized int getError ()
synchronized int getCacheHit ()
synchronized long getMinTime ()
synchronized long getMaxTime ()
synchronized long getTotalTime ()
synchronized void merge (Stats anotherStat) throws Exception
void displayOnStdout ()
String multipleLineDisplay ()
String singleLineDisplay ()
String[] toStringTable ()

Detailed Description

This class provides thread-safe statistics. Each statistic entry is composed as follow:

Author:
Emmanuel Cecchet

Julie Marguerite

Version:
1.0

Definition at line 43 of file Stats.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.common.util.Stats.Stats String  statName  ) 
 

Creates a new Stats instance. The entries are reset to 0.

Parameters:
statName The stat name

Definition at line 71 of file Stats.java.

00072   {
00073     name = statName;
00074     reset();
00075   }


Member Function Documentation

void org.objectweb.cjdbc.common.util.Stats.displayOnStdout  ) 
 

Displays the statistics on the standard output.

Definition at line 230 of file Stats.java.

00231   {
00232     System.out.println(multipleLineDisplay());
00233   }

synchronized int org.objectweb.cjdbc.common.util.Stats.getCacheHit  ) 
 

Gets current cache hit count of an entry

Returns:
current entry cache hit value

Definition at line 169 of file Stats.java.

00170   {
00171     return cacheHit;
00172   }

synchronized int org.objectweb.cjdbc.common.util.Stats.getCount  ) 
 

Gets current count of an entry.

Returns:
current entry count value

Definition at line 149 of file Stats.java.

00150   {
00151     return count;
00152   }

synchronized int org.objectweb.cjdbc.common.util.Stats.getError  ) 
 

Gets current error count of an entry

Returns:
current entry error value

Definition at line 159 of file Stats.java.

00160   {
00161     return error;
00162   }

synchronized long org.objectweb.cjdbc.common.util.Stats.getMaxTime  ) 
 

Gets the maximum time of an entry

Returns:
entry maximum time

Definition at line 189 of file Stats.java.

00190   {
00191     return maxTime;
00192   }

synchronized long org.objectweb.cjdbc.common.util.Stats.getMinTime  ) 
 

Gets the minimum time of an entry

Returns:
entry minimum time

Definition at line 179 of file Stats.java.

00180   {
00181     return minTime;
00182   }

String org.objectweb.cjdbc.common.util.Stats.getName  ) 
 

Gets the name of the current stat.

Returns:
stat name

Definition at line 139 of file Stats.java.

Referenced by org.objectweb.cjdbc.controller.monitoring.SQLMonitoring.logCacheHit(), org.objectweb.cjdbc.controller.monitoring.SQLMonitoring.logError(), and org.objectweb.cjdbc.controller.monitoring.SQLMonitoring.logRequestTime().

00140   {
00141     return name;
00142   }

synchronized long org.objectweb.cjdbc.common.util.Stats.getTotalTime  ) 
 

Gets the total time of an entry

Returns:
entry total time

Definition at line 199 of file Stats.java.

00200   {
00201     return totalTime;
00202   }

synchronized void org.objectweb.cjdbc.common.util.Stats.incrementCacheHit  ) 
 

Increments an entry cache hit by one.

Definition at line 108 of file Stats.java.

Referenced by org.objectweb.cjdbc.controller.monitoring.SQLMonitoring.logCacheHit().

00109   {
00110     cacheHit++;
00111   }

synchronized void org.objectweb.cjdbc.common.util.Stats.incrementCount  ) 
 

Increments an entry count by one.

Definition at line 92 of file Stats.java.

Referenced by org.objectweb.cjdbc.controller.monitoring.SQLMonitoring.logRequestTime().

00093   {
00094     count++;
00095   }

synchronized void org.objectweb.cjdbc.common.util.Stats.incrementError  ) 
 

Increments an entry error by one.

Definition at line 100 of file Stats.java.

Referenced by org.objectweb.cjdbc.controller.monitoring.SQLMonitoring.logError().

00101   {
00102     error++;
00103   }

synchronized void org.objectweb.cjdbc.common.util.Stats.merge Stats  anotherStat  )  throws Exception
 

Adds the entries of another Stats object to this one.

Parameters:
anotherStat stat to merge with current stat
Exceptions:
Exception if you try to merge a stat with itself

Definition at line 210 of file Stats.java.

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   }

String org.objectweb.cjdbc.common.util.Stats.multipleLineDisplay  ) 
 

Displays the statistics information on multiple lines.

Returns:
a String containing the Stat output

Definition at line 240 of file Stats.java.

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   }

synchronized void org.objectweb.cjdbc.common.util.Stats.reset  ) 
 

Resets all entries to 0.

Definition at line 80 of file Stats.java.

Referenced by org.objectweb.cjdbc.controller.monitoring.SQLMonitoring.resetRequestStat().

00081   {
00082     count = 0;
00083     error = 0;
00084     minTime = Long.MAX_VALUE;
00085     maxTime = Long.MIN_VALUE;
00086     totalTime = 0;
00087   }

String org.objectweb.cjdbc.common.util.Stats.singleLineDisplay  ) 
 

Displays the statistics information on a single line in the format: name count error cacheHit hit minTime maxTime avgTime totalTime

Returns:
a String containing the Stat output

Definition at line 274 of file Stats.java.

Referenced by org.objectweb.cjdbc.controller.monitoring.SQLMonitoring.dumpAllStatsInformation().

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   }

String [] org.objectweb.cjdbc.common.util.Stats.toStringTable  ) 
 

Get the stat information in the form of a String table. Format is: name count error cacheHit hit minTime maxTime avgTime totalTime

Returns:
the String table corresponding to this stat

Definition at line 304 of file Stats.java.

Referenced by org.objectweb.cjdbc.controller.monitoring.SQLMonitoring.getAllStatsInformation().

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   }

synchronized void org.objectweb.cjdbc.common.util.Stats.updateTime long  time  ) 
 

Adds a new time sample for this entry. time is added to total time and both minTime and maxTime are updated if needed.

Parameters:
time time to add to this entry

Definition at line 119 of file Stats.java.

Referenced by org.objectweb.cjdbc.controller.monitoring.SQLMonitoring.logRequestTime().

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   }


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:02:14 2005 for C-JDBC by  doxygen 1.3.9.1