test_backend: Add option to profile the backend test suite.

This commit is contained in:
Tim Abbott 2016-01-23 17:21:34 -08:00
parent f9791558e9
commit a5d4d0aae0
1 changed files with 12 additions and 0 deletions

View File

@ -21,6 +21,9 @@ if __name__ == "__main__":
parser.add_option('--coverage', dest='coverage', parser.add_option('--coverage', dest='coverage',
action="store_true", action="store_true",
default=False, help='Compute test coverage.') default=False, help='Compute test coverage.')
parser.add_option('--profile', dest='profile',
action="store_true",
default=False, help='Profile test runtime.')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if len(args) == 0: if len(args) == 0:
@ -32,6 +35,10 @@ if __name__ == "__main__":
import coverage import coverage
cov = coverage.Coverage() cov = coverage.Coverage()
cov.start() cov.start()
if options.profile:
import cProfile
prof = cProfile.Profile()
prof.enable()
TestRunner = get_runner(settings) TestRunner = get_runner(settings)
test_runner = TestRunner() test_runner = TestRunner()
@ -44,6 +51,11 @@ if __name__ == "__main__":
cov.report(show_missing=False) cov.report(show_missing=False)
cov.html_report() cov.html_report()
print("HTML report saved to htmlcov/") print("HTML report saved to htmlcov/")
if options.profile:
prof.disable()
prof.dump_stats("/tmp/profile.data")
print("Profile data saved to /tmp/profile.data")
print("You can visualize it using e.g. `runsnake /tmp/profile.data`")
if failures: if failures:
print('FAILED!') print('FAILED!')