Created
April 18, 2018 11:11
-
-
Save hverr/4aba8e877487a55dada35088b9b42170 to your computer and use it in GitHub Desktop.
Order GHC heap profiles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import fileinput | |
class Sample(object): | |
def __init__(self, start_line): | |
_, time = line.split(' ') | |
self.time = float(time) | |
self.lines = [start_line] | |
def print_hp(self): | |
for l in self.lines: | |
print l | |
class Line(object): | |
def __init__(self, line): | |
self.line = line | |
@property | |
def time(self): | |
return -1 | |
def __repr__(self): | |
return 'Line({})'.format(self.line) | |
def print_hp(self): | |
print self.line | |
class HP(object): | |
def __init__(self): | |
self.content = [] | |
def sort_samples(self): | |
self.content.sort(key=lambda c: c.time) | |
def print_hp(self): | |
for c in self.content: | |
c.print_hp() | |
hp = HP() | |
current_sample = None | |
for line in fileinput.input(): | |
line = line.strip() | |
if current_sample is None: | |
if line.startswith('BEGIN_SAMPLE'): | |
current_sample = Sample(line) | |
else: | |
hp.content.append(Line(line)) | |
else: | |
if line.startswith('END_SAMPLE'): | |
current_sample.lines.append(line) | |
hp.content.append(current_sample) | |
current_sample = None | |
else: | |
current_sample.lines.append(line) | |
hp.sort_samples() | |
hp.print_hp() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment