app/django/bin/profiling/gather_profile_stats.py
changeset 54 03e267d67478
child 323 ff1a9aa48cfd
equal deleted inserted replaced
53:57b4279d8c4e 54:03e267d67478
       
     1 """
       
     2 gather_profile_stats.py /path/to/dir/of/profiles
       
     3 
       
     4 Note that the aggregated profiles must be read with pstats.Stats, not
       
     5 hotshot.stats (the formats are incompatible)
       
     6 """
       
     7 
       
     8 from hotshot import stats
       
     9 import pstats
       
    10 import sys, os
       
    11 
       
    12 def gather_stats(p):
       
    13     profiles = {}
       
    14     for f in os.listdir(p):
       
    15         if f.endswith('.agg.prof'):
       
    16             path = f[:-9]
       
    17             prof = pstats.Stats(os.path.join(p, f))
       
    18         elif f.endswith('.prof'):
       
    19             bits = f.split('.')
       
    20             path = ".".join(bits[:-3])
       
    21             prof = stats.load(os.path.join(p, f))
       
    22         else:
       
    23             continue
       
    24         print "Processing %s" % f
       
    25         if path in profiles:
       
    26             profiles[path].add(prof)
       
    27         else:
       
    28             profiles[path] = prof
       
    29         os.unlink(os.path.join(p, f))
       
    30     for (path, prof) in profiles.items():
       
    31         prof.dump_stats(os.path.join(p, "%s.agg.prof" % path))
       
    32     
       
    33 if __name__ == '__main__':
       
    34     gather_stats(sys.argv[1])