[ARVADOS] updated: eac37febf548d1d103661ded6e1a0e21e64ba7cd
git at public.curoverse.com
git at public.curoverse.com
Tue Jun 23 09:25:42 EDT 2015
Summary of changes:
.../tests/performance/performance_profiler.py | 54 ++++++++++++++--------
sdk/python/tests/performance/test_a_sample.py | 17 ++++---
.../fuse/tests/performance/performance_profiler.py | 2 +-
3 files changed, 46 insertions(+), 27 deletions(-)
via eac37febf548d1d103661ded6e1a0e21e64ba7cd (commit)
via 1f40455a7bd764c517c7f1ddb8b4b41b4a2f7ee8 (commit)
from ae63accf8df1fdc458603fdf0c259c4bf0f25231 (commit)
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 eac37febf548d1d103661ded6e1a0e21e64ba7cd
Author: radhika <radhika at curoverse.com>
Date: Tue Jun 23 09:25:08 2015 -0400
6218: update the symlink and comment
diff --git a/sdk/python/tests/performance/performance_profiler.py b/sdk/python/tests/performance/performance_profiler.py
index 57030a7..4843610 100644
--- a/sdk/python/tests/performance/performance_profiler.py
+++ b/sdk/python/tests/performance/performance_profiler.py
@@ -10,13 +10,10 @@
#
# See "test_a_sample.py" for a working example.
#
-# To run performance tests:
-# cd arvados/sdk/python
+# Performance tests run as part of regular test suite.
+# You can also run only the performance tests using one of the following:
# python -m unittest discover tests.performance
-#
-# Alternatively, using run-tests.sh
-# ./run-tests.sh WORKSPACE=~/arvados --only sdk/python sdk/python_test="--test-suite=tests.performance"
-#
+# ./run-tests.sh WORKSPACE=~/arvados --only sdk/python sdk/python_test="--test-suite=tests.performance"
import functools
import os
diff --git a/services/fuse/tests/performance/performance_profiler.py b/services/fuse/tests/performance/performance_profiler.py
index 1ab8e75..01a6805 120000
--- a/services/fuse/tests/performance/performance_profiler.py
+++ b/services/fuse/tests/performance/performance_profiler.py
@@ -1 +1 @@
-/home/radhika/arvados/sdk/python/tests/performance/performance_profiler.py
\ No newline at end of file
+../../../../sdk/python/tests/performance/performance_profiler.py
\ No newline at end of file
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