Statistics
| Branch: | Revision:

root / env / lib / python2.7 / site-packages / django / bin / profiling / gather_profile_stats.py @ 1a305335

History | View | Annotate | Download (983 Bytes)

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 os
12
import pstats
13
import sys
14

    
15
def gather_stats(p):
16
    profiles = {}
17
    for f in os.listdir(p):
18
        if f.endswith('.agg.prof'):
19
            path = f[:-9]
20
            prof = pstats.Stats(os.path.join(p, f))
21
        elif f.endswith('.prof'):
22
            bits = f.split('.')
23
            path = ".".join(bits[:-3])
24
            prof = stats.load(os.path.join(p, f))
25
        else:
26
            continue
27
        print "Processing %s" % f
28
        if path in profiles:
29
            profiles[path].add(prof)
30
        else:
31
            profiles[path] = prof
32
        os.unlink(os.path.join(p, f))
33
    for (path, prof) in profiles.items():
34
        prof.dump_stats(os.path.join(p, "%s.agg.prof" % path))
35
    
36
if __name__ == '__main__':
37
    gather_stats(sys.argv[1])