[Zope-Checkins] CVS: ZODB3/ZEO - stats.py:1.17.6.1.18.1

Jeremy Hylton cvs-admin at zope.org
Wed Nov 26 12:49:09 EST 2003


Update of /cvs-repository/ZODB3/ZEO
In directory cvs.zope.org:/tmp/cvs-serv27452

Modified Files:
      Tag: Zope-2_6-branch
	stats.py 
Log Message:
Add code to compute and display temporal distance.


=== ZODB3/ZEO/stats.py 1.17.6.1 => 1.17.6.1.18.1 ===
--- ZODB3/ZEO/stats.py:1.17.6.1	Wed Oct 16 17:45:59 2002
+++ ZODB3/ZEO/stats.py	Wed Nov 26 12:49:08 2003
@@ -66,6 +66,7 @@
     dostats = 1
     print_size_histogram = 0
     print_histogram = 0
+    print_distance = 1
     interval = 900 # Every 15 minutes
     try:
         opts, args = getopt.getopt(sys.argv[1:], "hi:qsSv")
@@ -133,6 +134,7 @@
     bysizew = {}
     total_loads = 0
     byinterval = {}
+    refs = {}
     thisinterval = None
     h0 = he = None
     offset = 0
@@ -203,6 +205,7 @@
             if code & 0x70 == 0x20:
                 oids[oid] = oids.get(oid, 0) + 1
                 total_loads += 1
+                refs.setdefault(oid, []).append(datarecords)
             if code in (0x00, 0x70):
                 if not quiet:
                     dumpbyinterval(byinterval, h0, he)
@@ -281,6 +284,47 @@
         print
         dumpbysize(bysizew, "written", "writes")
         dumpbysize(bysize, "loaded", "loads")
+
+    # Compute temporal distance and display histogram
+    if print_distance:
+        dist = {}
+        repeats = 0
+        rest = 0
+        for oid, L in refs.items():
+            if len(L) < 2:
+                rest += 1
+                continue
+            repeats += 1
+            distances = [v - L[i-1] for i, v in enumerate(L) if i >= 1]
+            for d in distances:
+                dist[d] = dist.get(d, 0) + 1
+
+        binsize = 100
+        bins = dict.fromkeys(range(0, max(dist), binsize), 0)
+        for d, count in dist.items():
+            bins[d / binsize * binsize] += count
+        L = bins.items()
+        L.sort()
+            
+        print
+        print "Histogram of temporal distance"
+        all = sum(dist.values())
+        print "Total oids with 1 load: %s" % addcommas(rest)
+        print "Total oids with 2 or more loads: %s" % addcommas(repeats)
+        headers = ["Dist", "Count", "Percent"]
+        fmt = "%5s %7s %3s"
+        print fmt % tuple(headers)
+        dots = False
+        for i, (dist, count) in enumerate(L):
+            if not count and dots:
+                continue
+            if not (count or L[i+1][1]):
+                if not dots:
+                    print "..."
+                dots = True
+                continue
+            dots = False
+            print fmt % (dist, count, 100 * count / all)
 
 def dumpbysize(bysize, how, how2):
     print




More information about the Zope-Checkins mailing list