[Checkins] SVN: z3ext.profiler/trunk/s separate profilers for portlets, pageelements

Nikolay Kim fafhrd91 at gmail.com
Sun Aug 16 10:41:37 EDT 2009


Log message for revision 102856:
  separate profilers for portlets,pageelements

Changed:
  U   z3ext.profiler/trunk/setup.py
  U   z3ext.profiler/trunk/src/z3ext/profiler/DMstats.py
  U   z3ext.profiler/trunk/src/z3ext/profiler/configlet.py
  U   z3ext.profiler/trunk/src/z3ext/profiler/configure.zcml
  U   z3ext.profiler/trunk/src/z3ext/profiler/interfaces.py
  A   z3ext.profiler/trunk/src/z3ext/profiler/pageelement.py
  U   z3ext.profiler/trunk/src/z3ext/profiler/pagelet.py
  U   z3ext.profiler/trunk/src/z3ext/profiler/portlet.py
  U   z3ext.profiler/trunk/src/z3ext/profiler/profiler.py
  U   z3ext.profiler/trunk/src/z3ext/profiler/stats.py
  A   z3ext.profiler/trunk/src/z3ext/profiler/timelog.py
  U   z3ext.profiler/trunk/src/z3ext/profiler/view.py

-=-
Modified: z3ext.profiler/trunk/setup.py
===================================================================
--- z3ext.profiler/trunk/setup.py	2009-08-16 14:23:32 UTC (rev 102855)
+++ z3ext.profiler/trunk/setup.py	2009-08-16 14:41:36 UTC (rev 102856)
@@ -46,12 +46,12 @@
       package_dir = {'':'src'},
       namespace_packages=['z3ext'],
       install_requires = ['setuptools',
-    		          'zope.interface',
+                          'zope.interface',
                           'zope.component',
-			  'zope.app.wsgi',
+                          'zope.app.wsgi',
                           'zope.app.folder',
-			  'zope.app.publisher',
-			  'z3ext.cache',
+                          'zope.app.publisher',
+                          'z3ext.cache',
                           'z3ext.layout',
                           'z3ext.portlet',
                           'z3ext.pageelement',

Modified: z3ext.profiler/trunk/src/z3ext/profiler/DMstats.py
===================================================================
--- z3ext.profiler/trunk/src/z3ext/profiler/DMstats.py	2009-08-16 14:23:32 UTC (rev 102855)
+++ z3ext.profiler/trunk/src/z3ext/profiler/DMstats.py	2009-08-16 14:41:36 UTC (rev 102856)
@@ -18,74 +18,74 @@
 
 class Stats(pStats):
 
-  def setOutputFile(self, file):
-    self._out = file
+    def setOutputFile(self, file):
+        self._out = file
 
-  def showCallees(self, *amount):
-    msg, fs = self._selectFunctions(amount)
-    self._print(msg)
-    for f in fs: self._showCallees(f); self._print('\n')
+    def showCallees(self, *amount):
+        msg, fs = self._selectFunctions(amount)
+        self._print(msg)
+        for f in fs: self._showCallees(f); self._print('\n')
 
-  def showStats(self, *amount):
-    msg, fs = self._selectFunctions(amount)
-    self._print(msg)
-    for f in fs: self._showStats(f)
+    def showStats(self, *amount):
+        msg, fs = self._selectFunctions(amount)
+        self._print(msg)
+        for f in fs: self._showStats(f)
 
-  def showCallers(self, *amount):
-    msg, fs = self._selectFunctions(amount)
-    self._print(msg)
-    for f in fs: self._showCallers(f); self._print('\n')
+    def showCallers(self, *amount):
+        msg, fs = self._selectFunctions(amount)
+        self._print(msg)
+        for f in fs: self._showCallers(f); self._print('\n')
 
-  def _selectFunctions(self, amount):
-    if self.fcn_list:
-      l = self.fcn_list
-      msg = "   Ordered by: " + self.sort_type + '\n'
-    else:
-      l = self.stats.keys()
-      msg = "   Unordered\n"
-    for sel in amount:
-      l, msg = self.eval_print_amount(sel, l, msg)
-    return msg, l
+    def _selectFunctions(self, amount):
+        if self.fcn_list:
+            l = self.fcn_list
+            msg = "   Ordered by: " + self.sort_type + '\n'
+        else:
+            l = self.stats.keys()
+            msg = "   Unordered\n"
+        for sel in amount:
+            l, msg = self.eval_print_amount(sel, l, msg)
+        return msg, l
 
-  def _showCallees(self, f):
-    self._showStats(f)
-    self.calc_callees()
-    callees = self.all_callees.get(f)
-    if not callees: return
-    stats = self.stats; format = self._formatFunction
-    for (cf, calls) in callees.iteritems():
-      scf = stats[cf]
-      try:
-        self._print('\t%4dc\t(of %4dc in %8.3fs)\t%s\n'
-                    % (calls, scf[1], scf[3], format(cf), ))
-      except:
-        self._print('\t%4dc\t(of %4dc in %8.3fs)\t%s\n'
-                    % (calls[0], scf[1], scf[3], format(cf), ))
+    def _showCallees(self, f):
+        self._showStats(f)
+        self.calc_callees()
+        callees = self.all_callees.get(f)
+        if not callees: return
+        stats = self.stats; format = self._formatFunction
+        for (cf, calls) in callees.iteritems():
+            scf = stats[cf]
+            try:
+                self._print('\t%4dc\t(of %4dc in %8.3fs)\t%s\n'
+                            % (calls, scf[1], scf[3], format(cf), ))
+            except:
+                self._print('\t%4dc\t(of %4dc in %8.3fs)\t%s\n'
+                            % (calls[0], scf[1], scf[3], format(cf), ))
 
-  def _showCallers(self, f):
-    self._showStats(f)
-    stats = self.stats; format = self._formatFunction
-    mstat = stats[f]
-    for (cf, calls) in mstat[4].iteritems():
-      scf = stats[cf]
-      try:
-        self._print('\t%4dc\t(from %4dc in %8.3fs)\t%s\n'
-                    % (calls, scf[1], scf[3], format(cf), )
-                    )
-      except:
-        self._print('\t%4dc\t(from %4dc in %8.3fs)\t%s\n'
-                    % (calls[0], scf[1], scf[3], format(cf), )
-                    )
+    def _showCallers(self, f):
+        self._showStats(f)
+        stats = self.stats; format = self._formatFunction
+        mstat = stats[f]
+        for (cf, calls) in mstat[4].iteritems():
+            scf = stats[cf]
+            try:
+                self._print('\t%4dc\t(from %4dc in %8.3fs)\t%s\n'
+                            % (calls, scf[1], scf[3], format(cf), )
+                            )
+            except:
+                self._print('\t%4dc\t(from %4dc in %8.3fs)\t%s\n'
+                            % (calls[0], scf[1], scf[3], format(cf), )
+                            )
 
-  def _formatFunction(self, ft):
-    return '%s:%s(%s)' % ft
+    def _formatFunction(self, ft):
+        return '%s:%s(%s)' % ft
 
-  def _showStats(self, ft):
-    s = self.stats[ft]
-    self._print('%4dc - %8.3fs %8.3fs/c - %8.3fs %8.3fs/c - %s\n' % (
-      s[1], s[2], s[2]/s[1], s[3], s[3]/s[1], self._formatFunction(ft),
-      )
-                )
+    def _showStats(self, ft):
+        s = self.stats[ft]
+        self._print('%4dc - %8.3fs %8.3fs/c - %8.3fs %8.3fs/c - %s\n' % (
+          s[1], s[2], s[2]/s[1], s[3], s[3]/s[1], self._formatFunction(ft),
+          )
+                    )
 
-  def _print(self, txt):
-    self._out.write(txt)
+    def _print(self, txt):
+        self._out.write(txt)

Modified: z3ext.profiler/trunk/src/z3ext/profiler/configlet.py
===================================================================
--- z3ext.profiler/trunk/src/z3ext/profiler/configlet.py	2009-08-16 14:23:32 UTC (rev 102855)
+++ z3ext.profiler/trunk/src/z3ext/profiler/configlet.py	2009-08-16 14:41:36 UTC (rev 102856)
@@ -11,7 +11,7 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-""" 
+"""
 
 $Id:  2007-12-12 12:27:02Z fafhrd $
 """

Modified: z3ext.profiler/trunk/src/z3ext/profiler/configure.zcml
===================================================================
--- z3ext.profiler/trunk/src/z3ext/profiler/configure.zcml	2009-08-16 14:23:32 UTC (rev 102855)
+++ z3ext.profiler/trunk/src/z3ext/profiler/configure.zcml	2009-08-16 14:41:36 UTC (rev 102856)
@@ -28,4 +28,25 @@
      class=".portlet.PortletProfiler"
      weight="200" />
 
+  <z3ext:pagelet
+     name="pageelement"
+     type="wizard.step"
+     title="Page element"
+     label="Page element profiler"
+     for=".interfaces.IProfilerConfiglet
+	  z3ext.controlpanel.browser.interfaces.IConfigletEditWizard"
+     template="edit.pt"
+     class=".pageelement.PageElementProfiler"
+     weight="210" />
+
+  <z3ext:pagelet
+     name="timelogger"
+     type="wizard.step"
+     title="Time logger"
+     label="Time logger"
+     for=".interfaces.IProfilerConfiglet
+	  z3ext.controlpanel.browser.interfaces.IConfigletEditWizard"
+     class=".timelog.TimeLogger"
+     weight="250" />
+
 </configure>

Modified: z3ext.profiler/trunk/src/z3ext/profiler/interfaces.py
===================================================================
--- z3ext.profiler/trunk/src/z3ext/profiler/interfaces.py	2009-08-16 14:23:32 UTC (rev 102855)
+++ z3ext.profiler/trunk/src/z3ext/profiler/interfaces.py	2009-08-16 14:41:36 UTC (rev 102856)
@@ -11,27 +11,45 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-""" 
+"""
 
 $Id:  2007-12-12 12:27:02Z fafhrd $
 """
 from zope import interface, schema
 from z3ext.widget.list import SimpleList
 
+profilerEnabled = False
 
+
 class IPortletProfiler(interface.Interface):
     """ portlet profiler """
 
     pnumber = schema.Int(
         title = u'Number of calls',
         default = 1,
+        min = 1,
         required = True)
 
     portlets = SimpleList(
         title = u'Portlet ids',
         default = [],
+        required = False)
+
+
+class IPageElementProfiler(interface.Interface):
+    """ pageelement profiler """
+
+    penumber = schema.Int(
+        title = u'Number of calls',
+        default = 1,
+        min = 1,
         required = True)
 
+    pageelements = SimpleList(
+        title = u'Page element ids',
+        default = [],
+        required = True)
 
-class IProfilerConfiglet(IPortletProfiler):
+
+class IProfilerConfiglet(IPortletProfiler, IPageElementProfiler):
     """ profiler """

Added: z3ext.profiler/trunk/src/z3ext/profiler/pageelement.py
===================================================================
--- z3ext.profiler/trunk/src/z3ext/profiler/pageelement.py	                        (rev 0)
+++ z3ext.profiler/trunk/src/z3ext/profiler/pageelement.py	2009-08-16 14:41:36 UTC (rev 102856)
@@ -0,0 +1,95 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" 
+
+$Id$
+"""
+import time, profile, types
+from z3ext.layoutform import button, Fields, PageletEditForm
+from z3ext.wizard.step import WizardStepForm
+from z3ext.pageelement.element import PageElement
+from z3ext.statusmessage.interfaces import IStatusMessage
+
+from DMstats import Stats
+from stats import ProfilerStatistics
+from interfaces import profilerEnabled, IPageElementProfiler
+
+
+class PageElementProfiler(WizardStepForm, PageletEditForm, ProfilerStatistics):
+
+    fields = Fields(IPageElementProfiler)
+
+    buttons = PageletEditForm.buttons.copy()
+    handlers = PageletEditForm.handlers.copy()
+
+    def getStats(self):
+        return _stats
+
+    @button.buttonAndHandler(u'Run Profiler')
+    def handleProfiler(self, action):
+        if profilerEnabled:
+            IStatusMessage(self.request).add(
+                u'Can not start profiler. Another profiler is running.',
+                'warning')
+        else:
+            configlet = self.getContent()
+
+            installProfiler(configlet.penumber, configlet.pageelements)
+            IStatusMessage(self.request).add(
+                u'PageElements profiler has been started.')
+
+
+_calls = 1
+_stats = {}
+_elements = []
+
+originalMethod = PageElement.render
+
+
+def renderPageElement(self):
+    global _calls, profilerEnabled
+
+    print self.__name__, _elements, self.__name__ in _elements
+
+    if _calls > 0 and (self.__name__ in _elements):
+        prof = profile.Profile(time.time)
+        response = prof.runcall(method)
+
+        uri = 'page element: %s'%self.__name__
+        if _stats.has_key(uri):
+            _stats[uri][0].add(prof)
+            _stats[uri][1] = _stats[uri][1] + 1
+        else:
+            _stats[uri] = ([Stats(prof), 1])
+
+        if _calls > 0:
+            _calls = _calls - 1
+        if _calls <= 0:
+            profilerEnabled = False
+            PageElement.updateAndRender = originalMethod
+
+        return response
+    else:
+        return originalMethod(self)
+
+
+def installProfiler(calls, elements):
+    global _calls, _stats, _elements, profilerEnabled
+
+    _calls = calls
+    _stats = {}
+    _elements = tuple(elements)
+    profilerEnabled = True
+
+    PageElement.render = renderPageElement


Property changes on: z3ext.profiler/trunk/src/z3ext/profiler/pageelement.py
___________________________________________________________________
Added: svn:keywords
   + Id

Modified: z3ext.profiler/trunk/src/z3ext/profiler/pagelet.py
===================================================================
--- z3ext.profiler/trunk/src/z3ext/profiler/pagelet.py	2009-08-16 14:23:32 UTC (rev 102855)
+++ z3ext.profiler/trunk/src/z3ext/profiler/pagelet.py	2009-08-16 14:41:36 UTC (rev 102856)
@@ -11,9 +11,20 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-""" 
+"""
 
 $Id:  2007-12-12 12:27:02Z fafhrd $
 """
 
 pageletNames = []
+
+#                if __debug__:
+#                    dt = datetime.now()
+#                    rendered = pagelet.updateAndRender()
+#                    td = datetime.now() - dt
+#                    secs = (td.days*86400+td.seconds)+(0.000001*td.microseconds)
+#                    print >>sys.stderr, 'pagelet:      ', secs, name
+#
+#                    return rendered
+#                else:
+#                    return pagelet.updateAndRender()

Modified: z3ext.profiler/trunk/src/z3ext/profiler/portlet.py
===================================================================
--- z3ext.profiler/trunk/src/z3ext/profiler/portlet.py	2009-08-16 14:23:32 UTC (rev 102855)
+++ z3ext.profiler/trunk/src/z3ext/profiler/portlet.py	2009-08-16 14:41:36 UTC (rev 102856)
@@ -11,7 +11,7 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-""" 
+"""
 
 $Id:  2007-12-12 12:27:02Z fafhrd $
 """
@@ -23,11 +23,10 @@
 from z3ext.portlet.manager import PortletManagerBase
 from z3ext.portlet.interfaces import IPortletManagerView
 from z3ext.statusmessage.interfaces import IStatusMessage
-from z3ext.cache import configlet as cacheconfiglet
 
 from DMstats import Stats
 from stats import ProfilerStatistics
-from interfaces import IPortletProfiler
+from interfaces import profilerEnabled, IPortletProfiler
 
 
 class PortletProfiler(WizardStepForm, PageletEditForm, ProfilerStatistics):
@@ -38,15 +37,20 @@
     handlers = PageletEditForm.handlers.copy()
 
     def getStats(self):
-        global _stats
         return _stats
 
     @button.buttonAndHandler(u'Run Profiler')
     def handleProfiler(self, action):
-        configlet = self.getContent()
+        if profilerEnabled:
+            IStatusMessage(self.request).add(
+                u'Can not start profiler. Another profiler is running.',
+                'warning')
+        else:
+            configlet = self.getContent()
 
-        installProfiler(configlet.pnumber, configlet.portlets)
-        IStatusMessage(self.request).add(u'Profiler has started.')
+            installProfiler(configlet.pnumber, configlet.portlets)
+            IStatusMessage(self.request).add(
+                u'Portlets profiler has been started.')
 
 
 _calls = 1
@@ -57,6 +61,8 @@
 
 
 def renderPortletManager(self):
+    global _calls, profilerEnabled
+
     if not self.portlets or not self.isAvailable():
         return u''
 
@@ -67,28 +73,21 @@
     portlets = []
 
     for portlet in self.portlets:
-        if portlet.__name__ in _portlets:
-            uri = 'portlet: %s'%portlet.__name__
+        if _calls > 0 and (not _portlets or portlet.__name__ in _portlets):
             prof = profile.Profile(time.time)
-
-            cache = cacheconfiglet.cache
-            cacheconfiglet.cache = None
-
             response = prof.runcall(portlet.updateAndRender)
 
-            cacheconfiglet.cache = cache
-
+            uri = 'portlet: %s'%portlet.__name__
             if _stats.has_key(uri):
                 _stats[uri][0].add(prof)
                 _stats[uri][1] = _stats[uri][1] + 1
             else:
                 _stats[uri] = ([Stats(prof), 1])
 
-            global _calls
             if _calls > 0:
                 _calls = _calls - 1
-
             if _calls <= 0:
+                profilerEnabled = False
                 PortletManagerBase.render = originalMethod
 
             portlets.append(response)
@@ -99,10 +98,11 @@
 
 
 def installProfiler(calls, portlets):
-    global _calls, _stats, _portlets
+    global _calls, _stats, _portlets, profilerEnabled
 
     _calls = calls
     _stats = {}
     _portlets = tuple(portlets)
+    profilerEnabled = True
 
     PortletManagerBase.render = renderPortletManager

Modified: z3ext.profiler/trunk/src/z3ext/profiler/profiler.py
===================================================================
--- z3ext.profiler/trunk/src/z3ext/profiler/profiler.py	2009-08-16 14:23:32 UTC (rev 102855)
+++ z3ext.profiler/trunk/src/z3ext/profiler/profiler.py	2009-08-16 14:41:36 UTC (rev 102856)
@@ -35,7 +35,7 @@
 
     prof = profile.Profile(time.time)
     response = prof.runcall(orig_call, self, environ, start_response)
-    
+
     lock= _lock
 
     lock.acquire()
@@ -43,7 +43,7 @@
         global _stats
 
         uri = environ.get('REQUEST_URI', '')
-        
+
         if _stats.has_key(uri):
             _stats[uri][0].add(prof)
             _stats[uri][2] = _stats[uri][2] + 1

Modified: z3ext.profiler/trunk/src/z3ext/profiler/stats.py
===================================================================
--- z3ext.profiler/trunk/src/z3ext/profiler/stats.py	2009-08-16 14:23:32 UTC (rev 102855)
+++ z3ext.profiler/trunk/src/z3ext/profiler/stats.py	2009-08-16 14:41:36 UTC (rev 102856)
@@ -11,7 +11,7 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-""" 
+"""
 
 $Id:  2007-12-12 12:27:02Z fafhrd $
 """
@@ -62,7 +62,7 @@
             stats.setOutputFile(output)
             getattr(stats, 'show%s' % mode.capitalize())(str(stdnameRe), limit)
             res = output.getvalue()
-            if not res: 
+            if not res:
                 res = 'No matching functions'
             return res
         else:

Added: z3ext.profiler/trunk/src/z3ext/profiler/timelog.py
===================================================================
--- z3ext.profiler/trunk/src/z3ext/profiler/timelog.py	                        (rev 0)
+++ z3ext.profiler/trunk/src/z3ext/profiler/timelog.py	2009-08-16 14:41:36 UTC (rev 102856)
@@ -0,0 +1,154 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" 
+
+$Id$
+"""
+import time, sys
+from datetime import datetime
+
+from zope.component import queryMultiAdapter
+from z3ext.layoutform.interfaces import ISaveAction
+from z3ext.layoutform import button, Fields, PageletEditForm
+from z3ext.wizard.step import WizardStepForm
+from z3ext.layout.tales import PageletExpression
+from z3ext.layout.pagelet import PageletPublisher, queryPagelet
+from z3ext.portlet.manager import PortletManagerBase
+from z3ext.portlet.interfaces import IPortletManagerView
+from z3ext.pageelement.tales import PageelementExpression
+from z3ext.pageelement.interfaces import IPageElement
+from z3ext.statusmessage.interfaces import IStatusMessage
+
+from interfaces import profilerEnabled
+
+
+class TimeLogger(WizardStepForm, PageletEditForm):
+
+    @button.buttonAndHandler(u'Start logger')
+    def handleStartLogger(self, action):
+        if profilerEnabled:
+            IStatusMessage(self.request).add(
+                u'Can not start logger. Another logger or profiler is running.',
+                'warning')
+        else:
+            configlet = self.getContent()
+
+            installLogger()
+            IStatusMessage(self.request).add(
+                u'Time logger has been started.')
+
+    @button.buttonAndHandler(u'Stop logger')
+    def handleStopLogger(self, action):
+        uninstallLogger()
+        IStatusMessage(self.request).add(u'Time logger has been stoped.')
+
+
+_names = []
+
+originalRenderPagelet = PageletExpression.render
+originalGetitemPagelet = PageletPublisher.__getitem__
+originalPortletMethod = PortletManagerBase.render
+originalPageelementMethod = PageelementExpression.__call__
+
+
+def renderPortletManager(self):
+    if not self.portlets or not self.isAvailable():
+        return u''
+
+    view = queryMultiAdapter((self, self.request), IPortletManagerView)
+    if view is not None:
+        return view.updateAndRender()
+
+    portlets = []
+
+    for portlet in self.portlets:
+        dt = datetime.now()
+        rendered = portlet.updateAndRender()
+        td = datetime.now() - dt
+        secs = (td.days*86400+td.seconds)+(0.000001*td.microseconds)
+        print >>sys.stderr, 'portlet:      ', '%0.6f'%secs, portlet.__name__
+
+        portlets.append(rendered)
+
+    return u'\n'.join(portlets)
+
+
+def callPageElement(self, context, request, view, name):
+    pageelement = queryMultiAdapter(
+        (context, request, view), IPageElement, name)
+
+    if pageelement is None:
+        return u''
+
+    try:
+        dt = datetime.now()
+        rendered = pageelement.updateAndRender()
+        td = datetime.now() - dt
+        secs = (td.days*86400+td.seconds)+(0.000001*td.microseconds)
+        print >>sys.stderr, 'pageelement:  ', '%0.6f'%secs, name
+        return rendered
+    except Exception, exc:
+        return unicode(exc)
+
+
+def renderPagelet(self, context, request, view, name):
+    try:
+        dt = datetime.now()
+        pagelet = queryPagelet(context, request, name)
+        if pagelet is not None:
+             rendered = pagelet.updateAndRender()
+             td = datetime.now() - dt
+             secs = (td.days*86400+td.seconds)+(0.000001*td.microseconds)
+             print >>sys.stderr, 'pagelet:      ', '%0.6f'%secs, name
+             return rendered
+    except Exception, err:
+        pass
+
+    return u''
+
+
+def getitemPagelet(self, name):
+    dt = datetime.now()
+    view = queryPagelet(self.context, self.request, name)
+
+    if view is not None:
+        try:
+            rendered = view.updateAndRender()
+            td = datetime.now() - dt
+            secs = (td.days*86400+td.seconds)+(0.000001*td.microseconds)
+            print >>sys.stderr, 'pagelet:      ', '%0.6f'%secs, name
+            return rendered
+        except Exception, err:
+            pass
+
+    raise KeyError(name)
+
+
+def installLogger():
+    global profilerEnabled
+
+    profilerEnabled = True
+    PageletExpression.render = renderPagelet
+    PageletPublisher.__getitem__ = getitemPagelet
+    PortletManagerBase.render = renderPortletManager
+    PageelementExpression.__call__ = callPageElement
+
+def uninstallLogger():
+    global profilerEnabled
+
+    profilerEnabled = False
+    PageletExpression.render = originalRenderPagelet
+    PageletPublisher.__getitem__ = originalGetitemPagelet
+    PortletManagerBase.render = originalPortletMethod
+    PageelementExpression.__call__ = originalPageelementMethod


Property changes on: z3ext.profiler/trunk/src/z3ext/profiler/timelog.py
___________________________________________________________________
Added: svn:keywords
   + Id

Modified: z3ext.profiler/trunk/src/z3ext/profiler/view.py
===================================================================
--- z3ext.profiler/trunk/src/z3ext/profiler/view.py	2009-08-16 14:23:32 UTC (rev 102855)
+++ z3ext.profiler/trunk/src/z3ext/profiler/view.py	2009-08-16 14:41:36 UTC (rev 102856)
@@ -61,7 +61,7 @@
             stats.setOutputFile(output)
             getattr(stats, 'show%s' % mode.capitalize())(str(stdnameRe), limit)
             res = output.getvalue()
-            if not res: 
+            if not res:
                 res = 'No matching functions'
             return res
         else:



More information about the Checkins mailing list