Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add profile contextmanager #5

Merged
merged 1 commit into from

2 participants

Timothée Peignier Bryan O'Sullivan
Timothée Peignier

Add profile contextmanager for easier use :

import statprof
import test.pystone

with statprof.profile():
     test.pystone.pystones()
Bryan O'Sullivan bos merged commit d017747 into from
Bryan O'Sullivan
Owner

Applied, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 10, 2012
  1. Timothée Peignier

    add profile contextmanager

    cyberdelia authored
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 3 deletions.
  1. +8 −0 README.rst
  2. +13 −3 statprof.py
8 README.rst
View
@@ -34,6 +34,14 @@ It's easy to get started with ``statprof``: ::
statprof.stop()
statprof.display()
+Or with a contextmanager : ::
+
+ import statprof
+
+ with statprof.profile():
+ my_questionable_function()
+
+
For more comprehensive help, run ``pydoc statprof``.
16 statprof.py
View
@@ -100,15 +100,15 @@
significantly off if other threads' work patterns are not similar to the
main thread's work patterns.
"""
-
-
from __future__ import division
import os
import signal
+from contextlib import contextmanager
+
-__all__ = ['start', 'stop', 'reset', 'display']
+__all__ = ['start', 'stop', 'reset', 'display', 'profile']
###########################################################################
@@ -273,6 +273,16 @@ def reset(frequency=None):
state.reset(frequency)
+@contextmanager
+def profile():
+ start()
+ try:
+ yield
+ finally:
+ stop()
+ display()
+
+
###########################################################################
## Reporting API
Something went wrong with that request. Please try again.