def add_timing(min_duration=3): module = import_module('urllib3') if not module: return def gather_args_url(r, m, url, *args, **kwargs): return { 'type': 'remote', 'statement': 'urllib3.request.RequestMethods.request_encode_url', 'parameters': url, 'count': True, 'ignore_in': ignore_set } deco_func_or_method(module.request, 'RequestMethods.request_encode_url', time_trace, gatherer=gather_args_url, min_duration=min_duration) def gather_args_body(r, m, url, *args, **kwargs): return { 'type': 'remote', 'statement': 'urllib3.request.RequestMethods.request_encode_body', 'parameters': url, 'count': True, 'ignore_in': ignore_set } deco_func_or_method(module.request, 'RequestMethods.request_encode_body', time_trace, gatherer=gather_args_body, min_duration=min_duration)
def add_timing(min_duration=0.1): module = import_module('redis') if not module: return def general_factory(slow_call_name): def gather_args(self, *args, **kwargs): return { 'type': 'nosql', 'subtype': 'redispy', 'count': True, 'statement': slow_call_name, 'ignore_in': ignore_set } return gather_args if hasattr(module, 'StrictRedis'): for m in to_decorate: deco_func_or_method(module, 'StrictRedis.%s' % m, time_trace, gatherer=general_factory('%s' % m), min_duration=min_duration) else: for m in to_decorate: deco_func_or_method(module, 'Redis.%s' % m, time_trace, gatherer=general_factory('%s' % m), min_duration=min_duration)
def add_timing(min_duration=3): module = import_module("urllib") if not module: return def gather_args_open(opener, url, *args, **kwargs): return { "type": "remote", "statement": "urllib.URLopener.open", "parameters": url, "count": True, "ignore_in": ignore_set, } deco_func_or_method(module, "URLopener.open", time_trace, gatherer=gather_args_open, min_duration=min_duration) def gather_args_urlretrieve(url, *args, **kwargs): return { "type": "remote", "statement": "urllib.urlretrieve", "parameters": url, "count": True, "ignore_in": ignore_set, } deco_func_or_method(module, "urlretrieve", time_trace, gatherer=gather_args_urlretrieve, min_duration=min_duration)
def add_timing(min_duration=0.15): module = import_module('jinja2') if not module: return from jinja2 import environment def gather_template(template, *args, **kwargs): try: tmpl_name = str(template.name) except Exception: tmpl_name = '' return { 'type': 'tmpl', 'subtype': 'jinja2', 'statement': 'render', 'parameters': tmpl_name, 'count': True, 'ignore_in': ignore_set } deco_func_or_method(environment, 'Template.render', time_trace, gatherer=gather_template, min_duration=min_duration, is_template=True) environment.Environment.template_class = environment.Template module.Template = environment.Template
def add_timing(min_duration=3): module = import_module('httplib') if not module: return def gather_args_host(c): return { 'type': 'remote', 'statement': 'httplib.HTTPConnection.connect', 'parameters': c.host, 'count': True, 'ignore_in': ignore_set } def gather_args_sslhost(c): return { 'type': 'remote', 'statement': 'httplib.HTTPSConnection.connect', 'parameters': c.host, 'count': True, 'ignore_in': ignore_set } deco_func_or_method(module, 'HTTPConnection.connect', time_trace, gatherer=gather_args_host, min_duration=min_duration) deco_func_or_method(module, 'HTTPSConnection.connect', time_trace, gatherer=gather_args_sslhost, min_duration=min_duration)
def add_timing(min_duration=0.15): module = import_module('django') if not module: return from django import template def gather_template(self, *args, **kwargs): try: tmpl_name = str(self.name) except Exception: tmpl_name = '' return { 'type': 'tmpl', 'subtype': 'django', 'statement': 'render', 'count': True, 'parameters': tmpl_name, 'ignore_in': ignore_set } if hasattr(template.Template, 'render'): deco_func_or_method(template, 'Template.render', time_trace, gatherer=gather_template, min_duration=min_duration, is_template=True) elif hasattr(template.Template, '_render'): deco_func_or_method(template, 'Template._render', time_trace, gatherer=gather_template, min_duration=min_duration, is_template=True)
def add_timing(min_duration=0.15): module = import_module('django') if not module: return from django import template def gather_template(self, *args, **kwargs): try: tmpl_name = str(self.name) except Exception: tmpl_name = '' return {'type': 'tmpl', 'subtype': 'django', 'statement': 'render', 'count': True, 'parameters': tmpl_name, 'ignore_in': ignore_set} if hasattr(template.Template, 'render'): deco_func_or_method(template, 'Template.render', time_trace, gatherer=gather_template, min_duration=min_duration, is_template=True) elif hasattr(template.Template, '_render'): deco_func_or_method(template, 'Template._render', time_trace, gatherer=gather_template, min_duration=min_duration, is_template=True)
def add_timing(min_duration=3): module = import_module('urllib3') if not module: return def gather_args_url(r, m, url, *args, **kwargs): return {'type': 'remote', 'statement': 'urllib3.request.RequestMethods.request_encode_url', 'parameters': url, 'count': True, 'ignore_in': ignore_set} deco_func_or_method(module.request, 'RequestMethods.request_encode_url', time_trace, gatherer=gather_args_url, min_duration=min_duration) def gather_args_body(r, m, url, *args, **kwargs): return {'type': 'remote', 'statement': 'urllib3.request.RequestMethods.request_encode_body', 'parameters': url, 'count': True, 'ignore_in': ignore_set} deco_func_or_method(module.request, 'RequestMethods.request_encode_body', time_trace, gatherer=gather_args_body, min_duration=min_duration)
def add_timing(min_duration=0.1): module = import_module('pymongo') if not module: return logging.warning('mongodb timing is currently experimental') from pymongo.collection import Collection def general_factory(slow_call_name): def gather_args(self, *args, **kwargs): return { 'type': 'nosql', 'subtype': 'mongo', 'count': True, 'statement': slow_call_name, 'ignore_in': ignore_set } return gather_args for m in to_decorate: deco_func_or_method(module.collection, 'Collection.%s' % m, time_trace, gatherer=general_factory('%s' % m), min_duration=min_duration)
def register(): try: import pylons.controllers.core module = pylons.controllers.core except ImportError: module = None if not module: return deco_func_or_method(module, 'WSGIController.__call__', wrap_pylons_view_method_name)
def add_timing(min_duration=3): module = import_module('requests') if not module: return def gather_args_url(method, url, *args, **kwargs): return {'type': 'remote', 'statement': 'requests.request', 'parameters': url, 'count': True, 'ignore_in': ignore_set} deco_func_or_method(module, 'api.request', time_trace, gatherer=gather_args_url, min_duration=min_duration)
def add_timing(min_duration=0.15): module = import_module('chameleon') if not module: return def gather_template(template, *args, **kwargs): return {'type': 'tmpl', 'subtype': 'chameleon', 'statement': 'render', 'parameters': '', 'count': True, 'ignore_in': ignore_set} deco_func_or_method(module.template, 'Template.render', time_trace, gatherer=gather_template, min_duration=min_duration, is_template=True)
def add_timing(min_duration=0.1): module = import_module('memcache') if not module: return def general_factory(slow_call_name): def gather_args(self, *args, **kwargs): return {'type': 'nosql', 'subtype': 'memcache-py', 'count': True, 'statement': slow_call_name, 'ignore_in': ignore_set} return gather_args for m in to_decorate: deco_func_or_method(module, 'Client.%s' % m, time_trace, gatherer=general_factory('%s' % m), min_duration=min_duration)
def add_timing(min_duration=3): module = import_module('urllib2') if not module: return def gather_args_open(opener, url, *args, **kwargs): if not isinstance(url, basestring): g_url = url.get_full_url() else: g_url = url return {'type': 'remote', 'statement': 'urllib2.OpenerDirector.open', 'parameters': g_url, 'count': True, 'ignore_in': ignore_set} deco_func_or_method(module, 'OpenerDirector.open', time_trace, gatherer=gather_args_open, min_duration=min_duration)
def add_timing(min_duration=0.15): module = import_module('jinja2') if not module: return from jinja2 import environment def gather_template(template, *args, **kwargs): return {'type': 'tmpl', 'subtype': 'jinja2', 'statement': 'render', 'parameters': '', 'count': True, 'ignore_in': ignore_set} deco_func_or_method(environment, 'Template.render', time_trace, gatherer=gather_template, min_duration=min_duration, is_template=True) environment.Environment.template_class = environment.Template module.Template = environment.Template
def add_timing(min_duration=0.1): module = import_module('pymongo') if not module: return logging.warning('mongodb timing is currently experimental') from pymongo.collection import Collection def general_factory(slow_call_name): def gather_args(self, *args, **kwargs): return {'type': 'nosql', 'subtype': 'mongo', 'count': True, 'statement': slow_call_name, 'ignore_in': ignore_set} return gather_args for m in to_decorate: deco_func_or_method(module.collection, 'Collection.%s' % m, time_trace, gatherer=general_factory('%s' % m), min_duration=min_duration)
def add_timing(min_duration=0.15): module = import_module('chameleon') if not module: return def gather_template(template, *args, **kwargs): return { 'type': 'tmpl', 'subtype': 'chameleon', 'statement': 'render', 'parameters': '', 'count': True, 'ignore_in': ignore_set } deco_func_or_method(module.template, 'Template.render', time_trace, gatherer=gather_template, min_duration=min_duration, is_template=True)
def add_timing(min_duration=3): module = import_module('urllib') if not module: return def gather_args_open(opener, url, *args, **kwargs): return {'type': 'remote', 'statement': 'urllib.URLopener.open', 'parameters': url, 'count': True, 'ignore_in': ignore_set} deco_func_or_method(module, 'URLopener.open', time_trace, gatherer=gather_args_open, min_duration=min_duration) def gather_args_urlretrieve(url, *args, **kwargs): return {'type': 'remote', 'statement': 'urllib.urlretrieve', 'parameters': url, 'count': True, 'ignore_in': ignore_set} deco_func_or_method(module, 'urlretrieve', time_trace, gatherer=gather_args_urlretrieve, min_duration=min_duration)
def add_timing(min_duration=0.1): module = import_module('redis') if not module: return def general_factory(slow_call_name): def gather_args(self, *args, **kwargs): return {'type': 'nosql', 'subtype': 'redispy', 'count': True, 'statement': slow_call_name, 'ignore_in': ignore_set} return gather_args if hasattr(module, 'StrictRedis'): for m in to_decorate: deco_func_or_method(module, 'StrictRedis.%s' % m, time_trace, gatherer=general_factory('%s' % m), min_duration=min_duration) else: for m in to_decorate: deco_func_or_method(module, 'Redis.%s' % m, time_trace, gatherer=general_factory('%s' % m), min_duration=min_duration)
def add_timing(min_duration=3): module = import_module('urllib') if not module: return def gather_args_open(opener, url, *args, **kwargs): return {'type': 'remote', 'statement': 'urllib.URLopener.open', 'parameters': url, 'count': True, 'ignore_in': ignore_set} deco_func_or_method(module, 'URLopener.open', time_trace, gatherer=gather_args_open, min_duration=min_duration) def gather_args_urlretrieve(url, *args, **kwargs): return {'type': 'remote', 'statement': 'urllib.urlretrieve', 'parameters': url, 'count': True, 'ignore_in': ignore_set} deco_func_or_method(module, 'urlretrieve', time_trace, gatherer=gather_args_urlretrieve, min_duration=min_duration )
def add_timing(min_duration=3): module = import_module('urllib2') if not module: return def gather_args_open(opener, url, *args, **kwargs): if not isinstance(url, basestring): g_url = url.get_full_url() else: g_url = url return { 'type': 'remote', 'statement': 'urllib2.OpenerDirector.open', 'parameters': g_url, 'count': True, 'ignore_in': ignore_set } deco_func_or_method(module, 'OpenerDirector.open', time_trace, gatherer=gather_args_open, min_duration=min_duration)
def add_timing(min_duration=3): module = import_module('httplib') if not module: return def gather_args_host(c): return {'type': 'remote', 'statement': 'httplib.HTTPConnection.connect', 'parameters': c.host, 'count': True, 'ignore_in': ignore_set} def gather_args_sslhost(c): return {'type': 'remote', 'statement': 'httplib.HTTPSConnection.connect', 'parameters': c.host, 'count': True, 'ignore_in': ignore_set} deco_func_or_method(module, 'HTTPConnection.connect', time_trace, gatherer=gather_args_host, min_duration=min_duration) deco_func_or_method(module, 'HTTPSConnection.connect', time_trace, gatherer=gather_args_sslhost, min_duration=min_duration)
def add_timing(min_duration=0.15): module = import_module('mako') if not module: return from mako import template def gather_template(template, *args, **kwargs): return {'type': 'tmpl', 'subtype': 'mako', 'statement': 'render', 'parameters': '', 'count': True, 'ignore_in': ignore_set} deco_func_or_method(template, 'Template.render', time_trace, gatherer=gather_template, min_duration=min_duration, is_template=True) deco_func_or_method(template, 'Template.render_unicode', time_trace, gatherer=gather_template, min_duration=min_duration, is_template=True) deco_func_or_method(template, 'Template.render_context', time_trace, gatherer=gather_template, min_duration=min_duration, is_template=True)
def add_timing(min_duration=0.15): module = import_module("mako") if not module: return from mako import template def gather_template(self, *args, **kwargs): try: tmpl_name = str(self.filename or self.module_id) except Exception: tmpl_name = "" return { "type": "tmpl", "subtype": "mako", "statement": "render", "parameters": tmpl_name, "count": True, "ignore_in": ignore_set, } deco_func_or_method( template, "Template.render", time_trace, gatherer=gather_template, min_duration=min_duration, is_template=True ) deco_func_or_method( template, "Template.render_unicode", time_trace, gatherer=gather_template, min_duration=min_duration, is_template=True, ) deco_func_or_method( template, "Template.render_context", time_trace, gatherer=gather_template, min_duration=min_duration, is_template=True, )
def add_timing(min_duration=0.1): module = import_module('pysolr') if not module: return def general_factory(slow_call_name): def gather_args(solr, *args, **kwargs): return {'type': 'nosql', 'subtype': 'solr', 'statement': slow_call_name, 'count': True, 'ignore_in': ignore_set} return gather_args def gather_args_search(solr, q, *args, **kwargs): return {'type': 'nosql', 'subtype': 'solr', 'statement': q, 'count': True, 'ignore_in': ignore_set} def gather_args_more_like_this(solr, q, *args, **kwargs): return {'type': 'nosql', 'subtype': 'solr', 'statement': q, 'count': True, 'ignore_in': ignore_set} deco_func_or_method(module, 'Solr.search', time_trace, gatherer=gather_args_search, min_duration=min_duration) deco_func_or_method(module, 'Solr.add', time_trace, gatherer=general_factory('Solr.add'), min_duration=min_duration) deco_func_or_method(module, 'Solr.commit', time_trace, gatherer=general_factory('Solr.commit'), min_duration=min_duration) deco_func_or_method(module, 'Solr.delete', time_trace, gatherer=general_factory('Solr.delete'), min_duration=min_duration) deco_func_or_method(module, 'Solr.extract', time_trace, gatherer=general_factory('Solr.extract'), min_duration=min_duration) deco_func_or_method(module, 'Solr.more_like_this', time_trace, gatherer=gather_args_more_like_this, min_duration=min_duration) deco_func_or_method(module, 'Solr.suggest_terms', time_trace, gatherer=general_factory('Solr.commit'), min_duration=min_duration)
def add_timing(min_duration=0.1): module = import_module('pysolr') if not module: return def general_factory(slow_call_name): def gather_args(solr, *args, **kwargs): return { 'type': 'nosql', 'subtype': 'solr', 'statement': slow_call_name, 'count': True, 'ignore_in': ignore_set } return gather_args def gather_args_search(solr, q, *args, **kwargs): return { 'type': 'nosql', 'subtype': 'solr', 'statement': q, 'count': True, 'ignore_in': ignore_set } def gather_args_more_like_this(solr, q, *args, **kwargs): return { 'type': 'nosql', 'subtype': 'solr', 'statement': q, 'count': True, 'ignore_in': ignore_set } deco_func_or_method(module, 'Solr.search', time_trace, gatherer=gather_args_search, min_duration=min_duration) deco_func_or_method(module, 'Solr.add', time_trace, gatherer=general_factory('Solr.add'), min_duration=min_duration) deco_func_or_method(module, 'Solr.commit', time_trace, gatherer=general_factory('Solr.commit'), min_duration=min_duration) deco_func_or_method(module, 'Solr.delete', time_trace, gatherer=general_factory('Solr.delete'), min_duration=min_duration) deco_func_or_method(module, 'Solr.extract', time_trace, gatherer=general_factory('Solr.extract'), min_duration=min_duration) deco_func_or_method(module, 'Solr.more_like_this', time_trace, gatherer=gather_args_more_like_this, min_duration=min_duration) deco_func_or_method(module, 'Solr.suggest_terms', time_trace, gatherer=general_factory('Solr.commit'), min_duration=min_duration)
from functools import wraps def wrap_pylons_view_method_name(): def decorator(appenlight_callable): @wraps(appenlight_callable) def view_callable_wrapper(self, environ, start_response): try: action = environ['pylons.routes_dict'].get('action', '') controller = fullyQualifiedName(self.__class__) environ['appenlight.view_name'] = "%s.%s" % (controller, action) except Exception, e: pass return appenlight_callable(self, environ, start_response) return view_callable_wrapper return decorator def register(): try: import pylons.controllers.core module = pylons.controllers.core except ImportError, e: module = None if not module: return deco_func_or_method(module, 'WSGIController.__call__', wrap_pylons_view_method_name)