equal
deleted
inserted
replaced
|
1 #!/usr/bin/env python |
|
2 |
|
3 """ |
|
4 gather_profile_stats.py /path/to/dir/of/profiles |
|
5 |
|
6 Note that the aggregated profiles must be read with pstats.Stats, not |
|
7 hotshot.stats (the formats are incompatible) |
|
8 """ |
|
9 |
|
10 from hotshot import stats |
|
11 import pstats |
|
12 import sys, os |
|
13 |
|
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)) |
|
34 |
|
35 if __name__ == '__main__': |
|
36 gather_stats(sys.argv[1]) |