Changeset 191

Show
Ignore:
Timestamp:
02/23/06 16:34:38
Author:
douglm
Message:

More statistics changes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/calendar3/appcommon/src/org/bedework/appcommon/TimeView.java

    r185 r191  
    106106  private TimeViewDailyInfo[] tvdis; 
    107107   
    108   private static final TimezoneCache tzcache = new TimezoneCache(false); 
     108  //private static final TimezoneCache tzcache = new TimezoneCache(false); 
    109109 
    110110  /** Constructor: 
     
    270270  public Collection getDaysEvents(MyCalendarVO date) throws Throwable { 
    271271    Vector v = new Vector(); 
     272    CalTimezones tzcache = cal.getTimezones(); 
    272273//    Dur oneDay = new Dur(1, 0, 0, 0); 
    273274    long millis = System.currentTimeMillis(); 
    274275     
    275     tzcache.setSysTimezones(cal.getTimezones()); 
     276    //tzcache.setSysTimezones(cal.getTimezones()); 
    276277    BwDateTime startDt = CalFacadeUtil.getDateTime(date.getDateDigits(), 
    277278                                                   tzcache); 
    278 //                                                   cal.getTimezones()); 
    279  
    280 //    BwDateTime endDt = startDt.getNextDay(cal.getTimezones()); 
     279 
    281280    BwDateTime endDt = startDt.getNextDay(tzcache); 
    282281    String start = startDt.getDate(); 
     
    291290      events = cal.getEvents(null, null, 
    292291                             CalFacadeUtil.getDateTime(firstDay.getDateDigits(), 
    293 //                                                     cal.getTimezones()), 
    294292                                                       tzcache), 
    295293                             CalFacadeUtil.getDateTime(lastDay.getTomorrow().getDateDigits(), 
    296 //                                                     cal.getTimezones()), 
    297294                                                       tzcache), 
    298295                             CalFacadeDefs.retrieveRecurExpanded); 
  • trunk/calendar3/appcommon/src/org/bedework/appcommon/TimezoneCache.java

    r185 r191  
    137137    HashMap cache; 
    138138     
    139     if (tz == null) { 
     139    if (tzid == null) { 
    140140      cache = defaultCache; 
    141     } else if (tz.equals(getDefaultTimeZoneId())) { 
     141    } else if (tzid.equals(getDefaultTimeZoneId())) { 
    142142      cache = defaultCache; 
    143143    } else { 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalTimezonesImpl.java

    r171 r191  
    175175  public void clearPublicTimezones() throws CalFacadeException { 
    176176    cal.clearPublicTimezones(); 
     177    super.clearPublicTimezones(); 
    177178  } 
    178179 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java

    r176 r191  
    338338 
    339339  public BwStats getStats() throws CalFacadeException { 
     340    if (stats == null) { 
     341      return null; 
     342    } 
     343     
     344    BwRWStats rwstats = (BwRWStats)stats; 
     345     
     346    if (timezones != null) { 
     347      rwstats.setDateCacheHits(timezones.getDateCacheHits()); 
     348      rwstats.setDateCacheMisses(timezones.getDateCacheMisses()); 
     349      rwstats.setDatesCached(timezones.getDatesCached()); 
     350    } 
     351     
    340352    return stats; 
    341353  } 
    342354 
    343   public void setStats(boolean enable) throws CalFacadeException { 
     355  public void setDbStatsEnabled(boolean enable) throws CalFacadeException { 
    344356    if (!enable && (dbStats == null)) { 
    345357      return; 
     
    352364    dbStats.setStatisticsEnabled(enable); 
    353365  } 
     366 
     367  public boolean getDbStatsEnabled() throws CalFacadeException { 
     368    if (dbStats == null) { 
     369      return false; 
     370    } 
     371     
     372    return dbStats.isStatisticsEnabled(); 
     373  } 
    354374   
    355   public void dumpStats() throws CalFacadeException { 
     375  public void dumpDbStats() throws CalFacadeException { 
    356376    DbStatistics.dumpStats(dbStats); 
     377  } 
     378   
     379  public Collection getDbStats() throws CalFacadeException { 
     380    return DbStatistics.getStats(dbStats); 
    357381  } 
    358382 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/DbStatistics.java

    r176 r191  
    5454package org.bedework.calcore.hibernate; 
    5555 
     56import java.util.Collection; 
     57import java.util.Vector; 
     58 
    5659import org.bedework.calfacade.BwCalendar; 
    5760import org.bedework.calfacade.BwCategory; 
     
    5962import org.bedework.calfacade.BwLocation; 
    6063import org.bedework.calfacade.BwSponsor; 
     64import org.bedework.calfacade.BwStats; 
    6165import org.bedework.calfacade.BwUser; 
     66import org.bedework.calfacade.BwStats.StatsEntry; 
    6267 
    6368import org.apache.log4j.Logger; 
     
    7378 */ 
    7479public class DbStatistics { 
    75   private static final int lcolw = 50; 
    76    
    7780  public static void dumpStats(Statistics dbStats) { 
     81    if (dbStats == null) { 
     82      return; 
     83    } 
     84 
     85    Logger log = Logger.getLogger(DbStatistics.class); 
     86 
     87    log.debug(BwStats.toString(getStats(dbStats))); 
     88  } 
     89 
     90  public static Collection getStats(Statistics dbStats) { 
    7891    /* XXX this ought to be property driven to some extent. The cache stats in 
    7992     * particular. 
    8093     */ 
     94    Vector v = new Vector(); 
     95 
    8196    if (dbStats == null) { 
    82       return
     97      return v
    8398    } 
    84      
    85     Logger log = Logger.getLogger(DbStatistics.class); 
    86      
    87     log.debug(lpad("Number of connection requests: " , lcolw) +  
    88               dbStats.getConnectCount()); 
    89     log.debug(lpad("Session flushes: " , lcolw) +  
    90               dbStats.getFlushCount()); 
    91     log.debug(lpad("Transactions: " , lcolw) + 
    92               dbStats.getTransactionCount()); 
    93     log.debug(lpad("Successful transactions: " , lcolw) +  
    94               dbStats.getSuccessfulTransactionCount()); 
    95     log.debug(lpad("Sessions opened: " , lcolw) + 
    96               dbStats.getSessionOpenCount()); 
    97     log.debug(lpad("Sessions closed: " , lcolw) + 
    98               dbStats.getSessionCloseCount()); 
    99     log.debug(lpad("Queries executed: " , lcolw) +  
    100               dbStats.getQueryExecutionCount()); 
    101     log.debug(lpad("Slowest query time: " , lcolw) +  
    102               dbStats.getQueryExecutionMaxTime()); 
    103      
    104     log.debug(" ");  
    105     log.debug(lpad("Collection statistics" , lcolw));  
    106     log.debug(" ");  
    107      
    108     log.debug(lpad("Collections fetched: " , lcolw) + 
    109               dbStats.getCollectionFetchCount()); 
    110     log.debug(lpad("Collections loaded: " , lcolw) + 
    111               dbStats.getCollectionLoadCount()); 
    112     log.debug(lpad("Collections rebuilt: " , lcolw) + 
    113               dbStats.getCollectionRecreateCount()); 
    114     log.debug(lpad("Collections batch deleted: " , lcolw) + 
    115               dbStats.getCollectionRemoveCount()); 
    116     log.debug(lpad("Collections batch updated: " , lcolw) + 
    117               dbStats.getCollectionUpdateCount()); 
    118      
    119     log.debug(" ");  
    120     log.debug(lpad("Object statistics" , lcolw));  
    121     log.debug(" ");  
    122      
    123     log.debug(lpad("Objects fetched: " , lcolw) + 
    124               dbStats.getEntityFetchCount()); 
    125     log.debug(lpad("Objects loaded: " , lcolw) + 
    126               dbStats.getEntityLoadCount()); 
    127     log.debug(lpad("Objects inserted: " , lcolw) + 
    128               dbStats.getEntityInsertCount()); 
    129     log.debug(lpad("Objects deleted: " , lcolw) + 
    130               dbStats.getEntityDeleteCount()); 
    131     log.debug(lpad("Objects updated: " , lcolw) + 
    132               dbStats.getEntityUpdateCount()); 
    13399 
    134     log.debug(" ");  
    135     log.debug(lpad("Cache statistics" , lcolw));  
    136     log.debug(" ");  
    137      
     100    v.add(new StatsEntry("Number of connection requests", dbStats.getConnectCount())); 
     101    v.add(new StatsEntry("Session flushes", dbStats.getFlushCount())); 
     102    v.add(new StatsEntry("Transactions", dbStats.getTransactionCount())); 
     103    v.add(new StatsEntry("Successful transactions", dbStats.getSuccessfulTransactionCount())); 
     104    v.add(new StatsEntry("Sessions opened", dbStats.getSessionOpenCount())); 
     105    v.add(new StatsEntry("Sessions closed", dbStats.getSessionCloseCount())); 
     106    v.add(new StatsEntry("Queries executed", dbStats.getQueryExecutionCount())); 
     107    v.add(new StatsEntry("Slowest query time", dbStats.getQueryExecutionMaxTime())); 
     108 
     109    v.add(new StatsEntry("Collection statistics")); 
     110 
     111    v.add(new StatsEntry("Collections fetched", dbStats.getCollectionFetchCount())); 
     112    v.add(new StatsEntry("Collections loaded", dbStats.getCollectionLoadCount())); 
     113    v.add(new StatsEntry("Collections rebuilt", dbStats.getCollectionRecreateCount())); 
     114    v.add(new StatsEntry("Collections batch deleted", dbStats.getCollectionRemoveCount())); 
     115    v.add(new StatsEntry("Collections batch updated", dbStats.getCollectionUpdateCount())); 
     116 
     117    v.add(new StatsEntry("Object statistics")); 
     118 
     119    v.add(new StatsEntry("Objects fetched", dbStats.getEntityFetchCount())); 
     120    v.add(new StatsEntry("Objects loaded", dbStats.getEntityLoadCount())); 
     121    v.add(new StatsEntry("Objects inserted", dbStats.getEntityInsertCount())); 
     122    v.add(new StatsEntry("Objects deleted", dbStats.getEntityDeleteCount())); 
     123    v.add(new StatsEntry("Objects updated", dbStats.getEntityUpdateCount())); 
     124 
     125    v.add(new StatsEntry("Cache statistics")); 
     126 
    138127    double chit = dbStats.getQueryCacheHitCount(); 
    139128    double cmiss = dbStats.getQueryCacheMissCount(); 
    140      
    141     log.debug(lpad("Cache hit count: " , lcolw) + chit); 
    142     log.debug(lpad("Cache miss count: " , lcolw) + cmiss); 
    143     log.debug(lpad("Cache hit ratio: " , lcolw) + chit / (chit + cmiss)); 
    144129 
    145     entityStats(dbStats, BwCalendar.class, log); 
    146     entityStats(dbStats, BwCategory.class, log); 
    147     entityStats(dbStats, BwEventObj.class, log); 
    148     entityStats(dbStats, BwLocation.class, log); 
    149     entityStats(dbStats, BwSponsor.class, log); 
    150     entityStats(dbStats, BwUser.class, log); 
     130    v.add(new StatsEntry("Cache hit count", chit)); 
     131    v.add(new StatsEntry("Cache miss count", cmiss)); 
     132    v.add(new StatsEntry("Cache hit ratio", chit / (chit + cmiss))); 
    151133 
    152     collectionStats(dbStats, BwCalendar.class, "children", log); 
    153     collectionStats(dbStats, BwEventObj.class, "categories", log); 
    154     collectionStats(dbStats, BwEventObj.class, "attendees", log); 
    155     collectionStats(dbStats, BwEventObj.class, "rrules", log); 
    156     //collectionStats(dbStats, BwEventObj.class, "exrules", log); 
    157     collectionStats(dbStats, BwEventObj.class, "rdates", log); 
    158     collectionStats(dbStats, BwEventObj.class, "exdates", log); 
     134    entityStats(v, dbStats, BwCalendar.class); 
     135    entityStats(v, dbStats, BwCategory.class); 
     136    entityStats(v, dbStats, BwEventObj.class); 
     137    entityStats(v, dbStats, BwLocation.class); 
     138    entityStats(v, dbStats, BwSponsor.class); 
     139    entityStats(v, dbStats, BwUser.class); 
     140 
     141    collectionStats(v, dbStats, BwCalendar.class, "children"); 
     142    collectionStats(v, dbStats, BwEventObj.class, "categories"); 
     143    collectionStats(v, dbStats, BwEventObj.class, "attendees"); 
     144    collectionStats(v, dbStats, BwEventObj.class, "rrules"); 
     145    //collectionStats(v, dbStats, BwEventObj.class, "exrules"); 
     146    collectionStats(v, dbStats, BwEventObj.class, "rdates"); 
     147    collectionStats(v, dbStats, BwEventObj.class, "exdates"); 
     148 
     149    return v; 
    159150  } 
    160    
    161   private static void entityStats(Statistics dbStats, Class cl, Logger log) { 
     151 
     152  private static void entityStats(Collection c, Statistics dbStats, 
     153                                  Class cl) { 
    162154    String name = cl.getName(); 
    163      
    164     log.debug(" ");  
    165     log.debug(lpad("Statistics for " + name , lcolw));  
    166     log.debug(" ");  
    167      
     155 
     156    c.add(new StatsEntry("Statistics for " + name)); 
     157 
    168158    EntityStatistics eStats = dbStats.getEntityStatistics(name); 
    169159 
    170     log.debug(lpad("Fetched: " , lcolw) + eStats.getFetchCount()); 
    171     log.debug(lpad("Loaded: " , lcolw) + eStats.getLoadCount()); 
    172     log.debug(lpad("Inserted: " , lcolw) + eStats.getInsertCount()); 
    173     log.debug(lpad("Deleted: " , lcolw) + eStats.getDeleteCount()); 
    174     log.debug(lpad("Updated: " , lcolw) + eStats.getUpdateCount()); 
     160    c.add(new StatsEntry("Fetched", eStats.getFetchCount())); 
     161    c.add(new StatsEntry("Loaded", eStats.getLoadCount())); 
     162    c.add(new StatsEntry("Inserted", eStats.getInsertCount())); 
     163    c.add(new StatsEntry("Deleted", eStats.getDeleteCount())); 
     164    c.add(new StatsEntry("Updated", eStats.getUpdateCount())); 
    175165  } 
    176    
    177   private static void collectionStats(Statistics dbStats, Class cl,  
    178                                       String cname, Logger log) { 
     166 
     167  private static void collectionStats(Collection c, Statistics dbStats, Class cl, 
     168                                      String cname) { 
    179169    String name = cl.getName() + "." + cname; 
    180      
    181     log.debug(" ");  
    182     log.debug(lpad("Statistics for " + name , lcolw));  
    183     log.debug(" ");  
    184      
     170 
     171    c.add(new StatsEntry("Statistics for " + name)); 
     172 
    185173    CollectionStatistics cStats = dbStats.getCollectionStatistics(name); 
    186174 
    187     log.debug(lpad("Fetched: " , lcolw) + cStats.getFetchCount()); 
    188     log.debug(lpad("Loaded: " , lcolw) + cStats.getLoadCount()); 
    189     log.debug(lpad("Recreated: " , lcolw) + cStats.getRecreateCount()); 
    190     log.debug(lpad("Removed: " , lcolw) + cStats.getRemoveCount()); 
    191     log.debug(lpad("Updated: " , lcolw) + cStats.getUpdateCount()); 
     175    c.add(new StatsEntry("Fetched", cStats.getFetchCount())); 
     176    c.add(new StatsEntry("Loaded", cStats.getLoadCount())); 
     177    c.add(new StatsEntry("Recreated", cStats.getRecreateCount())); 
     178    c.add(new StatsEntry("Removed", cStats.getRemoveCount())); 
     179    c.add(new StatsEntry("Updated", cStats.getUpdateCount())); 
    192180  } 
    193    
    194   private static void secondLevelStats(Statistics dbStats, String name,  
    195                                        Logger log) { 
    196     log.debug(" ");  
    197     log.debug(lpad("Second level statistics for " + name , lcolw));  
    198     log.debug(" ");  
    199      
     181 
     182  private static void secondLevelStats(Collection c, Statistics dbStats, 
     183                                       String name) { 
     184    c.add(new StatsEntry("Second level statistics for " + name)); 
     185 
    200186    SecondLevelCacheStatistics slStats = dbStats.getSecondLevelCacheStatistics(name); 
    201187 
    202     log.debug(lpad("Elements in memory: " , lcolw) + slStats.getElementCountInMemory()); 
    203     log.debug(lpad("Element on disk: " , lcolw) + slStats.getElementCountOnDisk()); 
    204     log.debug(lpad("Entries: " , lcolw) + slStats.getEntries()); 
    205     log.debug(lpad("Hit count: " , lcolw) + slStats.getHitCount()); 
    206     log.debug(lpad("Miss count: " , lcolw) + slStats.getMissCount()); 
    207     log.debug(lpad("Put count: " , lcolw) + slStats.getPutCount()); 
    208     log.debug(lpad("Memory size: " , lcolw) + slStats.getSizeInMemory()); 
    209   } 
    210  
    211   private final static String padder = "                    " + 
    212                                        "                    " + 
    213                                        "                    " + 
    214                                        "                    "; 
    215    
    216   private final static int padderLen = padder.length(); 
    217    
    218   private static String lpad(String s, int len) { 
    219     int l = len - s.length(); 
    220      
    221     if (l > padderLen) { 
    222       return padder + s; 
    223     } 
    224      
    225     if (l < 0) { 
    226       return s; 
    227     } 
    228      
    229     return padder.substring(0, l) + s; 
     188    c.add(new StatsEntry("Elements in memory", slStats.getElementCountInMemory())); 
     189    c.add(new StatsEntry("Element on disk", slStats.getElementCountOnDisk())); 
     190    //c.add(new StatsEntry("Entries", slStats.getEntries())); 
     191    c.add(new StatsEntry("Hit count", slStats.getHitCount())); 
     192    c.add(new StatsEntry("Miss count", slStats.getMissCount())); 
     193    c.add(new StatsEntry("Put count", slStats.getPutCount())); 
     194    c.add(new StatsEntry("Memory size", slStats.getSizeInMemory())); 
    230195  } 
    231196} 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/BwRWStats.java

    r2 r191  
    8080    tzStores++; 
    8181  } 
     82 
     83  /** 
     84   * @param  val  double event fetch millis. 
     85   */ 
     86  public void incEventFetchTime(double val) { 
     87    eventFetchTime += val; 
     88  } 
     89 
     90  /** 
     91   * @param val   long event fetches. 
     92   */ 
     93  public void incEventFetches(long val) { 
     94    eventFetches += val; 
     95  } 
     96 
     97  /** 
     98   * @param val   number of utc values cached 
     99   */ 
     100  public void setDatesCached(long val) { 
     101    datesCached = val; 
     102  } 
     103 
     104  /** 
     105   * @param val    date cache hits 
     106   */ 
     107  public void setDateCacheHits(long val) { 
     108    dateCacheHits = val; 
     109  } 
     110 
     111  /** 
     112   * @param val   data cache misses. 
     113   */ 
     114  public void setDateCacheMisses(long val) { 
     115    dateCacheMisses = val; 
     116  } 
    82117} 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/BwStats.java

    r176 r191  
    5656 
    5757import java.io.Serializable; 
     58import java.util.Collection; 
     59import java.util.Iterator; 
     60import java.util.Vector; 
    5861 
    5962/** Some statistics for the Bedework calendar. These are not necessarily 
     
    6467 */ 
    6568public class BwStats implements Serializable { 
     69  /** Class to hold a statistics. We build a collection of these. 
     70   * We use Strings for values as these are going to be dumped as xml. 
     71   */ 
     72  public static class StatsEntry { 
     73    public final static int statKindHeader = 0; 
     74    public final static int statKindStat = 1; 
     75 
     76    private int statKind; 
     77 
     78    private String statLabel; 
     79 
     80    public final static int statTypeString = 0; 
     81    public final static int statTypeInt = 1; 
     82    public final static int statTypeLong = 2; 
     83    public final static int statTypeDouble = 3; 
     84    private int statType; 
     85 
     86    private String statVal; 
     87 
     88    public StatsEntry(String label, int val) { 
     89      statKind = statKindStat; 
     90      statLabel = label; 
     91      statType = statTypeInt; 
     92      statVal = String.valueOf(val); 
     93    } 
     94 
     95    public StatsEntry(String label, long val) { 
     96      statKind = statKindStat; 
     97      statLabel = label; 
     98      statType = statTypeLong; 
     99      statVal = String.valueOf(val); 
     100    } 
     101 
     102    public StatsEntry(String label, double val) { 
     103      statKind = statKindStat; 
     104      statLabel = label; 
     105      statType = statTypeDouble; 
     106      statVal = String.valueOf(val); 
     107    } 
     108 
     109    public StatsEntry(String label, String val) { 
     110      statKind = statKindStat; 
     111      statLabel = label; 
     112      statType = statTypeString; 
     113      statVal = val; 
     114    } 
     115 
     116    public StatsEntry(String header) { 
     117      statKind = statKindHeader; 
     118      statLabel = header; 
     119    } 
     120 
     121    public int getStatKind() { 
     122      return statKind; 
     123    } 
     124 
     125    public String getStatLabel() { 
     126      return statLabel; 
     127    } 
     128 
     129    public int getStatType() { 
     130      return statType; 
     131    } 
     132 
     133    public String getStatVal() { 
     134      return statVal; 
     135    } 
     136  } 
     137 
    66138  protected int tzFetches; 
    67139 
     
    69141 
    70142  protected int tzStores; 
    71    
     143 
    72144  protected double eventFetchTime; 
    73    
     145 
    74146  protected long eventFetches; 
     147 
     148  /* Timezone cache stats */ 
     149  protected long datesCached; 
     150  protected long dateCacheHits; 
     151  protected long dateCacheMisses; 
    75152 
    76153  /** 
     
    109186  } 
    110187 
     188  /** 
     189   * @return Number of utc values cached 
     190   */ 
     191  public long getDatesCached() { 
     192    return datesCached; 
     193  } 
     194 
     195  /** 
     196   * @return date cache hits 
     197   */ 
     198  public long getDateCacheHits() { 
     199    return dateCacheHits; 
     200  } 
     201 
     202  /** 
     203   * @return data cache misses. 
     204   */ 
     205  public long getDateCacheMisses() { 
     206    return dateCacheMisses; 
     207  } 
     208 
     209  public Collection getStats() { 
     210    Vector v = new Vector(); 
     211 
     212    v.add(new StatsEntry("Bedework statistics.")); 
     213    v.add(new StatsEntry("tzFetches", getTzFetches())); 
     214    v.add(new StatsEntry("systemTzFetches", getSystemTzFetches())); 
     215    v.add(new StatsEntry("tzStores", getTzStores())); 
     216 
     217    v.add(new StatsEntry("event fetch time", getEventFetchTime())); 
     218    v.add(new StatsEntry("event fetches", getEventFetches())); 
     219 
     220    v.add(new StatsEntry("UTC dates cached", getDatesCached())); 
     221    v.add(new StatsEntry("UTC date cache hits", getDateCacheHits())); 
     222    v.add(new StatsEntry("UTC date cache misses", getDateCacheMisses())); 
     223 
     224    return v; 
     225  } 
     226 
     227  /** Turn the Collection of StatsEntry into a String for dumps. 
     228   */ 
     229  public static String toString(Collection c) { 
     230    StringBuffer sb = new StringBuffer(); 
     231 
     232    Iterator it = c.iterator(); 
     233 
     234    while (it.hasNext()) { 
     235      StatsEntry se = (StatsEntry)it.next(); 
     236      int k = se.getStatKind(); 
     237 
     238      if (k == StatsEntry.statKindHeader) { 
     239        header(sb, se.getStatLabel()); 
     240      } else { 
     241        format(sb, se.getStatLabel(), se.getStatVal()); 
     242      } 
     243    } 
     244 
     245    return sb.toString(); 
     246  } 
     247 
    111248  public String toString() { 
    112     StringBuffer sb = new StringBuffer(); 
    113  
    114     sb.append("Bedework svc layer statistics.\n"); 
    115     format(sb, "tzFetches: ", getTzFetches()); 
    116     format(sb, "systemTzFetches: ", getSystemTzFetches()); 
    117     format(sb, "tzStores: ", getTzStores()); 
    118      
    119     format(sb, "event fetch time: ", getEventFetchTime()); 
    120     format(sb, "event fetches: ", getEventFetches()); 
    121  
    122     return sb.toString(); 
    123   } 
    124  
    125   private static final String padding = "                      "; 
     249    return toString(getStats()); 
     250  } 
     251 
     252  private final static String padder = "                    " + 
     253                                       "                    " + 
     254                                       "                    " + 
     255                                       "                    "; 
     256 
     257  private final static int padderLen = padder.length(); 
     258 
    126259  private static final int maxvalpad = 10; 
    127   private static final int maxnamepad = padding.length(); 
    128  
    129   private void pad(StringBuffer sb, String val, int padlen) { 
    130     int len = val.length(); 
    131  
    132     if (len <= padlen) { 
    133       sb.append(padding.substring(len)); 
     260 
     261  private static void pad(StringBuffer sb, String val, int padlen) { 
     262    int len = padlen - val.length(); 
     263 
     264    if (len > 0) { 
     265      sb.append(padder.substring(0, len)); 
    134266    } 
    135267 
     
    137269  } 
    138270 
    139   private void format(StringBuffer sb, String name, double val) { 
    140     pad(sb, name, maxnamepad); 
     271  private static void header(StringBuffer sb, String h) { 
     272    sb.append("\n"); 
     273    pad(sb, h, padderLen); 
     274    sb.append("\n"); 
     275  } 
     276 
     277  private static void format(StringBuffer sb, String name, String val) { 
     278    pad(sb, name, padderLen); 
    141279    sb.append(": "); 
    142     pad(sb, String.valueOf(val), maxvalpad); 
     280    pad(sb, val, maxvalpad); 
    143281    sb.append("\n"); 
    144282  } 
    145  
    146   private void format(StringBuffer sb, String name, int val) { 
    147     pad(sb, name, maxnamepad); 
    148     sb.append(": "); 
    149     pad(sb, String.valueOf(val), maxvalpad); 
    150     sb.append("\n"); 
    151   } 
    152283} 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/base/CalintfBase.java

    r176 r191  
    169169  } 
    170170 
    171   public void setStats(boolean enable) throws CalFacadeException { 
    172   } 
    173  
    174   public void dumpStats() throws CalFacadeException { 
     171  public void setDbStatsEnabled(boolean enable) throws CalFacadeException { 
     172  } 
     173 
     174  public boolean getDbStatsEnabled() throws CalFacadeException { 
     175    return false; 
     176  } 
     177 
     178  public void dumpDbStats() throws CalFacadeException { 
     179  } 
     180   
     181  public Collection getDbStats() throws CalFacadeException { 
     182    return null; 
    175183  } 
    176184 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/CalTimezones.java

    r185 r191  
    140140  /* Map of user TimezoneInfo */ 
    141141  protected HashMap timezones = new HashMap(); 
     142   
     143  /* Cache date only UTC values - we do a lot of those but the number of 
     144   * different dates should be limited. 
     145   *  
     146   * We have one cache per timezone 
     147   */ 
     148  private HashMap dateCaches = new HashMap(); 
     149 
     150  private HashMap defaultDateCache = new HashMap(); 
     151   
     152  private long datesCached; 
     153  private long dateCacheHits; 
     154  private long dateCacheMisses; 
    142155 
    143156  protected CalTimezones(boolean debug) { 
     
    230243  public abstract VTimeZone findTimeZone(final String id, BwUser owner) throws CalFacadeException; 
    231244   
    232   /** Clear all public timezone objects 
     245  /** Clear all public timezone objects. Implementing classes should call this. 
    233246   * 
    234247   * <p>Will remove all public timezones in preparation for a replacement 
     
    237250   * @throws CalFacadeException 
    238251   */ 
    239   public abstract void clearPublicTimezones() throws CalFacadeException; 
     252  public void clearPublicTimezones() throws CalFacadeException { 
     253    dateCaches.clear(); 
     254    defaultDateCache.clear(); 
     255  } 
    240256   
    241257  /** Refresh the public timezone table - presumably after a call to clearPublicTimezones. 
     
    291307      return time; 
    292308    } 
     309 
     310    String dateKey = null; 
     311    HashMap cache = null; 
    293312     
    294313    if (CalFacadeUtil.isISODate(time)) { 
     314      /* See if we have it cached */ 
     315       
     316      if (tzid == null) { 
     317        cache = defaultDateCache; 
     318      } else if (tzid.equals(getDefaultTimeZoneId())) { 
     319        cache = defaultDateCache; 
     320      } else { 
     321        cache = (HashMap)dateCaches.get(tzid); 
     322        if (cache == null) { 
     323          cache = new HashMap(); 
     324          dateCaches.put(tzid, cache); 
     325        } 
     326      } 
     327       
     328      String utc = (String)cache.get(time); 
     329       
     330      if (utc != null) { 
     331        dateCacheHits++; 
     332        return utc; 
     333      } 
     334 
     335      /* Not in the cache - calculate it */ 
     336       
     337      dateCacheMisses++; 
     338      dateKey = time; 
    295339      time += "T000000"; 
    296340    } else if (!CalFacadeUtil.isISODateTime(time)) { 
     
    364408      digit2(sb, cal.get(Calendar.SECOND)); 
    365409      sb.append('Z'); 
    366       return sb.toString(); 
     410       
     411      String utc = sb.toString(); 
     412       
     413      if (dateKey != null) { 
     414        cache.put(dateKey, utc); 
     415        datesCached++; 
     416      } 
     417       
     418      return utc; 
    367419    } catch (Throwable t) { 
    368420      t.printStackTrace(); 
     
    371423  } 
    372424   
     425  /** 
     426   * @return Number of utc values cached 
     427   */ 
     428  public long getDatesCached() { 
     429    return datesCached; 
     430  } 
     431   
     432  /** 
     433   * @return date cache hits 
     434   */ 
     435  public long getDateCacheHits() { 
     436    return dateCacheHits; 
     437  } 
     438   
     439  /** 
     440   * @return data cache misses. 
     441   */ 
     442  public long getDateCacheMisses() { 
     443    return dateCacheMisses; 
     444  } 
     445     
    373446  /* ==================================================================== 
    374447   *                   protected methods 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/Calintf.java

    r176 r191  
    126126   * @throws CalFacadeException if not admin 
    127127   */ 
    128   public void setStats(boolean enable) throws CalFacadeException; 
     128  public void setDbStatsEnabled(boolean enable) throws CalFacadeException; 
     129 
     130  /**   
     131   * 
     132   * @return boolean true if statistics collection enabled 
     133   * @throws CalFacadeException if not admin 
     134   */ 
     135  public boolean getDbStatsEnabled() throws CalFacadeException; 
    129136 
    130137  /** Dump db statistics  
     
    132139   * @throws CalFacadeException if not admin 
    133140   */ 
    134   public void dumpStats() throws CalFacadeException; 
     141  public void dumpDbStats() throws CalFacadeException; 
     142 
     143  /** Get db statistics  
     144   * 
     145   * @return Collection of BwStats.StatsEntry objects 
     146   * @throws CalFacadeException if not admin 
     147   */ 
     148  public Collection getDbStats() throws CalFacadeException; 
    135149 
    136150  /** Get the system pars 
  • trunk/calendar3/calsvc/src/org/bedework/calsvc/CalSvc.java

    r177 r191  
    325325 
    326326  public BwStats getStats() throws CalFacadeException { 
    327     //if (!pars.getPublicAdmin()) { 
    328     //  throw new CalFacadeAccessException(); 
    329     //
     327    if (!pars.getPublicAdmin()) { 
     328      throw new CalFacadeAccessException(); 
     329   
    330330 
    331331    return getCal().getStats(); 
    332332  } 
    333333 
    334   public void setStats(boolean enable) throws CalFacadeException { 
    335     //if (!pars.getPublicAdmin()) { 
    336     //  throw new CalFacadeAccessException(); 
    337     //} 
    338  
    339     getCal().setStats(enable); 
    340   } 
    341  
    342   public void dumpStats() throws CalFacadeException { 
    343     //if (!pars.getPublicAdmin()) { 
    344     //  throw new CalFacadeAccessException(); 
    345     //} 
     334  public void setDbStatsEnabled(boolean enable) throws CalFacadeException { 
     335    if (!pars.getPublicAdmin()) { 
     336      throw new CalFacadeAccessException(); 
     337    } 
     338 
     339    getCal().setDbStatsEnabled(enable); 
     340  } 
     341 
     342  public boolean getDbStatsEnabled() throws CalFacadeException { 
     343    return getCal().getDbStatsEnabled(); 
     344  } 
     345   
     346  public void dumpDbStats() throws CalFacadeException { 
     347    if (!pars.getPublicAdmin()) { 
     348      throw new CalFacadeAccessException(); 
     349    } 
    346350     
    347351    trace(getStats().toString()); 
    348     getCal().dumpStats(); 
     352    getCal().dumpDbStats(); 
     353  } 
     354   
     355  public Collection getDbStats() throws CalFacadeException { 
     356    if (!pars.getPublicAdmin()) { 
     357      throw new CalFacadeAccessException(); 
     358    } 
     359     
     360    return getCal().getDbStats(); 
    349361  } 
    350362 
  • trunk/calendar3/calsvci/src/org/bedework/calsvci/CalSvcI.java

    r176 r191  
    119119   * @throws CalFacadeException if not admin 
    120120   */ 
    121   public abstract void setStats(boolean enable) throws CalFacadeException; 
     121  public abstract void setDbStatsEnabled(boolean enable) throws CalFacadeException; 
     122 
     123  /**   
     124   * 
     125   * @return boolean true if statistics collection enabled 
     126   * @throws CalFacadeException if not admin 
     127   */ 
     128  public abstract boolean getDbStatsEnabled() throws CalFacadeException; 
    122129 
    123130  /** Dump db statistics  
     
    125132   * @throws CalFacadeException if not admin 
    126133   */ 
    127   public abstract void dumpStats() throws CalFacadeException; 
     134  public abstract void dumpDbStats() throws CalFacadeException; 
     135 
     136  /** Get db statistics  
     137   * 
     138   * @return Collection of BwStats.StatsEntry objects 
     139   * @throws CalFacadeException if not admin 
     140   */ 
     141  public abstract Collection getDbStats() throws CalFacadeException; 
    128142 
    129143  /** Get the system pars 
  • trunk/calendar3/dumprestore/src/org/bedework/dumprestore/restore/TimezonesImpl.java

    r171 r191  
    190190  } 
    191191 
    192   public void clearPublicTimezones() throws CalFacadeException { 
    193   } 
    194  
    195192  public void refreshTimezones() throws CalFacadeException { 
    196193    synchronized (this) { 
  • trunk/calendar3/webadmin/war/WEB-INF/struts-config.xml

    r190 r191  
    947947      <forward name="continue"  path="/admingroup/showChooseGroup.rdo" redirect="true" /> 
    948948    </action> 
     949 
     950    <!-- =============================================================== 
     951                     Stats Actions 
     952         =============================================================== --> 
     953 
     954    <action    path="/stats/show" 
     955               type="org.bedework.webadmin.PERenderAction" 
     956               name="peForm" 
     957               scope="session" 
     958               validate="false"> 
     959      <forward name="success" path="/docs/system/showSysStats.jsp" /> 
     960    </action> 
     961 
     962    <action    path="/stats/update" 
     963               type="org.bedework.webcommon.misc.StatisticsAction" 
     964               name="peForm" 
     965               scope="session" 
     966               validate="false"> 
     967      <forward name="continue"  path="/stats/show.rdo" redirect="true" /> 
     968      <forward name="success"  path="/stats/show.rdo" redirect="true" /> 
     969    </action> 
    949970  </action-mappings> 
    950971 
  • trunk/calendar3/webcommon/src/org/bedework/webcommon/BwActionFormBase.java

    r145 r191  
    108108  private BwSystem syspars; 
    109109 
     110  private Collection sysStats; 
     111   
    110112  private transient MailerIntf mailer; 
    111113 
     
    395397    return syspars; 
    396398  } 
    397  
     399   
     400  /** Set system statistics  
     401  * 
     402  * @param val      Collection of BwStats.StatsEntry objects 
     403  */ 
     404  public void assignSysStats(Collection val) { 
     405    sysStats = val; 
     406  } 
     407 
     408  /** Get system statistics  
     409  * 
     410  * @return Collection of BwStats.StatsEntry objects 
     411  */ 
     412  public Collection getSysStats() { 
     413    if (sysStats == null) { 
     414      sysStats = new Vector(); 
     415    } 
     416     
     417    return sysStats; 
     418  } 
     419 
     420  /** Get system statistics enabled state  
     421  * 
     422   * @return boolean true if statistics collection enabled 
     423  */ 
     424  public boolean getSysStatsEnabled() { 
     425    try { 
     426      return fetchSvci().getDbStatsEnabled(); 
     427    } catch (Throwable t) { 
     428      return false; 
     429    } 
     430  } 
     431   
    398432  /** This will default to the current user. Superusers will be able to 
    399433   * specify a creator. 
  • trunk/calendar3/webcommon/src/org/bedework/webcommon/misc/StatisticsAction.java

    r176 r191  
    5555package org.bedework.webcommon.misc; 
    5656 
     57import java.util.Collection; 
     58 
     59import org.bedework.calfacade.BwStats; 
    5760import org.bedework.calsvci.CalSvcI; 
    5861import org.bedework.webcommon.BwAbstractAction; 
     
    7073 *      <li>"disable"           Disable stats</li> 
    7174 *      <li>"dump"              Dump stats</li> 
     75 *      <li>"fetch"             fetch stats</li> 
    7276 * </ul> 
    7377 * 
     
    9094 
    9195    if (getReqPar(request, "enable") != null) { 
    92       svci.setStats(true); 
     96      svci.setDbStatsEnabled(true); 
    9397    } else if (getReqPar(request, "disable") != null) { 
    94       svci.setStats(false); 
     98      svci.setDbStatsEnabled(false); 
    9599    } else if (getReqPar(request, "dump") != null) { 
    96       svci.dumpStats(); 
     100      svci.dumpDbStats(); 
     101    } else if (getReqPar(request, "fetch") != null) { 
     102      BwStats stats = svci.getStats(); 
     103       
     104      Collection c = stats.getStats(); 
     105       
     106      c.addAll(svci.getDbStats()); 
     107       
     108      form.assignSysStats(c); 
     109 
     110      return "continue"; 
    97111    }  
    98112