Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 230   Methods: 16
NCLOC: 168   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CacheMgmtInterceptor.java 57.1% 73.3% 81.2% 72.5%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source
 3    * Copyright 2005, JBoss Inc., and individual contributors as indicated
 4    * by the @authors tag. See the copyright.txt in the distribution for a
 5    * full listing of individual contributors.
 6    *
 7    * This is free software; you can redistribute it and/or modify it
 8    * under the terms of the GNU Lesser General Public License as
 9    * published by the Free Software Foundation; either version 2.1 of
 10    * the License, or (at your option) any later version.
 11    *
 12    * This software is distributed in the hope that it will be useful,
 13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15    * Lesser General Public License for more details.
 16    *
 17    * You should have received a copy of the GNU Lesser General Public
 18    * License along with this software; if not, write to the Free
 19    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21    */
 22    package org.jboss.cache.interceptors;
 23   
 24    import org.jboss.cache.CacheSPI;
 25    import org.jboss.cache.InvocationContext;
 26    import org.jboss.cache.marshall.MethodCall;
 27    import org.jboss.cache.marshall.MethodDeclarations;
 28   
 29    import java.util.HashMap;
 30    import java.util.Map;
 31   
 32    /**
 33    * Captures cache management statistics
 34    *
 35    * @author Jerry Gauthier
 36    * @version $Id: CacheMgmtInterceptor.java,v 1.32 2007/06/06 12:43:48 msurtani Exp $
 37    */
 38    public class CacheMgmtInterceptor
 39    extends Interceptor
 40    implements CacheMgmtInterceptorMBean
 41    {
 42    private long m_hit_times = 0;
 43    private long m_miss_times = 0;
 44    private long m_store_times = 0;
 45    private long m_hits = 0;
 46    private long m_misses = 0;
 47    private long m_stores = 0;
 48    private long m_evictions = 0;
 49    private long m_start = System.currentTimeMillis();
 50    private long m_reset = m_start;
 51   
 52  5668 public void setCache(CacheSPI cache)
 53    {
 54  5668 super.setCache(cache);
 55    }
 56   
 57    /**
 58    * Pass the method on and capture cache statistics
 59    *
 60    * @return
 61    * @throws Throwable
 62    */
 63  2485340 public Object invoke(InvocationContext ctx) throws Throwable
 64    {
 65  2485340 MethodCall m = ctx.getMethodCall();
 66  2485340 Map attributes;
 67  2485340 Object[] args = m.getArgs();
 68  2485340 Object retval;
 69   
 70    // if statistics not enabled, execute the method and return
 71  2485340 if (!getStatisticsEnabled())
 72  2139 return super.invoke(ctx);
 73   
 74  2483201 long t1, t2;
 75  2483201 switch (m.getMethodId())
 76    {
 77  1511832 case MethodDeclarations.getKeyValueMethodLocal_id:
 78    //fqn = (Fqn) args[0];
 79    //key = args[1];
 80  1511832 t1 = System.currentTimeMillis();
 81  1511832 retval = super.invoke(ctx);
 82  1511819 t2 = System.currentTimeMillis();
 83  1511819 if (retval == null)
 84    {
 85  1123844 m_miss_times = m_miss_times + (t2 - t1);
 86  1123844 m_misses++;
 87    }
 88    else
 89    {
 90  387975 m_hit_times = m_hit_times + (t2 - t1);
 91  387975 m_hits++;
 92    }
 93  1511819 break;
 94  24 case MethodDeclarations.putForExternalReadMethodLocal_id:
 95  404736 case MethodDeclarations.putKeyValMethodLocal_id:
 96  404760 t1 = System.currentTimeMillis();
 97  404771 retval = super.invoke(ctx);
 98  404751 t2 = System.currentTimeMillis();
 99  404751 m_store_times = m_store_times + (t2 - t1);
 100  404751 m_stores++;
 101  404751 break;
 102  11651 case MethodDeclarations.putDataMethodLocal_id:
 103  2 case MethodDeclarations.putDataEraseMethodLocal_id:
 104    //fqn = (Fqn) args[1];
 105  11653 attributes = (Map) args[2];
 106  11653 t1 = System.currentTimeMillis();
 107  11653 retval = super.invoke(ctx);
 108  11650 t2 = System.currentTimeMillis();
 109   
 110  11650 if (attributes != null && attributes.size() > 0)
 111    {
 112  6029 m_store_times = m_store_times + (t2 - t1);
 113  6029 m_stores = m_stores + attributes.size();
 114    }
 115  11650 break;
 116  118242 case MethodDeclarations.evictNodeMethodLocal_id:
 117  0 case MethodDeclarations.evictVersionedNodeMethodLocal_id:
 118    //fqn = (Fqn) args[0];
 119  118242 retval = super.invoke(ctx);
 120  118240 m_evictions++;
 121  118240 break;
 122  436703 default:
 123  436703 retval = super.invoke(ctx);
 124  436668 break;
 125    }
 126   
 127  2483118 return retval;
 128    }
 129   
 130  2 public long getHits()
 131    {
 132  2 return m_hits;
 133    }
 134   
 135  2 public long getMisses()
 136    {
 137  2 return m_misses;
 138    }
 139   
 140  3 public long getStores()
 141    {
 142  3 return m_stores;
 143    }
 144   
 145  3 public long getEvictions()
 146    {
 147  3 return m_evictions;
 148    }
 149   
 150  1 public double getHitMissRatio()
 151    {
 152  1 double total = m_hits + m_misses;
 153  1 if (total == 0)
 154  0 return 0;
 155  1 return (m_hits / total);
 156    }
 157   
 158  1 public double getReadWriteRatio()
 159    {
 160  1 if (m_stores == 0)
 161  0 return 0;
 162  1 return (((double) (m_hits + m_misses) / (double) m_stores));
 163    }
 164   
 165  0 public long getAverageReadTime()
 166    {
 167  0 long total = m_hits + m_misses;
 168  0 if (total == 0)
 169  0 return 0;
 170  0 return (m_hit_times + m_miss_times) / total;
 171    }
 172   
 173  0 public long getAverageWriteTime()
 174    {
 175  0 if (m_stores == 0)
 176  0 return 0;
 177  0 return (m_store_times) / m_stores;
 178    }
 179   
 180  3 public int getNumberOfAttributes()
 181    {
 182  3 return cache.getNumberOfAttributes();
 183    }
 184   
 185  3 public int getNumberOfNodes()
 186    {
 187  3 return cache.getNumberOfNodes();
 188    }
 189   
 190  2 public long getElapsedTime()
 191    {
 192  2 return (System.currentTimeMillis() - m_start) / 1000;
 193    }
 194   
 195  2 public long getTimeSinceReset()
 196    {
 197  2 return (System.currentTimeMillis() - m_reset) / 1000;
 198    }
 199   
 200  0 public Map<String, Object> dumpStatistics()
 201    {
 202  0 Map<String, Object> retval = new HashMap<String, Object>();
 203  0 retval.put("Hits", m_hits);
 204  0 retval.put("Misses", m_misses);
 205  0 retval.put("Stores", m_stores);
 206  0 retval.put("Evictions", m_evictions);
 207  0 retval.put("NumberOfAttributes", cache.getNumberOfAttributes());
 208  0 retval.put("NumberOfNodes", cache.getNumberOfNodes());
 209  0 retval.put("ElapsedTime", getElapsedTime());
 210  0 retval.put("TimeSinceReset", getTimeSinceReset());
 211  0 retval.put("AverageReadTime", getAverageReadTime());
 212  0 retval.put("AverageWriteTime", getAverageWriteTime());
 213  0 retval.put("HitMissRatio", getHitMissRatio());
 214  0 retval.put("ReadWriteRatio", getReadWriteRatio());
 215  0 return retval;
 216    }
 217   
 218  1 public void resetStatistics()
 219    {
 220  1 m_hits = 0;
 221  1 m_misses = 0;
 222  1 m_stores = 0;
 223  1 m_evictions = 0;
 224  1 m_hit_times = 0;
 225  1 m_miss_times = 0;
 226  1 m_store_times = 0;
 227  1 m_reset = System.currentTimeMillis();
 228    }
 229    }
 230