- properly use tempfile.mkstemp, by using os.fdopen() on the passed file
[opensuse:osc.git] / osc_hotshot.py
1 #!/usr/bin/env python
2
3 import hotshot, hotshot.stats
4 import tempfile
5 import os, sys
6
7 from osc import commandline
8 from osc.core import init_basicauth
9
10
11 if __name__ == '__main__':
12
13     (fd, filename) = tempfile.mkstemp(prefix = 'osc_profiledata_', dir = '/dev/shm')
14     f = os.fdopen(fd)
15
16     try:
17
18         prof = hotshot.Profile(filename)
19         
20         init_basicauth()
21         prof.runcall(commandline.main)
22         print 'run complete. analyzing.'
23         prof.close()
24
25         stats = hotshot.stats.load(filename)
26         stats.strip_dirs()
27         stats.sort_stats('time', 'calls')
28         stats.print_stats(20)
29
30         del stats
31
32     finally:
33         f.close()
34         os.unlink(filename)