diff --git a/product/CMFActivity/ActivityTool.py b/product/CMFActivity/ActivityTool.py index 51d8b174b15dad6f3c3974c08b7f3b2dcf167b33..95e3b79079fd78b57719bd06307d1a6eb35f1a7b 100644 --- a/product/CMFActivity/ActivityTool.py +++ b/product/CMFActivity/ActivityTool.py @@ -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)