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
from zLOG import LOG, INFO, WARNING, ERROR
from warnings import warn
from time import time
try:
from Products.TimerService import getTimerService
......@@ -93,6 +94,7 @@ import logging
activity_logger = logging.getLogger('CMFActivity')
# Some logging subchannels
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.
# Otherwise, it will end up in root logging facility (ie, event.log).
......@@ -132,6 +134,24 @@ def disableActivityCreationTrace():
global activity_creation_trace
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
# Structure:
# global_activity_buffer[activity_tool_path][thread_id] = ActivityBuffer
......@@ -282,7 +302,10 @@ class Message:
method = None
self.setExecutionState(MESSAGE_NOT_EXECUTABLE, context=activity_tool)
else:
result = method(*self.args, **self.kw)
if activity_timing_log:
result = activity_timing_method(method, self.args, self.kw)
else:
result = method(*self.args, **self.kw)
finally:
setSecurityManager(old_security_manager)
......
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