Add Django-1.2.1
[frozenviper.git] / Django-1.2.1 / build / lib.linux-i686-2.6 / django / bin / profiling / gather_profile_stats.py
blob0fd2b7fca9502c27afdbb8ff3d97c65564b9ee14
1 #!/usr/bin/env python
3 """
4 gather_profile_stats.py /path/to/dir/of/profiles
6 Note that the aggregated profiles must be read with pstats.Stats, not
7 hotshot.stats (the formats are incompatible)
8 """
10 from hotshot import stats
11 import pstats
12 import sys, os
14 def gather_stats(p):
15 profiles = {}
16 for f in os.listdir(p):
17 if f.endswith('.agg.prof'):
18 path = f[:-9]
19 prof = pstats.Stats(os.path.join(p, f))
20 elif f.endswith('.prof'):
21 bits = f.split('.')
22 path = ".".join(bits[:-3])
23 prof = stats.load(os.path.join(p, f))
24 else:
25 continue
26 print "Processing %s" % f
27 if path in profiles:
28 profiles[path].add(prof)
29 else:
30 profiles[path] = prof
31 os.unlink(os.path.join(p, f))
32 for (path, prof) in profiles.items():
33 prof.dump_stats(os.path.join(p, "%s.agg.prof" % path))
35 if __name__ == '__main__':
36 gather_stats(sys.argv[1])