[Zodb-checkins] CVS: ZODB3/ZEO - stats.py:1.8
Guido van Rossum
guido@python.org
Thu, 5 Sep 2002 13:56:44 -0400
Update of /cvs-repository/ZODB3/ZEO
In directory cvs.zope.org:/tmp/cvs-serv15931
Modified Files:
stats.py
Log Message:
Report hit rate for load requests.
=== ZODB3/ZEO/stats.py 1.7 => 1.8 ===
--- ZODB3/ZEO/stats.py:1.7 Wed Sep 4 13:59:52 2002
+++ ZODB3/ZEO/stats.py Thu Sep 5 13:56:44 2002
@@ -148,6 +148,7 @@
addcommas(datarecords),
100.0 * datarecords / records,
datasize / 1024.0 / datarecords)
+ print "Hit rate: %.1f%% (load hits / loads)" % hitrate(bycode)
print
codes = bycode.keys()
codes.sort()
@@ -157,6 +158,20 @@
addcommas(bycode.get(code, 0)),
code,
explain.get(code) or "*** unknown code ***")
+
+def hitrate(bycode):
+ loads = 0
+ hits = 0
+ for code in bycode.keys():
+ if code & 0x70 == 0x20:
+ n = bycode[code]
+ loads += n
+ if code in (0x2A, 0x2C, 0x2E):
+ hits += n
+ if loads:
+ return 100.0 * hits / loads
+ else:
+ return 0.0
def U64(s):
h, v = struct.unpack(">II", s)