[ARVADOS] updated: 1f40455a7bd764c517c7f1ddb8b4b41b4a2f7ee8

git at public.curoverse.com git at public.curoverse.com
Mon Jun 22 16:55:10 EDT 2015


Summary of changes:
 .../tests/performance/performance_profiler.py      | 24 +++++++++++++++-------
 sdk/python/tests/performance/test_a_sample.py      |  4 ++++
 2 files changed, 21 insertions(+), 7 deletions(-)

  discards  24fa04e6fee7a6cb94910b0ae93325816b1b2970 (commit)
       via  1f40455a7bd764c517c7f1ddb8b4b41b4a2f7ee8 (commit)

This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:

 * -- * -- B -- O -- O -- O (24fa04e6fee7a6cb94910b0ae93325816b1b2970)
            \
             N -- N -- N (1f40455a7bd764c517c7f1ddb8b4b41b4a2f7ee8)

When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 1f40455a7bd764c517c7f1ddb8b4b41b4a2f7ee8
Author: Tom Clegg <tom at curoverse.com>
Date:   Mon Jun 22 16:55:06 2015 -0400

    6218: Refactor profiler as a decorator

diff --git a/sdk/python/tests/performance/performance_profiler.py b/sdk/python/tests/performance/performance_profiler.py
index 3810f92..57030a7 100644
--- a/sdk/python/tests/performance/performance_profiler.py
+++ b/sdk/python/tests/performance/performance_profiler.py
@@ -1,8 +1,12 @@
-# Use the PerformanceProfiler class to write your performance tests.
+# Use the "profiled" decorator on a test to get profiling data.
 #
 # Usage:
-#   from performance_profiler import PerformanceProfiler
-#   self.run_profiler(...
+#   from performance_profiler import profiled
+#
+#   # See report in tmp/profile/foobar
+#   @profiled
+#   def foobar():
+#       baz = 1
 #
 #   See "test_a_sample.py" for a working example.
 #
@@ -14,22 +18,35 @@
 #         ./run-tests.sh WORKSPACE=~/arvados --only sdk/python sdk/python_test="--test-suite=tests.performance"
 #
 
+import functools
 import os
-import unittest
+import pstats
 import sys
-from datetime import datetime
+import unittest
 try:
     import cProfile as profile
 except ImportError:
     import profile
 
-class PerformanceProfiler(unittest.TestCase):
-    def run_profiler(self, function, test_name):
-        filename = os.getcwd()+'/tmp/performance/'+ datetime.now().strftime('%Y-%m-%d-%H-%M-%S') +'-' +test_name
-
-        directory = os.path.dirname(filename)
-        if not os.path.exists(directory):
-            os.makedirs(directory)
+output_dir = os.path.abspath(os.path.join('tmp', 'profile'))
+if not os.path.exists(output_dir):
+    os.makedirs(output_dir)
 
-        sys.stdout = open(filename, 'w')
-        profile.runctx(function, globals(), locals())
+def profiled(function):
+    @functools.wraps(function)
+    def profiled_function(*args, **kwargs):
+        outfile = open(os.path.join(output_dir, function.__name__), "w")
+        caught = None
+        pr = profile.Profile()
+        pr.enable()
+        try:
+            ret = function(*args, **kwargs)
+        except e:
+            caught = e
+        pr.disable()
+        ps = pstats.Stats(pr, stream=outfile)
+        ps.print_stats()
+        if caught:
+            raise caught
+        return ret
+    return profiled_function
diff --git a/sdk/python/tests/performance/test_a_sample.py b/sdk/python/tests/performance/test_a_sample.py
index aa35813..dff0984 100644
--- a/sdk/python/tests/performance/test_a_sample.py
+++ b/sdk/python/tests/performance/test_a_sample.py
@@ -1,10 +1,15 @@
 import unittest
 
-from performance_profiler import PerformanceProfiler
+from performance_profiler import profiled
 
-class PerformanceTestSample(PerformanceProfiler):
-    def func(self):
-        print 'Hello'
+class PerformanceTestSample(unittest.TestCase):
+    def foo(self):
+        bar = 64
 
-    def test_performance(self):
-        self.run_profiler('self.func()', 'test_sample')
+    @profiled
+    def test_profiled_decorator(self):
+        j = 0
+        for i in range(0,2**20):
+            j += i
+        self.foo()
+        print 'Hello'

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list