Mercurial > hg > nsaunier > traffic-intelligence
comparison python/utils.py @ 553:3622a5653ee9
added basic info and function to profile code
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 08 Jul 2014 17:23:02 -0400 |
| parents | 97c5fef5b2d6 |
| children | ee45c6eb6d49 |
comparison
equal
deleted
inserted
replaced
| 552:ca6bded754ac | 553:3622a5653ee9 |
|---|---|
| 550 | 550 |
| 551 return optionValues | 551 return optionValues |
| 552 | 552 |
| 553 | 553 |
| 554 ######################### | 554 ######################### |
| 555 # Profiling | |
| 556 ######################### | |
| 557 | |
| 558 def analyzeProfile(profileFilename, stripDirs = True): | |
| 559 '''Analyze the file produced by cProfile | |
| 560 | |
| 561 obtained by for example: | |
| 562 - call in script (for main() function in script) | |
| 563 import cProfile, os | |
| 564 cProfile.run('main()', os.path.join(os.getcwd(),'main.profile')) | |
| 565 | |
| 566 - or on the command line: | |
| 567 python -m cProfile [-o profile.bin] [-s sort] scriptfile [arg]''' | |
| 568 import pstats, os | |
| 569 p = pstats.Stats(os.path.join(os.pardir, profileFilename)) | |
| 570 if stripDirs: | |
| 571 p.strip_dirs() | |
| 572 p.sort_stats('time') | |
| 573 p.print_stats(.2) | |
| 574 #p.sort_stats('time') | |
| 575 # p.print_callees(.1, 'int_prediction.py:') | |
| 576 return p | |
| 577 | |
| 578 ######################### | |
| 555 # running tests | 579 # running tests |
| 556 ######################### | 580 ######################### |
| 557 | 581 |
| 558 if __name__ == "__main__": | 582 if __name__ == "__main__": |
| 559 import doctest | 583 import doctest |
