def process_trace(filename): trace = gc_nvp_common.parse_gc_trace(filename) if len(trace): keys = trace[0].keys() print(', '.join(keys)) for entry in trace: print(', '.join(map(lambda key: str(entry[key]), keys)))
def process_trace(filename): trace = gc_nvp_common.parse_gc_trace(filename) marksweeps = filter(lambda r: r['gc'] == 'ms', trace) scavenges = filter(lambda r: r['gc'] == 's', trace) globalgcs = filter(lambda r: r['gc'] != 's', trace) charts = plot_all(plots, trace, filename) def stats(out, prefix, trace, field): n = len(trace) total = calc_total(trace, field) max = calc_max(trace, field) if n > 0: avg = total / n else: avg = 0 if n > 1: dev = math.sqrt( freduce(lambda t, r: t + (r - avg)**2, field, trace, 0) / (n - 1)) else: dev = 0 out.write('<tr><td>%s</td><td>%d</td><td>%d</td>' '<td>%d</td><td>%d [dev %f]</td></tr>' % (prefix, n, total, max, avg, dev)) def HumanReadable(size): suffixes = ['bytes', 'kB', 'MB', 'GB'] power = 1 for i in range(len(suffixes)): if size < power * 1024: return "%.1f" % (float(size) / power) + " " + suffixes[i] power *= 1024 def throughput(name, trace): total_live_after = calc_total(trace, 'total_size_after') total_live_before = calc_total(trace, 'total_size_before') total_gc = calc_total(trace, 'pause') if total_gc == 0: return out.write('GC %s Throughput (after): %s / %s ms = %s/ms<br/>' % (name, HumanReadable(total_live_after), total_gc, HumanReadable(total_live_after / total_gc))) out.write('GC %s Throughput (before): %s / %s ms = %s/ms<br/>' % (name, HumanReadable(total_live_before), total_gc, HumanReadable(total_live_before / total_gc))) with open(filename + '.html', 'w') as out: out.write('<html><body>') out.write('<table>') out.write('<tr><td>Phase</td><td>Count</td><td>Time (ms)</td>') out.write('<td>Max</td><td>Avg</td></tr>') stats(out, 'Total in GC', trace, 'pause') stats(out, 'Scavenge', scavenges, 'pause') stats(out, 'MarkSweep', marksweeps, 'pause') stats(out, 'Mark', filter(lambda r: r['mark'] != 0, trace), 'mark') stats(out, 'Sweep', filter(lambda r: r['sweep'] != 0, trace), 'sweep') stats(out, 'External', filter(lambda r: r['external'] != 0, trace), 'external') out.write('</table>') throughput('TOTAL', trace) throughput('MS', marksweeps) throughput('OLDSPACE', globalgcs) out.write('<br/>') for chart in charts: out.write('<img src="%s">' % chart) out.write('</body></html>') print("%s generated." % (filename + '.html'))
def process_trace(filename): trace = gc_nvp_common.parse_gc_trace(filename) marksweeps = filter(lambda r: r['gc'] == 'ms', trace) scavenges = filter(lambda r: r['gc'] == 's', trace) globalgcs = filter(lambda r: r['gc'] != 's', trace) charts = plot_all(plots, trace, filename) def stats(out, prefix, trace, field): n = len(trace) total = calc_total(trace, field) max = calc_max(trace, field) if n > 0: avg = total / n else: avg = 0 if n > 1: dev = math.sqrt(freduce(lambda t,r: t + (r - avg) ** 2, field, trace, 0) / (n - 1)) else: dev = 0 out.write('<tr><td>%s</td><td>%d</td><td>%d</td>' '<td>%d</td><td>%d [dev %f]</td></tr>' % (prefix, n, total, max, avg, dev)) def HumanReadable(size): suffixes = ['bytes', 'kB', 'MB', 'GB'] power = 1 for i in range(len(suffixes)): if size < power*1024: return "%.1f" % (float(size) / power) + " " + suffixes[i] power *= 1024 def throughput(name, trace): total_live_after = calc_total(trace, 'total_size_after') total_live_before = calc_total(trace, 'total_size_before') total_gc = calc_total(trace, 'pause') if total_gc == 0: return out.write('GC %s Throughput (after): %s / %s ms = %s/ms<br/>' % (name, HumanReadable(total_live_after), total_gc, HumanReadable(total_live_after / total_gc))) out.write('GC %s Throughput (before): %s / %s ms = %s/ms<br/>' % (name, HumanReadable(total_live_before), total_gc, HumanReadable(total_live_before / total_gc))) with open(filename + '.html', 'w') as out: out.write('<html><body>') out.write('<table>') out.write('<tr><td>Phase</td><td>Count</td><td>Time (ms)</td>') out.write('<td>Max</td><td>Avg</td></tr>') stats(out, 'Total in GC', trace, 'pause') stats(out, 'Scavenge', scavenges, 'pause') stats(out, 'MarkSweep', marksweeps, 'pause') stats(out, 'Mark', filter(lambda r: r['mark'] != 0, trace), 'mark') stats(out, 'Sweep', filter(lambda r: r['sweep'] != 0, trace), 'sweep') stats(out, 'External', filter(lambda r: r['external'] != 0, trace), 'external') out.write('</table>') throughput('TOTAL', trace) throughput('MS', marksweeps) throughput('OLDSPACE', globalgcs) out.write('<br/>') for chart in charts: out.write('<img src="%s">' % chart) out.write('</body></html>') print "%s generated." % (filename + '.html')