changeset 1227:35e021959906

merge with main
author Franz Pletz <fpletz AT franz-pletz DOT org>
date Sun, 06 Aug 2006 18:55:31 +0200
parents 9b101f696445 (current diff) 67044a2a0224 (diff)
children b648187eac6c
files
diffstat 2 files changed, 42 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/i18n/__init__.py	Sun Aug 06 16:58:41 2006 +0200
+++ b/MoinMoin/i18n/__init__.py	Sun Aug 06 18:55:31 2006 +0200
@@ -61,10 +61,11 @@
         The very first time, this will be slow as it will load all languages,
         but next time it will be fast due to caching.
     """
+    request.clock.start('i18n_init')
     global languages
     if languages is None:
         meta_cache = caching.CacheEntry(request, 'i18n', 'meta', scope='farm')
-        i18n_dir = os.path.join(request.cfg.moinmoin_dir, 'i18n', 'mo')
+        i18n_dir = os.path.join(request.cfg.moinmoin_dir, 'i18n')
         if meta_cache.needsUpdate(i18n_dir):
             _languages = {}
             for lang_file in glob.glob(po_filename(request, language='*', domain='MoinMoin')): # only MoinMoin domain for now XXX
@@ -85,6 +86,7 @@
         _languages = pickle.loads(meta_cache.content())
         if languages is None:
             languages = _languages
+    request.clock.stop('i18n_init')
 
 
 class Translation(object):
@@ -162,6 +164,7 @@
         return text
 
     def loadLanguage(self, request):
+        request.clock.start('loadLanguage')
         cache = caching.CacheEntry(request, arena='i18n', key=self.language, scope='farm')
         langfilename = po_filename(request, self.language, self.domain)
         needsupdate = cache.needsUpdate(langfilename)
@@ -203,6 +206,7 @@
 
         self.formatted = uc_texts
         self.raw = uc_unformatted
+        request.clock.stop('loadLanguage')
 
 
 def getDirection(lang):
--- a/MoinMoin/request/__init__.py	Sun Aug 06 16:58:41 2006 +0200
+++ b/MoinMoin/request/__init__.py	Sun Aug 06 18:55:31 2006 +0200
@@ -31,21 +31,46 @@
     """
 
     def __init__(self):
-        self.timings = {'total': time.time()}
+        self.timings = {}
+        self.states = {}
 
     def start(self, timer):
-        self.timings[timer] = time.time() - self.timings.get(timer, 0)
+        state = self.states.setdefault(timer, 'new')
+        if state == 'new':
+            self.timings[timer] = time.time()
+            self.states[timer] = 'running'
+        elif state == 'running':
+            pass # this timer is already running, do nothing
+        elif state == 'stopped':
+            # if a timer is stopped, timings has the sum of all times it was running
+            self.timings[timer] = time.time() - self.timings[timer]
+            self.states[timer] = 'running'
 
     def stop(self, timer):
-        self.timings[timer] = time.time() - self.timings[timer]
+        state = self.states.setdefault(timer, 'neverstarted')
+        if state == 'running':
+            self.timings[timer] = time.time() - self.timings[timer]
+            self.states[timer] = 'stopped'
+        elif state == 'stopped':
+            pass # this timer already has been stopped, do nothing
+        elif state == 'neverstarted':
+            pass # this timer never has been started, do nothing
 
     def value(self, timer):
-        return "%.3f" % (self.timings[timer], )
+        state = self.states.setdefault(timer, 'nosuchtimer')
+        if state == 'stopped':
+            result = "%.3fs" % self.timings[timer]
+        elif state == 'running':
+            result = "%.3fs (still running)" % (time.time() - self.timings[timer])
+        else:
+            result = "- (%s)" % state
+        return result
 
     def dump(self):
         outlist = []
-        for timing in self.timings.items():
-            outlist.append("%s = %.3fs" % timing)
+        for timer in self.timings.keys():
+            value = self.value(timer)
+            outlist.append("%s = %s" % (timer, value))
         outlist.sort()
         return outlist
 
@@ -118,6 +143,8 @@
         else:
             self.writestack = []
             self.clock = Clock()
+            self.clock.start('total')
+            self.clock.start('base__init__')
             # order is important here!
             self.__dict__.update(properties)
             self._load_multi_cfg()
@@ -154,7 +181,7 @@
 
             rootname = u''
             self.rootpage = Page(self, rootname, is_rootpage=1)
-
+            
             from MoinMoin import i18n
             self.i18n = i18n
             i18n.i18n_init(self)
@@ -179,6 +206,7 @@
 
             self.opened_logs = 0
             self.reset()
+            self.clock.stop('base__init__')
 
     def surge_protect(self):
         """ check if someone requesting too much from us """
@@ -268,8 +296,10 @@
     def _load_multi_cfg(self):
         # protect against calling multiple times
         if not hasattr(self, 'cfg'):
+            self.clock.start('load_multi_cfg')
             from MoinMoin.config import multiconfig
             self.cfg = multiconfig.getConfig(self.url)
+            self.clock.stop('load_multi_cfg')
 
     def setAcceptedCharsets(self, accept_charset):
         """ Set accepted_charsets by parsing accept-charset header