Ejemplo n.º 1
0
def _timing(operation, name):
    """
    Run the `operation` callable, returning the number of seconds it took.
    """
    now = time.time()
    with Metric(name):
        operation()
    done = time.time()
    return done - now
Ejemplo n.º 2
0
def _patch_diazo():
    """Measure setup/compile time of diazo.

    This is the time needed to build the xslt from the rules and index.html
    files.
    """
    try:
        from plone.app.theming.transform import ThemeTransform
        from perfmetrics import Metric
    except ImportError:
        logger.debug('No Plone Diazo patche for zperfmetrics')
        return

    # patch to measure plone.app.theming by wrapping with a Metric,
    # similar to decorating.
    logger.info('Activating Plone Diazo patch for zperfmetrics')
    ThemeTransform.setupTransform = Metric(
        stat='diazo.setup',
        method=True,
    )(ThemeTransform.setupTransform)
Ejemplo n.º 3
0
##############################################################################
"""IObjectMover implementation.
"""
from __future__ import absolute_import
from perfmetrics import Metric
from relstorage.adapters.batch import RowBatcher
from relstorage.adapters.interfaces import IObjectMover
from relstorage.adapters._util import query_property as _query_property
from relstorage.adapters._util import noop_when_history_free
from relstorage.iter import fetchmany
from zope.interface import implementer
from hashlib import md5

from relstorage._compat import db_binary_to_bytes

metricmethod_sampled = Metric(method=True, rate=0.1)

@implementer(IObjectMover)
class AbstractObjectMover(object):

    def __init__(self, database_type, options, runner=None,
                 Binary=None, version_detector=None,
                 batcher_factory=RowBatcher):
        self.database_type = database_type
        self.keep_history = options.keep_history
        self.blob_chunk_size = options.blob_chunk_size
        self.runner = runner
        self.Binary = Binary
        self.version_detector = version_detector
        self.make_batcher = batcher_factory
Ejemplo n.º 4
0
 def spam(x, y=2):
     with Metric('thing-done', count=False, timing=False):
         args.append((x, y))
Ejemplo n.º 5
0
 def spam(x, y=2):
     with Metric():
         args.append((x, y))
Ejemplo n.º 6
0
 def spam(x, y=2):
     with Metric('thing-done', rate=0.99, random=lambda: 0.999):
         args.append((x, y))
         return 88
Ejemplo n.º 7
0
 def spam(x, y=2):
     with Metric('thing-done'):
         args.append((x, y))
Ejemplo n.º 8
0
 def __call__(self, f):
     new_f = _PMetric.__call__(self, f)
     new_f.__wrapped__ = f
     return new_f
Ejemplo n.º 9
0
        return result

    return f


def log_timed_only_self(func):
    func.log_args_only_self = 1
    return log_timed(func)


_ThreadWithReady = None

METRIC_SAMPLE_RATE = get_non_negative_float_from_environ(
    'RS_PERF_STATSD_SAMPLE_RATE', 0.1, logger=perf_logger)

metricmethod_sampled = Metric(method=True, rate=METRIC_SAMPLE_RATE)

if IN_TESTRUNNER and os.environ.get('RS_TEST_DISABLE_METRICS'):
    # If we're running under the testrunner,
    # don't apply the metricmethod stuff. It makes
    # backtraces ugly and makes stepping in the
    # debugger annoying.
    metricmethod = metricmethod_sampled = lambda f: f


def thread_spawn(func, args=(), daemon=False):
    global _ThreadWithReady
    if _ThreadWithReady is None:
        import threading

        class T(threading.Thread):