FileDocCategorySizeDatePackage
InvocationStatistics.javaAPI DocJBoss 4.2.15412Fri Jul 13 20:53:52 BST 2007org.jboss.ejb3.statistics

InvocationStatistics

public class InvocationStatistics extends Object implements Serializable
A method invocation statistics collection class.
author
Scott.Stark@jboss.org
author
William DeCoste

Fields Summary
private static final long
serialVersionUID
private Map
methodStats
A HashMap of the method invocations
public long
concurrentCalls
public long
maxConcurrentCalls
public long
lastResetTime
Constructors Summary
public InvocationStatistics()

      methodStats = new ConcurrentReaderHashMap();
   
Methods Summary
public synchronized voidcallIn()

      concurrentCalls++;
      if (concurrentCalls > maxConcurrentCalls)
         maxConcurrentCalls = concurrentCalls;
   
public synchronized voidcallOut()

      concurrentCalls--;
   
public java.util.MapgetStats()
Access the current collection of method invocation statistics

return
A HashMap of the method invocations

      return methodStats;
   
public voidresetStats()
Resets all current TimeStatistics.

      synchronized (methodStats)
      {
         Iterator iter = methodStats.values().iterator();
         while (iter.hasNext())
         {
            TimeStatistic stat = (TimeStatistic) iter.next();
            stat.reset();
         }
      }
      maxConcurrentCalls = 0;
      lastResetTime = System.currentTimeMillis();
   
public java.lang.StringtoString()
Generate an XML fragement for the InvocationStatistics. The format is ...

return
an XML representation of the InvocationStatistics

      StringBuffer tmp = new StringBuffer("<InvocationStatistics concurrentCalls='");
      tmp.append(concurrentCalls);
      tmp.append("' >\n");

      HashMap copy = new HashMap(methodStats);
      Iterator iter = copy.entrySet().iterator();
      while (iter.hasNext())
      {
         Map.Entry entry = (Map.Entry) iter.next();
         TimeStatistic stat = (TimeStatistic) entry.getValue();
         if (stat != null)
         {
            tmp.append("<method name='");
            tmp.append(entry.getKey());
            tmp.append("' count='");
            tmp.append(stat.count);
            tmp.append("' minTime='");
            tmp.append(stat.minTime);
            tmp.append("' maxTime='");
            tmp.append(stat.maxTime);
            tmp.append("' totalTime='");
            tmp.append(stat.totalTime);
            tmp.append("' />\n");
         }
      }
      tmp.append("</InvocationStatistics>");
      return tmp.toString();
   
public voidupdateStats(java.lang.reflect.Method m, long elapsed)
Update the TimeStatistic for the given method. This synchronizes on m to ensure that the TimeStatistic for m is updated atomically.

param
m the method to update the statistics for.
param
elapsed the elapsed time in milliseconds for the invocation.

      TimeStatistic stat = (TimeStatistic) methodStats.get(m.getName());
      if (stat == null)
      {
         stat = new TimeStatistic();
         methodStats.put(m.getName(), stat);
      }
      stat.count++;
      stat.totalTime += elapsed;
      if (stat.minTime > elapsed)
         stat.minTime = elapsed;
      if (stat.maxTime < elapsed)
         stat.maxTime = elapsed;