| 1 |
|
| 2 |
""" Parse gcdumps. Use by saying PYPYLOG=gc-collect:log pypy <program> |
| 3 |
and run it by: |
| 4 |
|
| 5 |
gcanalyze.py logfile [--plot] |
| 6 |
""" |
| 7 |
from __future__ import print_function |
| 8 |
|
| 9 |
import sys |
| 10 |
from rpython.tool.logparser import parse_log |
| 11 |
|
| 12 |
NO_BUCKETS = 8 |
| 13 |
|
| 14 |
def main(arg, plot=False): |
| 15 |
log = parse_log(open(arg).readlines()) |
| 16 |
all = [] |
| 17 |
for entry in log: |
| 18 |
if entry[0].startswith('gc-collect'): |
| 19 |
start = entry[1] |
| 20 |
end = entry[2] |
| 21 |
all.append(float(end - start) / 1000000) |
| 22 |
format_output(all, plot=plot) |
| 23 |
|
| 24 |
def format_output(all, plot=False): |
| 25 |
avg = sum(all) / len(all) |
| 26 |
max_t = max(all) |
| 27 |
print("AVG:", "%.1fms" % avg, "MAX:", "%.1fms" % max_t, "TOTAL:" , "%.1fms" % sum(all)) |
| 28 |
print() |
| 29 |
buckets = [0] * NO_BUCKETS |
| 30 |
for item in all: |
| 31 |
bucket = int(item / max_t * NO_BUCKETS) |
| 32 |
if bucket == len(buckets): |
| 33 |
bucket = len(buckets) - 1 |
| 34 |
buckets[bucket] += 1 |
| 35 |
l1 = ["%.1fms" % ((i + 1) * max_t / NO_BUCKETS) for i in range(NO_BUCKETS)] |
| 36 |
l2 = [str(i) for i in buckets] |
| 37 |
for i, elem in enumerate(l1): |
| 38 |
l2[i] += " " * (len(elem) - len(l2[i])) |
| 39 |
if plot: |
| 40 |
l3 = ["+"] |
| 41 |
for i, elem in enumerate(l1): |
| 42 |
l3.append("-" * len(elem) + "+") |
| 43 |
l1.insert(0, "") |
| 44 |
l2.insert(0, "") |
| 45 |
print("".join(l3)) |
| 46 |
print("|".join(l1) + "|") |
| 47 |
print("".join(l3)) |
| 48 |
print("|".join(l2) + "|") |
| 49 |
print("".join(l3)) |
| 50 |
else: |
| 51 |
print(" ".join(l1)) |
| 52 |
print(" ".join(l2)) |
| 53 |
|
| 54 |
if __name__ == '__main__': |
| 55 |
if len(sys.argv) < 2 or len(sys.argv) > 3: |
| 56 |
print(__doc__) |
| 57 |
sys.exit(1) |
| 58 |
plot = False |
| 59 |
if len(sys.argv) == 3: |
| 60 |
if sys.argv[1] == '--plot': |
| 61 |
plot = True |
| 62 |
arg = sys.argv[2] |
| 63 |
elif sys.argv[2] == '--plot': |
| 64 |
plot = True |
| 65 |
arg = sys.argv[1] |
| 66 |
else: |
| 67 |
print("Wrong command line options:", sys.argv) |
| 68 |
sys.exit(1) |
| 69 |
else: |
| 70 |
arg = sys.argv[1] |
| 71 |
main(arg, plot=plot) |