diff roundup/backends/rdbms_common.py @ 2237:f624fc20f8fe

added capturing of stats
author Richard Jones <richard@users.sourceforge.net>
date Sun, 25 Apr 2004 22:19:15 +0000
parents 70d21059aa18
children ad4b717e12b9
line wrap: on
line diff
--- a/roundup/backends/rdbms_common.py	Sat Apr 24 22:59:12 2004 +0000
+++ b/roundup/backends/rdbms_common.py	Sun Apr 25 22:19:15 2004 +0000
@@ -1,4 +1,4 @@
-# $Id: rdbms_common.py,v 1.93 2004-04-22 22:17:34 richard Exp $
+# $Id: rdbms_common.py,v 1.94 2004-04-25 22:19:15 richard Exp $
 ''' Relational database (SQL) backend common code.
 
 Basics:
@@ -76,6 +76,8 @@
         # (classname, nodeid) = row
         self.cache = {}
         self.cache_lru = []
+        self.stats = {'cache_hits': 0, 'cache_misses': 0, 'get_items': 0,
+            'filtering': 0}
 
         # database lock
         self.lockfile = None
@@ -831,9 +833,15 @@
             # push us back to the top of the LRU
             self.cache_lru.remove(key)
             self.cache_lru.insert(0, key)
+            if __debug__:
+                self.stats['cache_hits'] += 1
             # return the cached information
             return self.cache[key]
 
+        if __debug__:
+            self.stats['cache_misses'] += 1
+            start_t = time.time()
+
         # figure the columns we're fetching
         cl = self.classes[classname]
         cols, mls = self.determine_columns(cl.properties.items())
@@ -880,6 +888,9 @@
         if len(self.cache_lru) > ROW_CACHE_SIZE:
             del self.cache[self.cache_lru.pop()]
 
+        if __debug__:
+            self.stats['get_items'] += (time.time() - start_t)
+
         return node
 
     def destroynode(self, classname, nodeid):
@@ -1938,6 +1949,9 @@
         if search_matches == {}:
             return []
 
+        if __debug__:
+            start_t = time.time()
+
         cn = self.classname
 
         timezone = self.db.getUserTimezone()
@@ -2116,6 +2130,8 @@
         l = [str(row[0]) for row in l]
 
         if not mlsort:
+            if __debug__:
+                self.db.stats['filtering'] += (time.time() - start_t)
             return l
 
         # ergh. someone wants to sort by a multilink.
@@ -2134,7 +2150,12 @@
                     return cmp(a[1][i], b[1][i])
             r.sort(sortfun)
             i += 1
-        return [i[0] for i in r]
+        r = [i[0] for i in r]
+
+        if __debug__:
+            self.db.stats['filtering'] += (time.time() - start_t)
+
+        return r
 
     def count(self):
         '''Get the number of nodes in this class.

Roundup Issue Tracker: http://roundup-tracker.org/