Commit 075bfc23 authored by Vincent Pelletier's avatar Vincent Pelletier

Add the possibility to log activity execution timing.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24365 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2f158eba
...@@ -56,6 +56,7 @@ from Products.MailHost.MailHost import MailHostError ...@@ -56,6 +56,7 @@ from Products.MailHost.MailHost import MailHostError
from zLOG import LOG, INFO, WARNING, ERROR from zLOG import LOG, INFO, WARNING, ERROR
from warnings import warn from warnings import warn
from time import time
try: try:
from Products.TimerService import getTimerService from Products.TimerService import getTimerService
...@@ -93,6 +94,7 @@ import logging ...@@ -93,6 +94,7 @@ import logging
activity_logger = logging.getLogger('CMFActivity') activity_logger = logging.getLogger('CMFActivity')
# Some logging subchannels # Some logging subchannels
activity_tracking_logger = logging.getLogger('CMFActivity.Tracking') activity_tracking_logger = logging.getLogger('CMFActivity.Tracking')
activity_timing_logger = logging.getLogger('CMFActivity.TimingLog')
# Direct logging to "[instancehome]/log/CMFActivity.log", if this directory exists. # Direct logging to "[instancehome]/log/CMFActivity.log", if this directory exists.
# Otherwise, it will end up in root logging facility (ie, event.log). # Otherwise, it will end up in root logging facility (ie, event.log).
...@@ -132,6 +134,24 @@ def disableActivityCreationTrace(): ...@@ -132,6 +134,24 @@ def disableActivityCreationTrace():
global activity_creation_trace global activity_creation_trace
activity_creation_trace = False activity_creation_trace = False
activity_timing_log = False
def enableActivityTimingLog():
global activity_timing_log
activity_timing_log = True
def disableActivityTimingLog():
global activity_timing_log
activity_timing_log = False
def activity_timing_method(method, args, kw):
begin = time()
try:
return method(*args, **kw)
finally:
end = time()
activity_timing_logger.info('%.02fs: %r(*%r, **%r)' % (end - begin, method, args, kw))
# Here go ActivityBuffer instances # Here go ActivityBuffer instances
# Structure: # Structure:
# global_activity_buffer[activity_tool_path][thread_id] = ActivityBuffer # global_activity_buffer[activity_tool_path][thread_id] = ActivityBuffer
...@@ -281,6 +301,9 @@ class Message: ...@@ -281,6 +301,9 @@ class Message:
except: except:
method = None method = None
self.setExecutionState(MESSAGE_NOT_EXECUTABLE, context=activity_tool) self.setExecutionState(MESSAGE_NOT_EXECUTABLE, context=activity_tool)
else:
if activity_timing_log:
result = activity_timing_method(method, self.args, self.kw)
else: else:
result = method(*self.args, **self.kw) result = method(*self.args, **self.kw)
finally: finally:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment