Commit b221eaaa authored by David Wilson's avatar David Wilson

ansible: log call timings

parent 1e9fd633
...@@ -26,7 +26,9 @@ ...@@ -26,7 +26,9 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import absolute_import from __future__ import absolute_import
import logging
import os import os
import time
import ansible.errors import ansible.errors
import ansible.plugins.connection import ansible.plugins.connection
...@@ -38,6 +40,9 @@ import ansible_mitogen.helpers ...@@ -38,6 +40,9 @@ import ansible_mitogen.helpers
from ansible_mitogen.strategy.mitogen import ContextService from ansible_mitogen.strategy.mitogen import ContextService
LOG = logging.getLogger(__name__)
class Connection(ansible.plugins.connection.ConnectionBase): class Connection(ansible.plugins.connection.ConnectionBase):
#: mitogen.master.Router for this worker. #: mitogen.master.Router for this worker.
router = None router = None
...@@ -174,7 +179,12 @@ class Connection(ansible.plugins.connection.ConnectionBase): ...@@ -174,7 +179,12 @@ class Connection(ansible.plugins.connection.ConnectionBase):
:returns: :returns:
Function return value. Function return value.
""" """
return self.call_async(func, *args, **kwargs).get().unpickle() t0 = time.time()
try:
return self.call_async(func, *args, **kwargs).get().unpickle()
finally:
LOG.debug('Call %s%r took %d ms', func.func_name, args,
1000 * (time.time() - t0))
def exec_command(self, cmd, in_data='', sudoable=True): def exec_command(self, cmd, in_data='', sudoable=True):
""" """
......
...@@ -1000,11 +1000,14 @@ A random assortment of utility functions useful on masters and children. ...@@ -1000,11 +1000,14 @@ A random assortment of utility functions useful on masters and children.
OS X bundles some ancient version of the :py:mod:`six` module. OS X bundles some ancient version of the :py:mod:`six` module.
.. currentmodule:: mitogen.utils .. currentmodule:: mitogen.utils
.. function:: log_to_file (path=None, io=True, usec=False, level='INFO') .. function:: log_to_file (path=None, io=False, usec=False, level='INFO')
Install a new :py:class:`logging.Handler` writing applications logs to the Install a new :py:class:`logging.Handler` writing applications logs to the
filesystem. Useful when debugging slave IO problems. filesystem. Useful when debugging slave IO problems.
Parameters to this function may be overridden at runtime using environment
variables. See :ref:`logging-env-vars`.
:param str path: :param str path:
If not ``None``, a filesystem path to write logs to. Otherwise, logs If not ``None``, a filesystem path to write logs to. Otherwise, logs
are written to :py:data:`sys.stderr`. are written to :py:data:`sys.stderr`.
......
...@@ -49,7 +49,7 @@ def _formatTime(record, datefmt=None): ...@@ -49,7 +49,7 @@ def _formatTime(record, datefmt=None):
return dt.strftime(datefmt) return dt.strftime(datefmt)
def log_to_file(path=None, io=True, usec=False, level='INFO'): def log_to_file(path=None, io=False, usec=False, level='INFO'):
io = ('MITOGEN_LOG_IO' in os.environ) or io io = ('MITOGEN_LOG_IO' in os.environ) or io
usec = ('MITOGEN_LOG_USEC' in os.environ) or usec usec = ('MITOGEN_LOG_USEC' in os.environ) or usec
level = os.environ.get('MITOGEN_LOG_LEVEL', level).upper() level = os.environ.get('MITOGEN_LOG_LEVEL', level).upper()
......
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