2008-06-16 12:09:44 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2005-07-13 09:25:57 +08:00
|
|
|
"""
|
|
|
|
gather_profile_stats.py /path/to/dir/of/profiles
|
|
|
|
|
|
|
|
Note that the aggregated profiles must be read with pstats.Stats, not
|
|
|
|
hotshot.stats (the formats are incompatible)
|
|
|
|
"""
|
|
|
|
|
|
|
|
from hotshot import stats
|
2011-07-13 17:35:51 +08:00
|
|
|
import os
|
2005-07-13 09:25:57 +08:00
|
|
|
import pstats
|
2011-07-13 17:35:51 +08:00
|
|
|
import sys
|
2005-07-13 09:25:57 +08:00
|
|
|
|
|
|
|
def gather_stats(p):
|
|
|
|
profiles = {}
|
|
|
|
for f in os.listdir(p):
|
|
|
|
if f.endswith('.agg.prof'):
|
|
|
|
path = f[:-9]
|
|
|
|
prof = pstats.Stats(os.path.join(p, f))
|
|
|
|
elif f.endswith('.prof'):
|
|
|
|
bits = f.split('.')
|
|
|
|
path = ".".join(bits[:-3])
|
|
|
|
prof = stats.load(os.path.join(p, f))
|
|
|
|
else:
|
|
|
|
continue
|
2012-04-29 00:02:01 +08:00
|
|
|
print("Processing %s" % f)
|
2007-04-26 21:30:48 +08:00
|
|
|
if path in profiles:
|
2005-07-13 09:25:57 +08:00
|
|
|
profiles[path].add(prof)
|
|
|
|
else:
|
|
|
|
profiles[path] = prof
|
|
|
|
os.unlink(os.path.join(p, f))
|
|
|
|
for (path, prof) in profiles.items():
|
|
|
|
prof.dump_stats(os.path.join(p, "%s.agg.prof" % path))
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
gather_stats(sys.argv[1])
|