comparison src/org/dancres/blitz/stats/StoreStat.java @ 22:b7e52953b7a6

Add some cache/memory statistics to help spot potential exhaustion and other tuning issues.
author Dan Creswell <dan.creswell@gmail.com>
date Fri, 28 Aug 2009 17:23:33 +0100
parents src/org/dancres/blitz/stats/SearchStat.java@3dc0c5604566
children
comparison
equal deleted inserted replaced
21:8417eaebf5ab 22:b7e52953b7a6
1 package org.dancres.blitz.stats;
2
3 /**
4 */
5 public class StoreStat implements Stat {
6 private static final long _minimalFree;
7
8 private long _id;
9 private String _type;
10 private String[] _titles;
11 private long[] _missed;
12 private long[] _deleted;
13 private boolean _safe;
14
15 private int _activeCache;
16 private int _totalCache;
17 private long _free;
18 private long _max;
19
20 static {
21 _minimalFree = Runtime.getRuntime().maxMemory() / 5;
22 }
23
24 public StoreStat(long anId, String aType,
25 String[] aTitles,
26 long[] aMisses, long[] aDeld, int anActiveCacheSize, int aCacheSize) {
27 _id = anId;
28 _type = aType;
29 _titles = aTitles;
30 _missed = aMisses;
31 _deleted = aDeld;
32
33 _activeCache = anActiveCacheSize;
34 _totalCache = aCacheSize;
35 _free = Runtime.getRuntime().freeMemory();
36 _max = Runtime.getRuntime().maxMemory();
37
38 _safe = (anActiveCacheSize == aCacheSize) &&
39 (Runtime.getRuntime().freeMemory() >= _minimalFree);
40 }
41
42 public long getId() {
43 return _id;
44 }
45
46 public String toString() {
47 StringBuffer myBuffer = new StringBuffer("Store: " + _type);
48
49 for (int i = 0; i < _titles.length; i++) {
50 myBuffer.append(" ");
51 myBuffer.append(_titles[i]);
52 myBuffer.append(" miss: ");
53 myBuffer.append(_missed[i]);
54 myBuffer.append(" deld: ");
55 myBuffer.append(_deleted[i]);
56 }
57
58 myBuffer.append(" sustainable: ");
59 myBuffer.append(_safe);
60 myBuffer.append(" (" + _activeCache + ", " + _totalCache + ", " + _free + ", " + _max + ")");
61
62 return myBuffer.toString();
63 }
64 }