From: radhika Date: Fri, 19 Jun 2015 21:01:32 +0000 (-0400) Subject: 6218: add performance profiling and a sample test in python sdk. X-Git-Tag: 1.1.0~1537^2~5 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/372aaff2b572ce772fafc506e9c57d465eb823f6 6218: add performance profiling and a sample test in python sdk. --- diff --git a/.gitignore b/.gitignore index eec475862e..0871c89cb9 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ sdk/java/target *.class sdk/java/log /tmp +sdk/python/tmp +services/fuse/tmp diff --git a/sdk/python/tests/performance/__init__.py b/sdk/python/tests/performance/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sdk/python/tests/performance/performance_profiler.py b/sdk/python/tests/performance/performance_profiler.py new file mode 100644 index 0000000000..3810f92f18 --- /dev/null +++ b/sdk/python/tests/performance/performance_profiler.py @@ -0,0 +1,35 @@ +# Use the PerformanceProfiler class to write your performance tests. +# +# Usage: +# from performance_profiler import PerformanceProfiler +# self.run_profiler(... +# +# See "test_a_sample.py" for a working example. +# +# To run performance tests: +# cd arvados/sdk/python +# 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" +# + +import os +import unittest +import sys +from datetime import datetime +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) + + sys.stdout = open(filename, 'w') + profile.runctx(function, globals(), locals()) diff --git a/sdk/python/tests/performance/test_a_sample.py b/sdk/python/tests/performance/test_a_sample.py new file mode 100644 index 0000000000..cc30ba6051 --- /dev/null +++ b/sdk/python/tests/performance/test_a_sample.py @@ -0,0 +1,10 @@ +import unittest + +from performance_profiler import PerformanceProfiler + +class PerformanceTestSample(PerformanceProfiler): + def func(self): + print 'Hello' + + def test_performance(self): + self.run_profiler('self.func', 'test_sample') diff --git a/services/fuse/tests/performance/__init__.py b/services/fuse/tests/performance/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/services/fuse/tests/performance/performance_profiler.py b/services/fuse/tests/performance/performance_profiler.py new file mode 120000 index 0000000000..1ab8e75e6a --- /dev/null +++ b/services/fuse/tests/performance/performance_profiler.py @@ -0,0 +1 @@ +/home/radhika/arvados/sdk/python/tests/performance/performance_profiler.py \ No newline at end of file