Skip to content

Commit 00b18b5

Browse files
author
Richard Jones
committed
added capturing of stats
1 parent 7d81678 commit 00b18b5

File tree

6 files changed

+67
-10
lines changed

6 files changed

+67
-10
lines changed

BUILD.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ running:
2121
7. python setup.py sdist
2222
(if you find sdist a little verbose, add "--quiet" to the end of the
2323
command)
24-
8. unpack the new dist file in /tmp then a) run_test.py and b) demo.py
24+
8. unpack the new dist file in /tmp then a) run_test.py and b) demo.py
2525
with all available Python versions.
26+
9. python setup.py bdist_rpm
27+
10. python setup.py bdist_wininst
2628

2729
So, those commands in a nice, cut'n'pasteable form::
2830

2931
python setup.py clean --all
3032
python setup.py sdist --manifest-only
3133
python setup.py sdist --quiet
34+
python setup.py bdist_rpm
35+
python setup.py bdist_wininst
3236
python2.3 setup.py register
3337

3438

roundup/backends/back_anydbm.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.141 2004-04-07 01:12:25 richard Exp $
18+
#$Id: back_anydbm.py,v 1.142 2004-04-25 22:19:15 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in a
2020
database chosen by anydbm. It is guaranteed to always be available in python
2121
versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several
@@ -33,7 +33,7 @@
3333
except AssertionError:
3434
print "WARNING: you should upgrade to python 2.1.3"
3535

36-
import whichdb, os, marshal, re, weakref, string, copy
36+
import whichdb, os, marshal, re, weakref, string, copy, time
3737
from roundup import hyperdb, date, password, roundupdb, security
3838
from blobfiles import FileStorage
3939
from sessions_dbm import Sessions, OneTimeKeys
@@ -74,6 +74,8 @@ def __init__(self, config, journaltag=None):
7474
self.dir = config.DATABASE
7575
self.classes = {}
7676
self.cache = {} # cache of nodes loaded or created
77+
self.stats = {'cache_hits': 0, 'cache_misses': 0, 'get_items': 0,
78+
'filtering': 0}
7779
self.dirtynodes = {} # keep track of the dirty nodes by class
7880
self.newnodes = {} # keep track of the new nodes by class
7981
self.destroyednodes = {}# keep track of the destroyed nodes by class
@@ -314,9 +316,12 @@ def getnode(self, classname, nodeid, db=None, cache=1):
314316
if __debug__:
315317
print >>hyperdb.TRACE, 'get %s %s cached'%(classname,
316318
nodeid)
319+
self.stats['cache_hits'] += 1
317320
return cache_dict[nodeid]
318321

319322
if __debug__:
323+
self.stats['cache_misses'] += 1
324+
start_t = time.time()
320325
print >>hyperdb.TRACE, 'get %s %s'%(classname, nodeid)
321326

322327
# get from the database and save in the cache
@@ -340,6 +345,9 @@ def getnode(self, classname, nodeid, db=None, cache=1):
340345
if cache:
341346
cache_dict[nodeid] = res
342347

348+
if __debug__:
349+
self.stats['get_items'] += (time.time() - start_t)
350+
343351
return res
344352

345353
def destroynode(self, classname, nodeid):
@@ -1579,6 +1587,9 @@ def filter(self, search_matches, filterspec, sort=(None,None),
15791587
is a Multilink, in which case the item's property list must
15801588
match the filterspec list.
15811589
"""
1590+
if __debug__:
1591+
start_t = time.time()
1592+
15821593
cn = self.classname
15831594

15841595
# optimise filterspec
@@ -1826,7 +1837,10 @@ def sortfun(a, b, sort=sort, group=group, properties=self.getprops(),
18261837
return cmp(a[0], b[0])
18271838

18281839
l.sort(sortfun)
1829-
return [i[0] for i in l]
1840+
l = [i[0] for i in l]
1841+
if __debug__:
1842+
self.db.stats['filtering'] += (time.time() - start_t)
1843+
return l
18301844

18311845
def count(self):
18321846
'''Get the number of nodes in this class.

roundup/backends/back_mysql.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ def filter(self, search_matches, filterspec, sort=(None,None),
507507
if search_matches == {}:
508508
return []
509509

510+
if __debug__:
511+
start_t = time.time()
512+
510513
cn = self.classname
511514

512515
timezone = self.db.getUserTimezone()
@@ -687,6 +690,8 @@ def filter(self, search_matches, filterspec, sort=(None,None),
687690
l = [str(row[0]) for row in l]
688691

689692
if not mlsort:
693+
if __debug__:
694+
self.db.stats['filtering'] += (time.time() - start_t)
690695
return l
691696

692697
# ergh. someone wants to sort by a multilink.
@@ -705,7 +710,12 @@ def sortfun(a, b, dir=sortby[i], i=i):
705710
return cmp(a[1][i], b[1][i])
706711
r.sort(sortfun)
707712
i += 1
708-
return [i[0] for i in r]
713+
r = [i[0] for i in r]
714+
715+
if __debug__:
716+
self.db.stats['filtering'] += (time.time() - start_t)
717+
718+
return r
709719

710720
class Class(MysqlClass, rdbms_common.Class):
711721
pass

roundup/backends/rdbms_common.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.93 2004-04-22 22:17:34 richard Exp $
1+
# $Id: rdbms_common.py,v 1.94 2004-04-25 22:19:15 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -76,6 +76,8 @@ def __init__(self, config, journaltag=None):
7676
# (classname, nodeid) = row
7777
self.cache = {}
7878
self.cache_lru = []
79+
self.stats = {'cache_hits': 0, 'cache_misses': 0, 'get_items': 0,
80+
'filtering': 0}
7981

8082
# database lock
8183
self.lockfile = None
@@ -831,9 +833,15 @@ def getnode(self, classname, nodeid):
831833
# push us back to the top of the LRU
832834
self.cache_lru.remove(key)
833835
self.cache_lru.insert(0, key)
836+
if __debug__:
837+
self.stats['cache_hits'] += 1
834838
# return the cached information
835839
return self.cache[key]
836840

841+
if __debug__:
842+
self.stats['cache_misses'] += 1
843+
start_t = time.time()
844+
837845
# figure the columns we're fetching
838846
cl = self.classes[classname]
839847
cols, mls = self.determine_columns(cl.properties.items())
@@ -880,6 +888,9 @@ def getnode(self, classname, nodeid):
880888
if len(self.cache_lru) > ROW_CACHE_SIZE:
881889
del self.cache[self.cache_lru.pop()]
882890

891+
if __debug__:
892+
self.stats['get_items'] += (time.time() - start_t)
893+
883894
return node
884895

885896
def destroynode(self, classname, nodeid):
@@ -1938,6 +1949,9 @@ def filter(self, search_matches, filterspec, sort=(None,None),
19381949
if search_matches == {}:
19391950
return []
19401951

1952+
if __debug__:
1953+
start_t = time.time()
1954+
19411955
cn = self.classname
19421956

19431957
timezone = self.db.getUserTimezone()
@@ -2116,6 +2130,8 @@ def filter(self, search_matches, filterspec, sort=(None,None),
21162130
l = [str(row[0]) for row in l]
21172131

21182132
if not mlsort:
2133+
if __debug__:
2134+
self.db.stats['filtering'] += (time.time() - start_t)
21192135
return l
21202136

21212137
# ergh. someone wants to sort by a multilink.
@@ -2134,7 +2150,12 @@ def sortfun(a, b, dir=sortby[i], i=i):
21342150
return cmp(a[1][i], b[1][i])
21352151
r.sort(sortfun)
21362152
i += 1
2137-
return [i[0] for i in r]
2153+
r = [i[0] for i in r]
2154+
2155+
if __debug__:
2156+
self.db.stats['filtering'] += (time.time() - start_t)
2157+
2158+
return r
21382159

21392160
def count(self):
21402161
'''Get the number of nodes in this class.

roundup/cgi/client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.172 2004-04-22 22:16:36 richard Exp $
1+
# $Id: client.py,v 1.173 2004-04-25 22:19:15 richard Exp $
22

33
"""WWW request handler (also used in the stand-alone server).
44
"""
@@ -519,7 +519,14 @@ def renderContext(self):
519519
result = pt.render(self, None, None, **args)
520520
self.additional_headers['Content-Type'] = pt.content_type
521521
if os.environ.get('CGI_SHOW_TIMING', ''):
522-
s = '<p>Time elapsed: %fs</p></body>'%(time.time()-self.start)
522+
s = '<p>Time elapsed: %fs</p>'%(time.time()-self.start)
523+
if hasattr(self.db, 'stats'):
524+
s += '''<p>Cache hits: %(cache_hits)d,
525+
misses %(cache_misses)d.
526+
Loading items: %(get_items)f secs.
527+
Filtering: %(filtering)f secs.
528+
</p>'''%self.db.stats
529+
s += '</body>'
523530
result = result.replace('</body>', s)
524531
return result
525532
except templating.NoTemplate, message:

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: setup.py,v 1.62 2004-04-18 06:21:20 richard Exp $
19+
# $Id: setup.py,v 1.63 2004-04-25 22:19:14 richard Exp $
2020

2121
from distutils.core import setup, Extension
2222
from distutils.util import get_platform
@@ -147,6 +147,7 @@ def check_manifest():
147147
n = len(manifest)
148148
print '\n*** SOURCE ERROR: There are files missing (%d/%d found)!'%(
149149
n-len(err), n)
150+
print 'Missing:', '\nMissing: '.join(err)
150151
sys.exit(1)
151152

152153

0 commit comments

Comments
 (0)