profiling
[wolnelektury.git] / apps / wolnelektury_core / management / profile.py
diff --git a/apps/wolnelektury_core/management/profile.py b/apps/wolnelektury_core/management/profile.py
new file mode 100644 (file)
index 0000000..a68453d
--- /dev/null
@@ -0,0 +1,16 @@
+
+import cProfile
+import functools
+
+_object = None
+
+def profile(meth):
+    def _wrapper(self, *args, **kwargs):
+        object = self
+        setattr(object, "__%s" % meth.__name__, meth)
+        cProfile.runctx('object.__%s(object, *args, **kwargs)' % (meth.__name__, ), globals(), locals(),
+            "wlprofile")
+
+    functools.update_wrapper(_wrapper, meth)
+    return _wrapper
+