1 # Use the "profiled" decorator on a test to get profiling data.
4 # from performance_profiler import profiled
6 # # See report in tmp/profile/foobar
11 # See "test_a_sample.py" for a working example.
13 # Performance tests run as part of regular test suite.
14 # You can also run only the performance tests using one of the following:
15 # python -m unittest discover tests.performance
16 # ./run-tests.sh WORKSPACE=~/arvados --only sdk/python sdk/python_test="--test-suite=tests.performance"
24 import cProfile as profile
28 output_dir = os.path.abspath(os.path.join('tmp', 'profile'))
29 if not os.path.exists(output_dir):
30 os.makedirs(output_dir)
32 def profiled(function):
33 @functools.wraps(function)
34 def profiled_function(*args, **kwargs):
35 outfile = open(os.path.join(output_dir, function.__name__), "w")
37 pr = profile.Profile()
40 ret = function(*args, **kwargs)
41 except Exception as e:
44 ps = pstats.Stats(pr, stream=outfile)
49 return profiled_function