markus/main.py
def timer(self, stat, tags=None):
        """Contextmanager for easily computing timings.

        :arg string stat: A period delimited alphanumeric key.

        :arg list-of-strings tags: Each string in the tag consists of a key and
            a value separated by a colon. Tags can make it easier to break down
            metrics for analysis.

            For example ``['env:stage', 'compressed:yes']``.

        For example:

        >>> mymetrics = get_metrics(__name__)

        >>> def long_function():
        ...     with mymetrics.timer('long_function'):
        ...         # perform some thing we want to keep metrics on
        ...         pass


        .. Note::

           All timings generated with this are in milliseconds.

        """
        if six.PY3:
            start_time = time.perf_counter()
        else:
            start_time = time.time()

        yield

        if six.PY3:
            end_time = time.perf_counter()
        else:
            end_time = time.time()

        delta = end_time - start_time
        self.timing(stat, value=delta * 1000.0, tags=tags)
def timer(self, stat, tags=None):
        """Contextmanager for easily computing timings.

        :arg string stat: A period delimited alphanumeric key.

        :arg list-of-strings tags: Each string in the tag consists of a key and
            a value separated by a colon. Tags can make it easier to break down
            metrics for analysis.

            For example ``['env:stage', 'compressed:yes']``.

        For example:

        >>> mymetrics = get_metrics(__name__)

        >>> def long_function():
        ...     with mymetrics.timer('long_function'):
        ...         # perform some thing we want to keep metrics on
        ...         pass


        .. Note::

           All timings generated with this are in milliseconds.

        """
        if six.PY3:
            start_time = time.perf_counter()
        else:
            start_time = time.time()

        yield

        if six.PY3:
            end_time = time.perf_counter()
        else:
            end_time = time.time()

        delta = end_time - start_time
        self.timing(stat, value=delta * 1000.0, tags=tags)
Contextmanager for easily computing timings.

        :arg string stat: A period delimited alphanumeric key.

        :arg list-of-strings tags: Each string in the tag consists of a key and
            a value separated by a colon. Tags can make it easier to break down
            metrics for analysis.

            For example ``['env:stage', 'compressed:yes']``.

        For example:

        >>> mymetrics = get_metrics(__name__)

        >>> def long_function():
        ...     with mymetrics.timer('long_function'):
        ...         # perform some thing we want to keep metrics on
        ...         pass


        .. Note::

           All timings generated with this are in milliseconds.