# HG changeset patch # User Nicolas Saunier # Date 1404854582 14400 # Node ID 3622a5653ee976c9f6960fa3235fed030b471fa2 # Parent ca6bded754ac6569db4dcb77c65cca8fad1fe5dd added basic info and function to profile code diff -r ca6bded754ac -r 3622a5653ee9 python/utils.py --- a/python/utils.py Tue Jul 08 17:04:55 2014 -0400 +++ b/python/utils.py Tue Jul 08 17:23:02 2014 -0400 @@ -552,6 +552,30 @@ ######################### +# Profiling +######################### + +def analyzeProfile(profileFilename, stripDirs = True): + '''Analyze the file produced by cProfile + + obtained by for example: + - call in script (for main() function in script) + import cProfile, os + cProfile.run('main()', os.path.join(os.getcwd(),'main.profile')) + + - or on the command line: + python -m cProfile [-o profile.bin] [-s sort] scriptfile [arg]''' + import pstats, os + p = pstats.Stats(os.path.join(os.pardir, profileFilename)) + if stripDirs: + p.strip_dirs() + p.sort_stats('time') + p.print_stats(.2) + #p.sort_stats('time') + # p.print_callees(.1, 'int_prediction.py:') + return p + +######################### # running tests #########################